未验证 提交 a516ca6a 编写于 作者: O openharmony_ci 提交者: Gitee

!24005 剪贴板文档示例调整

Merge pull request !24005 from lin/master
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
## 导入模块 ## 导入模块
```js ```ts
import pasteboard from '@ohos.pasteboard'; import pasteboard from '@ohos.pasteboard';
``` ```
...@@ -61,16 +61,16 @@ createData(mimeType: string, value: ValueType): PasteData ...@@ -61,16 +61,16 @@ createData(mimeType: string, value: ValueType): PasteData
**示例1:** **示例1:**
```js ```ts
let dataXml = new ArrayBuffer(256); let dataXml = new ArrayBuffer(256);
let pasteData = pasteboard.createData('app/xml', dataXml); let pasteData: pasteboard.PasteData = pasteboard.createData('app/xml', dataXml);
``` ```
**示例2:** **示例2:**
```js ```ts
let dataText = 'hello'; let dataText = 'hello';
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, dataText); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, dataText);
``` ```
...@@ -97,16 +97,16 @@ createRecord(mimeType: string, value: ValueType):PasteDataRecord; ...@@ -97,16 +97,16 @@ createRecord(mimeType: string, value: ValueType):PasteDataRecord;
**示例1:** **示例1:**
```js ```ts
let dataXml = new ArrayBuffer(256); let dataXml = new ArrayBuffer(256);
let pasteDataRecord = pasteboard.createRecord('app/xml', dataXml); let pasteDataRecord: pasteboard.PasteDataRecord = pasteboard.createRecord('app/xml', dataXml);
``` ```
**示例2:** **示例2:**
```js ```ts
let dataUri = 'dataability:///com.example.myapplication1/user.txt'; let dataUri = 'dataability:///com.example.myapplication1/user.txt';
let record = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_URI, dataUri); let record: pasteboard.PasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_URI, dataUri);
``` ```
## pasteboard.getSystemPasteboard ## pasteboard.getSystemPasteboard
...@@ -125,8 +125,8 @@ getSystemPasteboard(): SystemPasteboard ...@@ -125,8 +125,8 @@ getSystemPasteboard(): SystemPasteboard
**示例:** **示例:**
```js ```ts
let systemPasteboard = pasteboard.getSystemPasteboard(); let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
``` ```
## ShareOption<sup>9+</sup> ## ShareOption<sup>9+</sup>
...@@ -166,9 +166,9 @@ createHtmlData(htmlText: string): PasteData ...@@ -166,9 +166,9 @@ createHtmlData(htmlText: string): PasteData
**示例:** **示例:**
```js ```ts
let html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>"; let html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
let pasteData = pasteboard.createHtmlData(html); let pasteData: pasteboard.PasteData = pasteboard.createHtmlData(html);
``` ```
## pasteboard.createWantData<sup>(deprecated)</sup> ## pasteboard.createWantData<sup>(deprecated)</sup>
...@@ -196,12 +196,14 @@ createWantData(want: Want): PasteData ...@@ -196,12 +196,14 @@ createWantData(want: Want): PasteData
**示例:** **示例:**
```js ```ts
let object = { import Want from '@ohos.app.ability.Want';
let object: Want = {
bundleName: "com.example.aafwk.test", bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility" abilityName: "com.example.aafwk.test.TwoAbility"
}; };
let pasteData = pasteboard.createWantData(object); let pasteData: pasteboard.PasteData = pasteboard.createWantData(object);
``` ```
## pasteboard.createPlainTextData<sup>(deprecated)</sup> ## pasteboard.createPlainTextData<sup>(deprecated)</sup>
...@@ -229,8 +231,8 @@ createPlainTextData(text: string): PasteData ...@@ -229,8 +231,8 @@ createPlainTextData(text: string): PasteData
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createPlainTextData('content'); let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('content');
``` ```
## pasteboard.createUriData<sup>(deprecated)</sup> ## pasteboard.createUriData<sup>(deprecated)</sup>
...@@ -258,8 +260,8 @@ createUriData(uri: string): PasteData ...@@ -258,8 +260,8 @@ createUriData(uri: string): PasteData
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createUriData('dataability:///com.example.myapplication1/user.txt'); let pasteData: pasteboard.PasteData = pasteboard.createUriData('dataability:///com.example.myapplication1/user.txt');
``` ```
## pasteboard.createHtmlTextRecord<sup>(deprecated)</sup> ## pasteboard.createHtmlTextRecord<sup>(deprecated)</sup>
...@@ -286,9 +288,9 @@ createHtmlTextRecord(htmlText: string): PasteDataRecord ...@@ -286,9 +288,9 @@ createHtmlTextRecord(htmlText: string): PasteDataRecord
**示例:** **示例:**
```js ```ts
let html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>"; let html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
let record = pasteboard.createHtmlTextRecord(html); let record: pasteboard.PasteDataRecord = pasteboard.createHtmlTextRecord(html);
``` ```
## pasteboard.createWantRecord<sup>(deprecated)</sup> ## pasteboard.createWantRecord<sup>(deprecated)</sup>
...@@ -316,12 +318,14 @@ createWantRecord(want: Want): PasteDataRecord ...@@ -316,12 +318,14 @@ createWantRecord(want: Want): PasteDataRecord
**示例:** **示例:**
```js ```ts
let object = { import Want from '@ohos.app.ability.Want';
let object: Want = {
bundleName: "com.example.aafwk.test", bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility" abilityName: "com.example.aafwk.test.TwoAbility"
}; };
let record = pasteboard.createWantRecord(object); let record: pasteboard.PasteDataRecord = pasteboard.createWantRecord(object);
``` ```
## pasteboard.createPlainTextRecord<sup>(deprecated)</sup> ## pasteboard.createPlainTextRecord<sup>(deprecated)</sup>
...@@ -349,8 +353,8 @@ createPlainTextRecord(text: string): PasteDataRecord ...@@ -349,8 +353,8 @@ createPlainTextRecord(text: string): PasteDataRecord
**示例:** **示例:**
```js ```ts
let record = pasteboard.createPlainTextRecord('hello'); let record: pasteboard.PasteDataRecord = pasteboard.createPlainTextRecord('hello');
``` ```
## pasteboard.createUriRecord<sup>(deprecated)</sup> ## pasteboard.createUriRecord<sup>(deprecated)</sup>
...@@ -378,8 +382,8 @@ createUriRecord(uri: string): PasteDataRecord ...@@ -378,8 +382,8 @@ createUriRecord(uri: string): PasteDataRecord
**示例:** **示例:**
```js ```ts
let record = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt'); let record: pasteboard.PasteDataRecord = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt');
``` ```
...@@ -392,7 +396,7 @@ let record = pasteboard.createUriRecord('dataability:///com.example.myapplicatio ...@@ -392,7 +396,7 @@ let record = pasteboard.createUriRecord('dataability:///com.example.myapplicatio
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | -------- | -------- | -------- | -------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| additions<sup>7+</sup> | {[key:string]:object} | 是 | 是 | 设置其他附加属性数据。 | | additions<sup>7+</sup> | {[key:string]:object} | 是 | 是 | 设置其他附加属性数据。不支持动态追加属性,只能通过重新赋值的方式修改附加值,具体见相关示例setProperty。 |
| mimeTypes<sup>7+</sup> | Array&lt;string&gt; | 是 | 否 | 剪贴板内容条目的数据类型,非重复的类型列表。 | | mimeTypes<sup>7+</sup> | Array&lt;string&gt; | 是 | 否 | 剪贴板内容条目的数据类型,非重复的类型列表。 |
| tag<sup>7+</sup> | string | 是 | 是 | 用户自定义标签。 | | tag<sup>7+</sup> | string | 是 | 是 | 用户自定义标签。 |
| timestamp<sup>7+</sup> | number | 是 | 否 | 剪贴板数据的写入时间戳(单位:ms)。 | | timestamp<sup>7+</sup> | number | 是 | 否 | 剪贴板数据的写入时间戳(单位:ms)。 |
...@@ -433,9 +437,9 @@ toPlainText(): string ...@@ -433,9 +437,9 @@ toPlainText(): string
**示例:** **示例:**
```js ```ts
let record = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt'); let record: pasteboard.PasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
let data = record.toPlainText(); let data: string = record.toPlainText();
console.info(`Succeeded in converting to text. Data: ${data}`); console.info(`Succeeded in converting to text. Data: ${data}`);
``` ```
...@@ -458,13 +462,15 @@ convertToText(callback: AsyncCallback&lt;string&gt;): void ...@@ -458,13 +462,15 @@ convertToText(callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```ts
let record = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt'); import { BusinessError } from '@ohos.base';
record.convertToText((err, data) => {
let record: pasteboard.PasteDataRecord = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt');
record.convertToText((err: BusinessError, data: string) => {
if (err) { if (err) {
console.error(`Failed to convert to text. Cause: ${err.message}`); console.error(`Failed to convert to text. Cause: ${err.message}`);
return; return;
} }
console.info(`Succeeded in converting to text. Data: ${data}`); console.info(`Succeeded in converting to text. Data: ${data}`);
}); });
``` ```
...@@ -488,11 +494,13 @@ convertToText(): Promise&lt;string&gt; ...@@ -488,11 +494,13 @@ convertToText(): Promise&lt;string&gt;
**示例:** **示例:**
```js ```ts
let record = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt'); import { BusinessError } from '@ohos.base';
record.convertToText().then((data) => {
let record: pasteboard.PasteDataRecord = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt');
record.convertToText().then((data: string) => {
console.info(`Succeeded in converting to text. Data: ${data}`); console.info(`Succeeded in converting to text. Data: ${data}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to convert to text. Cause: ${err.message}`); console.error(`Failed to convert to text. Cause: ${err.message}`);
}); });
``` ```
...@@ -521,9 +529,9 @@ getPrimaryText(): string ...@@ -521,9 +529,9 @@ getPrimaryText(): string
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello'); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let plainText = pasteData.getPrimaryText(); let plainText: string = pasteData.getPrimaryText();
``` ```
### getPrimaryHtml<sup>7+</sup> ### getPrimaryHtml<sup>7+</sup>
...@@ -542,10 +550,10 @@ getPrimaryHtml(): string ...@@ -542,10 +550,10 @@ getPrimaryHtml(): string
**示例:** **示例:**
```js ```ts
let html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>"; let html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, html); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, html);
let htmlText = pasteData.getPrimaryHtml(); let htmlText: string = pasteData.getPrimaryHtml();
``` ```
### getPrimaryWant<sup>7+</sup> ### getPrimaryWant<sup>7+</sup>
...@@ -564,13 +572,15 @@ getPrimaryWant(): Want ...@@ -564,13 +572,15 @@ getPrimaryWant(): Want
**示例:** **示例:**
```js ```ts
let object = { import Want from '@ohos.app.ability.Want';
let object: Want = {
bundleName: "com.example.aafwk.test", bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility" abilityName: "com.example.aafwk.test.TwoAbility"
}; };
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_WANT, object); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_WANT, object);
let want = pasteData.getPrimaryWant(); let want: Want = pasteData.getPrimaryWant();
``` ```
### getPrimaryUri<sup>7+</sup> ### getPrimaryUri<sup>7+</sup>
...@@ -589,9 +599,9 @@ getPrimaryUri(): string ...@@ -589,9 +599,9 @@ getPrimaryUri(): string
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt'); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
let uri = pasteData.getPrimaryUri(); let uri: string = pasteData.getPrimaryUri();
``` ```
### getPrimaryPixelMap<sup>9+</sup> ### getPrimaryPixelMap<sup>9+</sup>
...@@ -610,20 +620,21 @@ getPrimaryPixelMap(): image.PixelMap ...@@ -610,20 +620,21 @@ getPrimaryPixelMap(): image.PixelMap
**示例:** **示例:**
```js ```ts
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
let buffer = new ArrayBuffer(128); let buffer = new ArrayBuffer(128);
let opt = { let realSize: image.Size = { height: 3, width: 5 };
size: { height: 3, width: 5 }, let opt: image.InitializationOptions = {
pixelFormat: 3, size: realSize,
editable: true, pixelFormat: 3,
alphaType: 1, editable: true,
scaleMode: 1 alphaType: 1,
scaleMode: 1
}; };
image.createPixelMap(buffer, opt).then((pixelMap) => { image.createPixelMap(buffer, opt).then((pixelMap: image.PixelMap) => {
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_PIXELMAP, pixelMap); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_PIXELMAP, pixelMap);
let PixelMap = pasteData.getPrimaryPixelMap(); let PixelMap: image.PixelMap = pasteData.getPrimaryPixelMap();
}); });
``` ```
...@@ -643,11 +654,11 @@ addRecord(record: PasteDataRecord): void ...@@ -643,11 +654,11 @@ addRecord(record: PasteDataRecord): void
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt'); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
let textRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello'); let textRecord: pasteboard.PasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>"; let html: string = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
let htmlRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_HTML, html); let htmlRecord: pasteboard.PasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_HTML, html);
pasteData.addRecord(textRecord); pasteData.addRecord(textRecord);
pasteData.addRecord(htmlRecord); pasteData.addRecord(htmlRecord);
``` ```
...@@ -676,8 +687,8 @@ addRecord(mimeType: string, value: ValueType): void ...@@ -676,8 +687,8 @@ addRecord(mimeType: string, value: ValueType): void
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt'); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
let dataXml = new ArrayBuffer(256); let dataXml = new ArrayBuffer(256);
pasteData.addRecord('app/xml', dataXml); pasteData.addRecord('app/xml', dataXml);
``` ```
...@@ -698,9 +709,9 @@ getMimeTypes(): Array&lt;string&gt; ...@@ -698,9 +709,9 @@ getMimeTypes(): Array&lt;string&gt;
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello'); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let types = pasteData.getMimeTypes(); let types: string[] = pasteData.getMimeTypes();
``` ```
### getPrimaryMimeType<sup>7+</sup> ### getPrimaryMimeType<sup>7+</sup>
...@@ -719,9 +730,9 @@ getPrimaryMimeType(): string ...@@ -719,9 +730,9 @@ getPrimaryMimeType(): string
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello'); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let type = pasteData.getPrimaryMimeType(); let type: string = pasteData.getPrimaryMimeType();
``` ```
### getProperty<sup>7+</sup> ### getProperty<sup>7+</sup>
...@@ -740,9 +751,9 @@ getProperty(): PasteDataProperty ...@@ -740,9 +751,9 @@ getProperty(): PasteDataProperty
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello'); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let property = pasteData.getProperty(); let property: pasteboard.PasteDataProperty = pasteData.getProperty();
``` ```
### setProperty<sup>9+</sup> ### setProperty<sup>9+</sup>
...@@ -761,58 +772,59 @@ setProperty(property: PasteDataProperty): void ...@@ -761,58 +772,59 @@ setProperty(property: PasteDataProperty): void
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, 'application/xml'); type AdditionType = Record<string, Record<string, Object>>;
let prop = pasteData.getProperty();
let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, 'application/xml');
let prop: pasteboard.PasteDataProperty = pasteData.getProperty();
prop.shareOption = pasteboard.ShareOption.INAPP; prop.shareOption = pasteboard.ShareOption.INAPP;
prop.additions['TestOne'] = {'Test' : 123}; // 需要注意,不支持对addition进行追加属性的操作,只能通过重新赋值的方式达到追加属性的目的。
prop.additions['TestTwo'] = {'Test' : 'additions'}; prop.additions = { 'TestOne': { 'Test': 123 }, 'TestTwo': { 'Test': 'additions' } } as AdditionType;
prop.tag = 'TestTag'; prop.tag = 'TestTag';
pasteData.setProperty(prop); pasteData.setProperty(prop);
``` ```
[PasteDataProperty](#pastedataproperty7)的localOnly与shareOption属性互斥,最终结果以shareOption为准,shareOption会影响localOnly的值。 [PasteDataProperty](#pastedataproperty7)的localOnly与shareOption属性互斥,最终结果以shareOption为准,shareOption会影响localOnly的值。
```js ```ts
(async function() { (async () => {
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello'); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let prop = pasteData.getProperty(); let prop: pasteboard.PasteDataProperty = pasteData.getProperty();
prop.shareOption = pasteboard.ShareOption.INAPP; prop.shareOption = pasteboard.ShareOption.INAPP;
prop.localOnly = false; prop.localOnly = false;
pasteData.setProperty(prop); pasteData.setProperty(prop);
let systemPasteboard = pasteboard.getSystemPasteboard(); let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
await systemPasteboard.setData(pasteData).then(async () => { await systemPasteboard.setData(pasteData).then(async () => {
console.info('Succeeded in setting PasteData.'); console.info('Succeeded in setting PasteData.');
await systemPasteboard.getData().then(pasteData => { await systemPasteboard.getData().then((pasteData: pasteboard.PasteData) => {
let prop = pasteData.getProperty(); let prop: pasteboard.PasteDataProperty = pasteData.getProperty();
prop.localOnly //true prop.localOnly; // true
}); });
}); });
prop.shareOption = pasteboard.ShareOption.LOCALDEVICE; prop.shareOption = pasteboard.ShareOption.LOCALDEVICE;
prop.localOnly = false; prop.localOnly = false;
pasteData.setProperty(prop); pasteData.setProperty(prop);
await systemPasteboard.setData(pasteData).then(async () => { await systemPasteboard.setData(pasteData).then(async () => {
console.info('Succeeded in setting PasteData.'); console.info('Succeeded in setting PasteData.');
await systemPasteboard.getData().then(pasteData => { await systemPasteboard.getData().then((pasteData: pasteboard.PasteData) => {
let prop = pasteData.getProperty(); let prop: pasteboard.PasteDataProperty = pasteData.getProperty();
prop.localOnly; //true prop.localOnly; // true
}); });
}); });
prop.shareOption = pasteboard.ShareOption.CROSSDEVICE; prop.shareOption = pasteboard.ShareOption.CROSSDEVICE;
prop.localOnly = true; prop.localOnly = true;
pasteData.setProperty(prop); pasteData.setProperty(prop);
await systemPasteboard.setData(pasteData).then(async () => { await systemPasteboard.setData(pasteData).then(async () => {
console.info('Succeeded in setting PasteData.'); console.info('Succeeded in setting PasteData.');
await systemPasteboard.getData().then(pasteData => { await systemPasteboard.getData().then((pasteData: pasteboard.PasteData) => {
let prop = pasteData.getProperty(); let prop: pasteboard.PasteDataProperty = pasteData.getProperty();
prop.localOnly; //false prop.localOnly; // false
}); });
}); });
})() })()
``` ```
### getRecord<sup>9+</sup> ### getRecord<sup>9+</sup>
...@@ -845,9 +857,9 @@ getRecord(index: number): PasteDataRecord ...@@ -845,9 +857,9 @@ getRecord(index: number): PasteDataRecord
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello'); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let record = pasteData.getRecord(0); let record: pasteboard.PasteDataRecord = pasteData.getRecord(0);
``` ```
### getRecordCount<sup>7+</sup> ### getRecordCount<sup>7+</sup>
...@@ -866,9 +878,9 @@ getRecordCount(): number ...@@ -866,9 +878,9 @@ getRecordCount(): number
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello'); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let count = pasteData.getRecordCount(); let count: number = pasteData.getRecordCount();
``` ```
### getTag<sup>7+</sup> ### getTag<sup>7+</sup>
...@@ -887,9 +899,9 @@ getTag(): string ...@@ -887,9 +899,9 @@ getTag(): string
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello'); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let tag = pasteData.getTag(); let tag: string = pasteData.getTag();
``` ```
### hasType<sup>9+</sup> ### hasType<sup>9+</sup>
...@@ -914,9 +926,9 @@ hasType(mimeType: string): boolean ...@@ -914,9 +926,9 @@ hasType(mimeType: string): boolean
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello'); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let hasType = pasteData.hasType(pasteboard.MIMETYPE_TEXT_PLAIN); let hasType: boolean = pasteData.hasType(pasteboard.MIMETYPE_TEXT_PLAIN);
``` ```
### removeRecord<sup>9+</sup> ### removeRecord<sup>9+</sup>
...@@ -943,8 +955,8 @@ removeRecord(index: number): void ...@@ -943,8 +955,8 @@ removeRecord(index: number): void
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello'); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
pasteData.removeRecord(0); pasteData.removeRecord(0);
``` ```
...@@ -973,9 +985,9 @@ replaceRecord(index: number, record: PasteDataRecord): void ...@@ -973,9 +985,9 @@ replaceRecord(index: number, record: PasteDataRecord): void
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello'); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let record = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt'); let record: pasteboard.PasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
pasteData.replaceRecord(0, record); pasteData.replaceRecord(0, record);
``` ```
### addHtmlRecord<sup>(deprecated)</sup> ### addHtmlRecord<sup>(deprecated)</sup>
...@@ -998,9 +1010,9 @@ addHtmlRecord(htmlText: string): void ...@@ -998,9 +1010,9 @@ addHtmlRecord(htmlText: string): void
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('hello');
let html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>"; let html: string = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + " <h1>HEAD</h1>\n" + " <p></p>\n" + "</body>\n" + "</html>";
pasteData.addHtmlRecord(html); pasteData.addHtmlRecord(html);
``` ```
...@@ -1024,9 +1036,11 @@ addWantRecord(want: Want): void ...@@ -1024,9 +1036,11 @@ addWantRecord(want: Want): void
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createPlainTextData('hello'); import Want from '@ohos.app.ability.Want';
let object = {
let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('hello');
let object: Want = {
bundleName: "com.example.aafwk.test", bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility" abilityName: "com.example.aafwk.test.TwoAbility"
}; };
...@@ -1053,8 +1067,8 @@ addTextRecord(text: string): void ...@@ -1053,8 +1067,8 @@ addTextRecord(text: string): void
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('hello');
pasteData.addTextRecord('good'); pasteData.addTextRecord('good');
``` ```
...@@ -1078,8 +1092,8 @@ addUriRecord(uri: string): void ...@@ -1078,8 +1092,8 @@ addUriRecord(uri: string): void
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('hello');
pasteData.addUriRecord('dataability:///com.example.myapplication1/user.txt'); pasteData.addUriRecord('dataability:///com.example.myapplication1/user.txt');
``` ```
### getRecordAt<sup>(deprecated)</sup> ### getRecordAt<sup>(deprecated)</sup>
...@@ -1107,9 +1121,9 @@ getRecordAt(index: number): PasteDataRecord ...@@ -1107,9 +1121,9 @@ getRecordAt(index: number): PasteDataRecord
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('hello');
let record = pasteData.getRecordAt(0); let record: pasteboard.PasteDataRecord = pasteData.getRecordAt(0);
``` ```
### hasMimeType<sup>(deprecated)</sup> ### hasMimeType<sup>(deprecated)</sup>
...@@ -1137,9 +1151,9 @@ hasMimeType(mimeType: string): boolean ...@@ -1137,9 +1151,9 @@ hasMimeType(mimeType: string): boolean
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('hello');
let hasType = pasteData.hasMimeType(pasteboard.MIMETYPE_TEXT_PLAIN); let hasType: boolean = pasteData.hasMimeType(pasteboard.MIMETYPE_TEXT_PLAIN);
``` ```
### removeRecordAt<sup>(deprecated)</sup> ### removeRecordAt<sup>(deprecated)</sup>
...@@ -1166,9 +1180,9 @@ removeRecordAt(index: number): boolean ...@@ -1166,9 +1180,9 @@ removeRecordAt(index: number): boolean
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('hello');
let isRemove = pasteData.removeRecordAt(0); let isRemove: boolean = pasteData.removeRecordAt(0);
``` ```
### replaceRecordAt<sup>(deprecated)</sup> ### replaceRecordAt<sup>(deprecated)</sup>
...@@ -1196,10 +1210,10 @@ replaceRecordAt(index: number, record: PasteDataRecord): boolean ...@@ -1196,10 +1210,10 @@ replaceRecordAt(index: number, record: PasteDataRecord): boolean
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('hello');
let record = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt'); let record: pasteboard.PasteDataRecord = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt');
let isReplace = pasteData.replaceRecordAt(0, record); let isReplace: boolean = pasteData.replaceRecordAt(0, record);
``` ```
## SystemPasteboard ## SystemPasteboard
...@@ -1208,8 +1222,8 @@ let isReplace = pasteData.replaceRecordAt(0, record); ...@@ -1208,8 +1222,8 @@ let isReplace = pasteData.replaceRecordAt(0, record);
在调用SystemPasteboard的接口前,需要先通过[getSystemPasteboard](#pasteboardgetsystempasteboard)获取系统剪贴板。 在调用SystemPasteboard的接口前,需要先通过[getSystemPasteboard](#pasteboardgetsystempasteboard)获取系统剪贴板。
```js ```ts
let systemPasteboard = pasteboard.getSystemPasteboard(); let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
``` ```
### on('update')<sup>7+</sup> ### on('update')<sup>7+</sup>
...@@ -1229,8 +1243,8 @@ on(type: 'update', callback: () =&gt;void ): void ...@@ -1229,8 +1243,8 @@ on(type: 'update', callback: () =&gt;void ): void
**示例:** **示例:**
```js ```ts
let systemPasteboard = pasteboard.getSystemPasteboard(); let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
let listener = () => { let listener = () => {
console.info('The system pasteboard has changed.'); console.info('The system pasteboard has changed.');
}; };
...@@ -1254,8 +1268,8 @@ off(type: 'update', callback?: () =&gt;void ): void ...@@ -1254,8 +1268,8 @@ off(type: 'update', callback?: () =&gt;void ): void
**示例:** **示例:**
```js ```ts
let systemPasteboard = pasteboard.getSystemPasteboard(); let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
let listener = () => { let listener = () => {
console.info('The system pasteboard has changed.'); console.info('The system pasteboard has changed.');
}; };
...@@ -1278,8 +1292,8 @@ clearData(callback: AsyncCallback&lt;void&gt;): void ...@@ -1278,8 +1292,8 @@ clearData(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
let systemPasteboard = pasteboard.getSystemPasteboard(); let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.clearData((err, data) => { systemPasteboard.clearData((err, data) => {
if (err) { if (err) {
console.error(`Failed to clear the pasteboard. Cause: ${err.message}`); console.error(`Failed to clear the pasteboard. Cause: ${err.message}`);
...@@ -1305,11 +1319,13 @@ clearData(): Promise&lt;void&gt; ...@@ -1305,11 +1319,13 @@ clearData(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
let systemPasteboard = pasteboard.getSystemPasteboard(); import { BusinessError } from '@ohos.base';
systemPasteboard.clearData().then((data) => {
let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.clearData().then((data: void) => {
console.info('Succeeded in clearing the pasteboard.'); console.info('Succeeded in clearing the pasteboard.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to clear the pasteboard. Cause: ${err.message}`); console.error(`Failed to clear the pasteboard. Cause: ${err.message}`);
}); });
``` ```
...@@ -1340,9 +1356,9 @@ setData(data: PasteData, callback: AsyncCallback&lt;void&gt;): void ...@@ -1340,9 +1356,9 @@ setData(data: PasteData, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'content'); let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'content');
let systemPasteboard = pasteboard.getSystemPasteboard(); let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.setData(pasteData, (err, data) => { systemPasteboard.setData(pasteData, (err, data) => {
if (err) { if (err) {
console.error('Failed to set PasteData. Cause: ' + err.message); console.error('Failed to set PasteData. Cause: ' + err.message);
...@@ -1383,12 +1399,14 @@ setData(data: PasteData): Promise&lt;void&gt; ...@@ -1383,12 +1399,14 @@ setData(data: PasteData): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'content'); import { BusinessError } from '@ohos.base';
let systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.setData(pasteData).then((data) => { let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'content');
let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.setData(pasteData).then((data: void) => {
console.info('Succeeded in setting PasteData.'); console.info('Succeeded in setting PasteData.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.error('Failed to set PasteData. Cause: ' + err.message); console.error('Failed to set PasteData. Cause: ' + err.message);
}); });
``` ```
...@@ -1417,14 +1435,16 @@ getData( callback: AsyncCallback&lt;PasteData&gt;): void ...@@ -1417,14 +1435,16 @@ getData( callback: AsyncCallback&lt;PasteData&gt;): void
**示例:** **示例:**
```js ```ts
let systemPasteboard = pasteboard.getSystemPasteboard(); import { BusinessError } from '@ohos.base';
systemPasteboard.getData((err, pasteData) => {
let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.getData((err: BusinessError, pasteData: pasteboard.PasteData) => {
if (err) { if (err) {
console.error('Failed to get PasteData. Cause: ' + err.message); console.error('Failed to get PasteData. Cause: ' + err.message);
return; return;
} }
let text = pasteData.getPrimaryText(); let text: string = pasteData.getPrimaryText();
}); });
``` ```
...@@ -1452,13 +1472,15 @@ getData(): Promise&lt;PasteData&gt; ...@@ -1452,13 +1472,15 @@ getData(): Promise&lt;PasteData&gt;
**示例:** **示例:**
```js ```ts
let systemPasteboard = pasteboard.getSystemPasteboard(); import { BusinessError } from '@ohos.base';
systemPasteboard.getData().then((pasteData) => {
let text = pasteData.getPrimaryText(); let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
}).catch((err) => { systemPasteboard.getData().then((pasteData: pasteboard.PasteData) => {
let text: string = pasteData.getPrimaryText();
}).catch((err: BusinessError) => {
console.error('Failed to get PasteData. Cause: ' + err.message); console.error('Failed to get PasteData. Cause: ' + err.message);
}) });
``` ```
### hasData<sup>9+</sup> ### hasData<sup>9+</sup>
...@@ -1477,9 +1499,11 @@ hasData(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1477,9 +1499,11 @@ hasData(callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
let systemPasteboard = pasteboard.getSystemPasteboard(); import { BusinessError } from '@ohos.base';
systemPasteboard.hasData((err, data) => {
let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.hasData((err: BusinessError, data: boolean) => {
if (err) { if (err) {
console.error(`Failed to check the PasteData. Cause: ${err.message}`); console.error(`Failed to check the PasteData. Cause: ${err.message}`);
return; return;
...@@ -1504,11 +1528,13 @@ hasData(): Promise&lt;boolean&gt; ...@@ -1504,11 +1528,13 @@ hasData(): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
let systemPasteboard = pasteboard.getSystemPasteboard(); import { BusinessError } from '@ohos.base';
systemPasteboard.hasData().then((data) => {
let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.hasData().then((data: boolean) => {
console.info(`Succeeded in checking the PasteData. Data: ${data}`); console.info(`Succeeded in checking the PasteData. Data: ${data}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to check the PasteData. Cause: ${err.message}`); console.error(`Failed to check the PasteData. Cause: ${err.message}`);
}); });
``` ```
...@@ -1532,7 +1558,8 @@ clear(callback: AsyncCallback&lt;void&gt;): void ...@@ -1532,7 +1558,8 @@ clear(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.clear((err, data) => { systemPasteboard.clear((err, data) => {
if (err) { if (err) {
console.error(`Failed to clear the PasteData. Cause: ${err.message}`); console.error(`Failed to clear the PasteData. Cause: ${err.message}`);
...@@ -1561,10 +1588,13 @@ clear(): Promise&lt;void&gt; ...@@ -1561,10 +1588,13 @@ clear(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.clear().then((data) => { systemPasteboard.clear().then((data) => {
console.info('Succeeded in clearing the PasteData.'); console.info('Succeeded in clearing the PasteData.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to clear the PasteData. Cause: ${err.message}`); console.error(`Failed to clear the PasteData. Cause: ${err.message}`);
}); });
``` ```
...@@ -1588,14 +1618,16 @@ getPasteData( callback: AsyncCallback&lt;PasteData&gt;): void ...@@ -1588,14 +1618,16 @@ getPasteData( callback: AsyncCallback&lt;PasteData&gt;): void
**示例:** **示例:**
```js ```ts
let systemPasteboard = pasteboard.getSystemPasteboard(); import { BusinessError } from '@ohos.base';
systemPasteboard.getPasteData((err, pasteData) => {
let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.getPasteData((err: BusinessError, pasteData: pasteboard.PasteData) => {
if (err) { if (err) {
console.error('Failed to get PasteData. Cause: ' + err.message); console.error('Failed to get PasteData. Cause: ' + err.message);
return; return;
} }
let text = pasteData.getPrimaryText(); let text: string = pasteData.getPrimaryText();
}); });
``` ```
...@@ -1618,13 +1650,15 @@ getPasteData(): Promise&lt;PasteData&gt; ...@@ -1618,13 +1650,15 @@ getPasteData(): Promise&lt;PasteData&gt;
**示例:** **示例:**
```js ```ts
let systemPasteboard = pasteboard.getSystemPasteboard(); import { BusinessError } from '@ohos.base';
systemPasteboard.getPasteData().then((pasteData) => {
let text = pasteData.getPrimaryText(); let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
}).catch((err) => { systemPasteboard.getPasteData().then((pasteData: pasteboard.PasteData) => {
let text: string = pasteData.getPrimaryText();
}).catch((err: BusinessError) => {
console.error('Failed to get PasteData. Cause: ' + err.message); console.error('Failed to get PasteData. Cause: ' + err.message);
}) });
``` ```
### hasPasteData<sup>(deprecated)</sup> ### hasPasteData<sup>(deprecated)</sup>
...@@ -1646,8 +1680,11 @@ hasPasteData(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1646,8 +1680,11 @@ hasPasteData(callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
systemPasteboard.hasPasteData((err, data) => { import { BusinessError } from '@ohos.base';
let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.hasPasteData((err: BusinessError, data: boolean) => {
if (err) { if (err) {
console.error(`Failed to check the PasteData. Cause: ${err.message}`); console.error(`Failed to check the PasteData. Cause: ${err.message}`);
return; return;
...@@ -1675,10 +1712,13 @@ hasPasteData(): Promise&lt;boolean&gt; ...@@ -1675,10 +1712,13 @@ hasPasteData(): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
systemPasteboard.hasPasteData().then((data) => { import { BusinessError } from '@ohos.base';
let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.hasPasteData().then((data: boolean) => {
console.info(`Succeeded in checking the PasteData. Data: ${data}`); console.info(`Succeeded in checking the PasteData. Data: ${data}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to check the PasteData. Cause: ${err.message}`); console.error(`Failed to check the PasteData. Cause: ${err.message}`);
}); });
``` ```
...@@ -1703,9 +1743,9 @@ setPasteData(data: PasteData, callback: AsyncCallback&lt;void&gt;): void ...@@ -1703,9 +1743,9 @@ setPasteData(data: PasteData, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createPlainTextData('content'); let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('content');
let systemPasteboard = pasteboard.getSystemPasteboard(); let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.setPasteData(pasteData, (err, data) => { systemPasteboard.setPasteData(pasteData, (err, data) => {
if (err) { if (err) {
console.error('Failed to set PasteData. Cause: ' + err.message); console.error('Failed to set PasteData. Cause: ' + err.message);
...@@ -1739,12 +1779,14 @@ setPasteData(data: PasteData): Promise&lt;void&gt; ...@@ -1739,12 +1779,14 @@ setPasteData(data: PasteData): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
let pasteData = pasteboard.createPlainTextData('content'); import { BusinessError } from '@ohos.base';
let systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.setPasteData(pasteData).then((data) => { let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('content');
let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.setPasteData(pasteData).then((data: void) => {
console.info('Succeeded in setting PasteData.'); console.info('Succeeded in setting PasteData.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.error('Failed to set PasteData. Cause: ' + err.message); console.error('Failed to set PasteData. Cause: ' + err.message);
}); });
``` ```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册