提交 6c011f9c 编写于 作者: E ester.zhou

Update docs (15208)

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 2db031a6
# Pasteboard # @ohos.pasteboard (Pasteboard)
The **pasteboard** module provides the copy and paste support for the system pasteboard. You can use the APIs of this module to operate pasteboard content of the plain text, HTML, URI, Want, pixel map, and other types. The **pasteboard** module provides the copy and paste support for the system pasteboard. You can use the APIs of this module to operate pasteboard content of the plain text, HTML, URI, Want, pixel map, and other types.
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -63,7 +63,7 @@ Creates a **PasteData** object of a custom type. ...@@ -63,7 +63,7 @@ Creates a **PasteData** object of a custom type.
```js ```js
let dataXml = new ArrayBuffer(256); let dataXml = new ArrayBuffer(256);
let pasteData = pasteboard.createData('app/xml', dataXml); let pasteData = pasteboard.createData('app/xml', dataXml);
``` ```
## pasteboard.createRecord<sup>9+</sup> ## pasteboard.createRecord<sup>9+</sup>
...@@ -90,8 +90,8 @@ Creates a **PasteDataRecord** object of the custom type. ...@@ -90,8 +90,8 @@ Creates a **PasteDataRecord** object of the custom type.
**Example** **Example**
```js ```js
let dataXml = new ArrayBuffer(256); let dataXml = new ArrayBuffer(256);
let pasteDataRecord = pasteboard.createRecord('app/xml', dataXml); let pasteDataRecord = pasteboard.createRecord('app/xml', dataXml);
``` ```
## pasteboard.getSystemPasteboard ## pasteboard.getSystemPasteboard
...@@ -120,11 +120,11 @@ Enumerates the paste options of data. ...@@ -120,11 +120,11 @@ Enumerates the paste options of data.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
| Name | Description | | Name | Value| Description |
| ----- | ----------------------- | |-------------|---|-------------------|
| InApp |Only intra-application pasting is allowed.| | INAPP | 0 | Only intra-application pasting is allowed. |
| LocalDevice |Paste is allowed in any application on the local device.| | LOCALDEVICE | 1 | Paste is allowed in any application on the local device.|
| CrossDevice |Paste is allowed in any application across devices.| | CROSSDEVICE | 2 | Paste is allowed in any application across devices. |
## pasteboard.createHtmlData<sup>(deprecated)</sup> ## pasteboard.createHtmlData<sup>(deprecated)</sup>
...@@ -374,14 +374,14 @@ Defines the properties of all data records on the pasteboard, including the time ...@@ -374,14 +374,14 @@ Defines the properties of all data records on the pasteboard, including the time
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |--------------------------------------------------------------------------------------------|
| additions<sup>7+</sup> | {[key:string]:object} | Yes| Yes| Additional data.| | additions<sup>7+</sup> | {[key:string]:object} | Yes| Yes| Additional data. |
| mimeTypes<sup>7+</sup> | Array&lt;string&gt; | Yes| No| Non-repeating data types of the data records on the pasteboard.| | mimeTypes<sup>7+</sup> | Array&lt;string&gt; | Yes| No| Non-repeating data types of the data records on the pasteboard. |
| tag<sup>7+</sup> | string | Yes| Yes| Custom tag.| | tag<sup>7+</sup> | string | Yes| Yes| Custom tag. |
| timestamp<sup>7+</sup> | number | Yes| No| Timestamp when data is written to the pasteboard (unit: ms).| | timestamp<sup>7+</sup> | number | Yes| No| Timestamp when data is written to the pasteboard (unit: ms). |
| localOnly<sup>7+</sup> | boolean | Yes| Yes| Whether the pasteboard content is set for local access only. The default value is **true**.<br>- **true**: The pasteboard content is set for local access only.<br>- **false**: The pasteboard content can be shared between devices.| | localOnly<sup>7+</sup> | boolean | Yes| Yes| Whether the pasteboard content is set for local access only. The default value is **true**.<br>- **true**: The pasteboard content is set for local access only.<br>- **false**: The pasteboard content can be shared between devices.|
| shareOption<sup>9+</sup> | [ShareOption](#shareoption9) | Yes| Yes| Where the pasteboard content can be pasted. If this attribute is set incorrectly or not set, the default value **CrossDevice** is used.| | shareOption<sup>9+</sup> | [ShareOption](#shareoption9) | Yes| Yes| Where the pasteboard content can be pasted. If this attribute is set incorrectly or not set, the default value **CROSSDEVICE** is used. |
## PasteDataRecord<sup>7+</sup> ## PasteDataRecord<sup>7+</sup>
...@@ -401,38 +401,11 @@ Provides **PasteDataRecord** APIs. A **PasteDataRecord** is an abstract definiti ...@@ -401,38 +401,11 @@ Provides **PasteDataRecord** APIs. A **PasteDataRecord** is an abstract definiti
| pixelMap<sup>9+</sup> | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| No| Pixel map.| | pixelMap<sup>9+</sup> | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| No| Pixel map.|
| data<sup>9+</sup> | {[mimeType: string]: ArrayBuffer} | Yes| No| Content of custom data.| | data<sup>9+</sup> | {[mimeType: string]: ArrayBuffer} | Yes| No| Content of custom data.|
### convertToTextV9<sup>9+</sup> ### toPlainText<sup>9+</sup>
convertToTextV9(callback: AsyncCallback&lt;string&gt;): void
Forcibly converts the content in a **PasteData** object to text. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the text obtained from the conversion. Otherwise, **err** is error information.|
**Example**
```js toPlainText(): string
let record = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt');
record.convertToTextV9((err, data) => {
if (err) {
console.error(`Failed to convert to text. Cause: ${err.message}`);
return;
}
console.info(`Succeeded in converting to text. Data: ${data}`);
});
```
### convertToTextV9<sup>9+</sup>
convertToTextV9(): Promise&lt;string&gt; Forcibly converts the content in a **PasteData** object to text.
Forcibly converts the content in a **PasteData** object to text. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
...@@ -440,17 +413,14 @@ Forcibly converts the content in a **PasteData** object to text. This API uses a ...@@ -440,17 +413,14 @@ Forcibly converts the content in a **PasteData** object to text. This API uses a
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;string&gt; | Promise used to return the text obtained from the conversion.| | string | Plain text.|
**Example** **Example**
```js ```js
let record = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt'); let record = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
record.convertToTextV9().then((data) => { let data = record.toPlainText();
console.info(`Succeeded in converting to text. Data: ${data}`); console.info(`Succeeded in converting to text. Data: ${data}`);
}).catch((err) => {
console.error(`Failed to convert to text. Cause: ${err.message}`);
});
``` ```
### convertToText<sup>(deprecated)</sup> ### convertToText<sup>(deprecated)</sup>
...@@ -460,7 +430,7 @@ convertToText(callback: AsyncCallback&lt;string&gt;): void ...@@ -460,7 +430,7 @@ convertToText(callback: AsyncCallback&lt;string&gt;): void
Forcibly converts the content in a **PasteData** object to text. This API uses an asynchronous callback to return the result. Forcibly converts the content in a **PasteData** object to text. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [convertToTextV9](#converttotextv99). > This API is supported since API version 7 and deprecated since API version 9. You are advised to use [toPlainText](#toplaintext9).
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
...@@ -474,11 +444,11 @@ Forcibly converts the content in a **PasteData** object to text. This API uses a ...@@ -474,11 +444,11 @@ Forcibly converts the content in a **PasteData** object to text. This API uses a
```js ```js
let record = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt'); let record = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt');
record.convertToText((err, data) => { record.convertToText((err, data) => {
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}`);
}); });
``` ```
...@@ -490,7 +460,7 @@ convertToText(): Promise&lt;string&gt; ...@@ -490,7 +460,7 @@ convertToText(): Promise&lt;string&gt;
Forcibly converts the content in a **PasteData** object to text. This API uses a promise to return the result. Forcibly converts the content in a **PasteData** object to text. This API uses a promise to return the result.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [convertToTextV9](#converttotextv99-1). > This API is supported since API version 7 and deprecated since API version 9. You are advised to use [toPlainText](#toplaintext9).
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
...@@ -536,7 +506,7 @@ Obtains the plain text of the primary record. ...@@ -536,7 +506,7 @@ Obtains the plain text of the primary record.
**Example** **Example**
```js ```js
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let plainText = pasteData.getPrimaryText(); let plainText = pasteData.getPrimaryText();
``` ```
...@@ -558,7 +528,7 @@ Obtains the HTML content of the primary record. ...@@ -558,7 +528,7 @@ Obtains the HTML content of the primary record.
```js ```js
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.createData(pasteboard.MIMETYPE_TEXT_HTML, html);
let htmlText = pasteData.getPrimaryHtml(); let htmlText = pasteData.getPrimaryHtml();
``` ```
...@@ -583,7 +553,7 @@ let object = { ...@@ -583,7 +553,7 @@ let object = {
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.createData(pasteboard.MIMETYPE_TEXT_WANT, object);
let want = pasteData.getPrimaryWant(); let want = pasteData.getPrimaryWant();
``` ```
...@@ -604,7 +574,7 @@ Obtains the URI of the primary record. ...@@ -604,7 +574,7 @@ Obtains the URI of the primary record.
**Example** **Example**
```js ```js
let pasteData = pasteboard.createUriData('dataability:///com.example.myapplication1/user.txt'); let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
let uri = pasteData.getPrimaryUri(); let uri = pasteData.getPrimaryUri();
``` ```
...@@ -636,7 +606,7 @@ let opt = { ...@@ -636,7 +606,7 @@ let opt = {
scaleMode: 1 scaleMode: 1
}; };
image.createPixelMap(buffer, opt).then((pixelMap) => { image.createPixelMap(buffer, opt).then((pixelMap) => {
let pasteData = pasteboard.createData('app/xml',pixelMap); let pasteData = pasteboard.createData(MIMETYPE_PIXELMAP, pixelMap);
let PixelMap = pasteData.getPrimaryPixelMap(); let PixelMap = pasteData.getPrimaryPixelMap();
}); });
``` ```
...@@ -660,10 +630,10 @@ The pasteboard supports a maximum number of 512 data records. ...@@ -660,10 +630,10 @@ The pasteboard supports a maximum number of 512 data records.
**Example** **Example**
```js ```js
let pasteData = pasteboard.createUriData('dataability:///com.example.myapplication1/user.txt'); let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
let textRecord = pasteboard.createPlainTextRecord('hello'); 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 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.createHtmlTextRecord(html); let htmlRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_HTML, html);
pasteData.addRecord(textRecord); pasteData.addRecord(textRecord);
pasteData.addRecord(htmlRecord); pasteData.addRecord(htmlRecord);
``` ```
...@@ -695,9 +665,9 @@ For details about the error codes, see [Pasteboard Error Codes](../errorcodes/er ...@@ -695,9 +665,9 @@ For details about the error codes, see [Pasteboard Error Codes](../errorcodes/er
**Example** **Example**
```js ```js
let pasteData = pasteboard.createUriData('dataability:///com.example.myapplication1/user.txt'); let 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);
``` ```
### getMimeTypes<sup>7+</sup> ### getMimeTypes<sup>7+</sup>
...@@ -717,7 +687,7 @@ Obtains a list of **mimeTypes** objects in [PasteDataProperty](#pastedatapropert ...@@ -717,7 +687,7 @@ Obtains a list of **mimeTypes** objects in [PasteDataProperty](#pastedatapropert
**Example** **Example**
```js ```js
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let types = pasteData.getMimeTypes(); let types = pasteData.getMimeTypes();
``` ```
...@@ -738,7 +708,7 @@ Obtains the data type of the primary record in this pasteboard. ...@@ -738,7 +708,7 @@ Obtains the data type of the primary record in this pasteboard.
**Example** **Example**
```js ```js
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let type = pasteData.getPrimaryMimeType(); let type = pasteData.getPrimaryMimeType();
``` ```
...@@ -759,7 +729,7 @@ Obtains the property of the pasteboard data. ...@@ -759,7 +729,7 @@ Obtains the property of the pasteboard data.
**Example** **Example**
```js ```js
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let property = pasteData.getProperty(); let property = pasteData.getProperty();
``` ```
...@@ -780,9 +750,9 @@ Sets the property (attributes) for the pasteboard data. Currently, only the **sh ...@@ -780,9 +750,9 @@ Sets the property (attributes) for the pasteboard data. Currently, only the **sh
**Example** **Example**
```js ```js
let pasteData = pasteboard.createHtmlData('application/xml'); let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, 'application/xml');
let prop = pasteData.getProperty(); let prop = pasteData.getProperty();
prop.shareOption = pasteboard.ShareOption.InApp; prop.shareOption = pasteboard.ShareOption.INAPP;
pasteData.setProperty(prop); pasteData.setProperty(prop);
``` ```
...@@ -817,7 +787,7 @@ For details about the error codes, see [Pasteboard Error Codes](../errorcodes/er ...@@ -817,7 +787,7 @@ For details about the error codes, see [Pasteboard Error Codes](../errorcodes/er
**Example** **Example**
```js ```js
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let record = pasteData.getRecord(0); let record = pasteData.getRecord(0);
``` ```
...@@ -838,7 +808,7 @@ Obtains the number of records in the pasteboard. ...@@ -838,7 +808,7 @@ Obtains the number of records in the pasteboard.
**Example** **Example**
```js ```js
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let count = pasteData.getRecordCount(); let count = pasteData.getRecordCount();
``` ```
...@@ -859,7 +829,7 @@ Obtains the custom tag from the pasteboard. If no custom tag is set, null is ret ...@@ -859,7 +829,7 @@ Obtains the custom tag from the pasteboard. If no custom tag is set, null is ret
**Example** **Example**
```js ```js
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let tag = pasteData.getTag(); let tag = pasteData.getTag();
``` ```
...@@ -886,7 +856,7 @@ Checks whether the pasteboard contains data of the specified type. ...@@ -886,7 +856,7 @@ Checks whether the pasteboard contains data of the specified type.
**Example** **Example**
```js ```js
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let hasType = pasteData.hasType(pasteboard.MIMETYPE_TEXT_PLAIN); let hasType = pasteData.hasType(pasteboard.MIMETYPE_TEXT_PLAIN);
``` ```
...@@ -915,7 +885,7 @@ For details about the error codes, see [Pasteboard Error Codes](../errorcodes/er ...@@ -915,7 +885,7 @@ For details about the error codes, see [Pasteboard Error Codes](../errorcodes/er
**Example** **Example**
```js ```js
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
pasteData.removeRecord(0); pasteData.removeRecord(0);
``` ```
...@@ -945,8 +915,8 @@ For details about the error codes, see [Pasteboard Error Codes](../errorcodes/er ...@@ -945,8 +915,8 @@ For details about the error codes, see [Pasteboard Error Codes](../errorcodes/er
**Example** **Example**
```js ```js
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
let record = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt'); let record = 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>
...@@ -999,8 +969,8 @@ The pasteboard supports a maximum number of 512 data records. ...@@ -999,8 +969,8 @@ The pasteboard supports a maximum number of 512 data records.
```js ```js
let pasteData = pasteboard.createPlainTextData('hello'); let pasteData = pasteboard.createPlainTextData('hello');
let object = { let object = {
bundleName: "com.example.aafwk.test", bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility" abilityName: "com.example.aafwk.test.TwoAbility"
}; };
pasteData.addWantRecord(object); pasteData.addWantRecord(object);
...@@ -1255,7 +1225,7 @@ Clears the system pasteboard. This API uses an asynchronous callback to return t ...@@ -1255,7 +1225,7 @@ Clears the system pasteboard. This API uses an asynchronous callback to return t
```js ```js
let systemPasteboard = pasteboard.getSystemPasteboard(); let 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}`);
return; return;
...@@ -1282,7 +1252,7 @@ Clears the system pasteboard. This API uses a promise to return the result. ...@@ -1282,7 +1252,7 @@ Clears the system pasteboard. This API uses a promise to return the result.
```js ```js
let systemPasteboard = pasteboard.getSystemPasteboard(); let systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.clearData().then((data) => { systemPasteboard.clearData().then((data) => {
console.info('Succeeded in clearing the pasteboard.'); console.info('Succeeded in clearing the pasteboard.');
}).catch((err) => { }).catch((err) => {
console.error(`Failed to clear the pasteboard. Cause: ${err.message}`); console.error(`Failed to clear the pasteboard. Cause: ${err.message}`);
...@@ -1318,7 +1288,7 @@ For details about the error codes, see [Pasteboard Error Codes](../errorcodes/er ...@@ -1318,7 +1288,7 @@ For details about the error codes, see [Pasteboard Error Codes](../errorcodes/er
```js ```js
let pasteData = pasteboard.createPlainTextData('content'); let pasteData = pasteboard.createPlainTextData('content');
let systemPasteboard = pasteboard.getSystemPasteboard(); let 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);
return; return;
...@@ -1394,7 +1364,7 @@ For details about the error codes, see [Pasteboard Error Codes](../errorcodes/er ...@@ -1394,7 +1364,7 @@ For details about the error codes, see [Pasteboard Error Codes](../errorcodes/er
```js ```js
let systemPasteboard = pasteboard.getSystemPasteboard(); let systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.getData((err, pasteData) => { systemPasteboard.getData((err, 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;
...@@ -1429,7 +1399,7 @@ For details about the error codes, see [Pasteboard Error Codes](../errorcodes/er ...@@ -1429,7 +1399,7 @@ For details about the error codes, see [Pasteboard Error Codes](../errorcodes/er
```js ```js
let systemPasteboard = pasteboard.getSystemPasteboard(); let systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.getData().then((pasteData) => { systemPasteboard.getData().then((pasteData) => {
let text = pasteData.getPrimaryText(); let text = pasteData.getPrimaryText();
}).catch((err) => { }).catch((err) => {
console.error('Failed to get PasteData. Cause: ' + err.message); console.error('Failed to get PasteData. Cause: ' + err.message);
...@@ -1481,7 +1451,7 @@ Checks whether the system pasteboard contains data. This API uses a promise to r ...@@ -1481,7 +1451,7 @@ Checks whether the system pasteboard contains data. This API uses a promise to r
```js ```js
let systemPasteboard = pasteboard.getSystemPasteboard(); let systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.hasData().then((data) => { systemPasteboard.hasData().then((data) => {
console.info(`Succeeded in checking the PasteData. Data: ${data}`); console.info(`Succeeded in checking the PasteData. Data: ${data}`);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to check the PasteData. Cause: ${err.message}`); console.error(`Failed to check the PasteData. Cause: ${err.message}`);
...@@ -1508,8 +1478,8 @@ Clears the system pasteboard. This API uses an asynchronous callback to return t ...@@ -1508,8 +1478,8 @@ Clears the system pasteboard. This API uses an asynchronous callback to return t
**Example** **Example**
```js ```js
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}`);
return; return;
} }
...@@ -1537,9 +1507,9 @@ Clears the system pasteboard. This API uses a promise to return the result. ...@@ -1537,9 +1507,9 @@ Clears the system pasteboard. This API uses a promise to return the result.
**Example** **Example**
```js ```js
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) => {
console.error(`Failed to clear the PasteData. Cause: ${err.message}`); console.error(`Failed to clear the PasteData. Cause: ${err.message}`);
}); });
``` ```
...@@ -1595,7 +1565,7 @@ Obtains a **PasteData** object from the pasteboard. This API uses a promise to r ...@@ -1595,7 +1565,7 @@ Obtains a **PasteData** object from the pasteboard. This API uses a promise to r
```js ```js
let systemPasteboard = pasteboard.getSystemPasteboard(); let systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.getPasteData().then((pasteData) => { systemPasteboard.getPasteData().then((pasteData) => {
let text = pasteData.getPrimaryText(); let text = pasteData.getPrimaryText();
}).catch((err) => { }).catch((err) => {
console.error('Failed to get PasteData. Cause: ' + err.message); console.error('Failed to get PasteData. Cause: ' + err.message);
...@@ -1651,7 +1621,7 @@ Checks whether the system pasteboard contains data. This API uses a promise to r ...@@ -1651,7 +1621,7 @@ Checks whether the system pasteboard contains data. This API uses a promise to r
**Example** **Example**
```js ```js
systemPasteboard.hasPasteData().then((data) => { systemPasteboard.hasPasteData().then((data) => {
console.info(`Succeeded in checking the PasteData. Data: ${data}`); console.info(`Succeeded in checking the PasteData. Data: ${data}`);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to check the PasteData. Cause: ${err.message}`); console.error(`Failed to check the PasteData. Cause: ${err.message}`);
...@@ -1681,7 +1651,7 @@ Writes a **PasteData** object to the pasteboard. This API uses an asynchronous c ...@@ -1681,7 +1651,7 @@ Writes a **PasteData** object to the pasteboard. This API uses an asynchronous c
```js ```js
let pasteData = pasteboard.createPlainTextData('content'); let pasteData = pasteboard.createPlainTextData('content');
let systemPasteboard = pasteboard.getSystemPasteboard(); let 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);
return; return;
......
# Pasteboard Subsystem Changelog
OpenHarmony 4.0.3.2 has the following changes in the APIs of the pasteboard subsystem:
## cl.pasteboard.1 convertToTextV9 API Change
Renamed **convertToTextV9** **toPlainText()** and changed the API from asynchronous to synchronous.
**Change Impact**
Applications developed using the **convertToTextV9** API in versions earlier than OpenHarmony 4.0.3.3 cannot be used in OpenHarmony 4.0.3.3 and later versions.
**Key API/Component Changes**
- Involved APIs:
function convertToTextV9
- Before change:
```ts
convertToTextV9(callback: AsyncCallback<string>): void;
convertToTextV9(): Promise<string>;
```
- After change:
```ts
toPlainText(): string;
```
**Adaptation Guide**
Replace **convertToTextV9**, an asynchronous API, with **toPlainText**, a synchronous API.
## cl.pasteboard.2 ShareOption Enum Name Change
Changed the enum names of **ShareOption** from UpperCamelCase to all caps.
**Change Impact**
Applications developed using the **InApp/LocalDevice/CrossDevice** attributes in versions earlier than OpenHarmony 4.0.3.3 cannot be used in OpenHarmony 4.0.3.3 and later versions.
**Key API/Component Changes**
ShareOption<sup>9+</sup>
Before change:
| Name| Value| Description |
| ---- |---|-------------------|
| InApp | 0 | Only intra-application pasting is allowed. |
| LocalDevice | 1 | Paste is allowed in any application on the local device.|
| CrossDevice | 2 | Paste is allowed in any application across devices. |
After change:
| Name| Value| Description |
| ---- |---|-------------------|
| INAPP | 0 | Only intra-application pasting is allowed. |
| LOCALDEVICE | 1 | Paste is allowed in any application on the local device.|
| CROSSDEVICE | 2 | Paste is allowed in any application across devices. |
**Adaptation Guide**
Perform adaptation based on the new semantics.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册