提交 2f1b4792 编写于 作者: L linxinyu

剪贴板文档示例整改

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