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

!10441 翻译完成 9012/10251

Merge pull request !10441 from ester.zhou/C3-1010
...@@ -37,9 +37,7 @@ For details about the APIs, see [reminderAgent](../reference/apis/js-apis-remind ...@@ -37,9 +37,7 @@ For details about the APIs, see [reminderAgent](../reference/apis/js-apis-remind
import reminderAgent from '@ohos.reminderAgent'; import reminderAgent from '@ohos.reminderAgent';
import notification from '@ohos.notification'; import notification from '@ohos.notification';
export default { export default {
// For a JS project: // eTS project:
// timer: {
// For an eTS project:
let timer : reminderAgent.ReminderRequestTimer = { let timer : reminderAgent.ReminderRequestTimer = {
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 10, triggerTimeInSeconds: 10,
...@@ -69,9 +67,7 @@ For details about the APIs, see [reminderAgent](../reference/apis/js-apis-remind ...@@ -69,9 +67,7 @@ For details about the APIs, see [reminderAgent](../reference/apis/js-apis-remind
Sample code for defining a reminder agent for a calendar event: Sample code for defining a reminder agent for a calendar event:
```js ```js
// For a JS project: // eTS project:
// calendar: {
// For an eTS project:
let calendar : reminderAgent.ReminderRequestCalendar = { let calendar : reminderAgent.ReminderRequestCalendar = {
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_CALENDAR, reminderType: reminderAgent.ReminderType.REMINDER_TYPE_CALENDAR,
dateTime: { dateTime: {
...@@ -117,9 +113,7 @@ For details about the APIs, see [reminderAgent](../reference/apis/js-apis-remind ...@@ -117,9 +113,7 @@ For details about the APIs, see [reminderAgent](../reference/apis/js-apis-remind
Sample code for defining a reminder agent for an alarm: Sample code for defining a reminder agent for an alarm:
```js ```js
// For a JS project: // eTS project:
// alarm: {
// For an eTS project:
let alarm : reminderAgent.ReminderRequestAlarm = { let alarm : reminderAgent.ReminderRequestAlarm = {
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_ALARM, reminderType: reminderAgent.ReminderType.REMINDER_TYPE_ALARM,
hour: 11, hour: 11,
...@@ -171,4 +165,3 @@ For details about the APIs, see [reminderAgent](../reference/apis/js-apis-remind ...@@ -171,4 +165,3 @@ For details about the APIs, see [reminderAgent](../reference/apis/js-apis-remind
<button type="text" value="publishReminder" onclick="startTimer"></button> <button type="text" value="publishReminder" onclick="startTimer"></button>
</div> </div>
``` ```
# Pasteboard # Pasteboard
The **pasteboard** module provides the pasteboard management client and pasteboard server. The pasteboard management client manages pasteboard APIs. Specifically, it provides pasteboard APIs in JavaScript for applications, creates pasteboard data on the application framework side, and requests the pasteboard SA to create, delete, query, convert text, and configure pasteboards. The pasteboard server manages pasteboard events as well as the pasteboard SA lifecycle, providing support for the copy and paste functions of the system. 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
```js
```
import pasteboard from '@ohos.pasteboard'; import pasteboard from '@ohos.pasteboard';
``` ```
## Attributes ## Attributes
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
| Name | Type | Readable | Writable | Description | | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| MAX_RECORD_NUM<sup>7+</sup> | number | Yes | No | Maximum number of records allowed in a **PasteData** object. | | MAX_RECORD_NUM<sup>7+</sup> | number | Yes| No| Maximum number of records in a **PasteData** object.|
| MIMETYPE_TEXT_HTML<sup>7+</sup> | string | Yes | No | MIME type of the HTML text. | | MIMETYPE_TEXT_HTML<sup>7+</sup> | string | Yes| No| MIME type of the HTML content.|
| MIMETYPE_TEXT_WANT<sup>7+</sup> | string | Yes | No | MIME type of the Want text. | | MIMETYPE_TEXT_WANT<sup>7+</sup> | string | Yes| No| MIME type of the Want content.|
| MIMETYPE_TEXT_PLAIN<sup>7+</sup> | string | Yes | No | MIME type of the plain text. | | MIMETYPE_TEXT_PLAIN<sup>7+</sup> | string | Yes| No| MIME type of the plain text content.|
| MIMETYPE_TEXT_URI<sup>7+</sup> | string | Yes | No | MIME type of the URI text. | | MIMETYPE_TEXT_URI<sup>7+</sup> | string | Yes| No| MIME type of the URI content.|
| MIMETYPE_PIXELMAP<sup>9+</sup> | string | Yes| No| MIME type of the pixel map.|
## pasteboard.createPlainTextData ## pasteboard.createPlainTextData
createPlainTextData(text:string): PasteData createPlainTextData(text: string): PasteData
Creates a **PasteData** object for plain text. Creates a **PasteData** object of the plain text type.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| text | string | Yes | Plain text. | | text | string | Yes| Plain text.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| [PasteData](#pastedata) | **PasteData** object with the specified content. | | [PasteData](#pastedata) | **PasteData** object.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createPlainTextData("content"); var pasteData = pasteboard.createPlainTextData("content");
``` ```
## pasteboard.createHtmlData<sup>7+</sup> ## pasteboard.createHtmlData<sup>7+</sup>
createHtmlData(htmlText:string): PasteData createHtmlData(htmlText: string): PasteData
Creates a **PasteData** object for HTML text. Creates a **PasteData** object of the HTML type.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| htmlText | string | Yes | HTML text. | | htmlText | string | Yes| HTML content.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| [PasteData](#pastedata) | **PasteData** object with the specified content. | | [PasteData](#pastedata) | **PasteData** object.|
**Example** **Example**
```js ```js
var 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>"; var 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>";
var pasteData = pasteboard.createHtmlData(html); var pasteData = pasteboard.createHtmlData(html);
``` ```
## pasteboard.createWantData<sup>7+</sup> ## pasteboard.createWantData<sup>7+</sup>
createWantData(want:Want): PasteData createWantData(want: Want): PasteData
Creates a **PasteData** object for Want text. Creates a **PasteData** object of the Want type.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes | Want text. | | want | [Want](js-apis-application-Want.md) | Yes| Want content.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| [PasteData](#pastedata) | **PasteData** object with the specified content. | | [PasteData](#pastedata) | **PasteData** object.|
**Example** **Example**
```js ```js
var object = { var object = {
bundleName: "com.example.aafwk.test", bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility" abilityName: "com.example.aafwk.test.TwoAbility"
}; };
var pasteData = pasteboard.createWantData(object); var pasteData = pasteboard.createWantData(object);
``` ```
## pasteboard.createUriData<sup>7+</sup> ## pasteboard.createUriData<sup>7+</sup>
createUriData(uri:string): PasteData createUriData(uri: string): PasteData
Creates a **PasteData** object for URI text. Creates a **PasteData** object of the URI type.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uri | string | Yes | URI text. | | uri | string | Yes| URI content.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| [PasteData](#pastedata) | **PasteData** object with the specified content. | | [PasteData](#pastedata) | **PasteData** object.|
**Example**
```js
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1/user.txt");
```
## pasteboard.createPixelMapData<sup>9+</sup>
createPixelMapData(pixelMap: image.PixelMap): PasteData
Creates a **PasteData** object of the pixel map type.
**System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pixelMap | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| Pixel map.|
**Return value**
| Type| Description|
| -------- | -------- |
| [PasteData](#pastedata) | **PasteData** object.|
**Example**
```js
import image from '@ohos.multimedia.image';
var buffer = new ArrayBuffer(128)
var opt = {
size: { height: 3, width: 5 },
pixelFormat: 3,
editable: true,
alphaType: 1,
scaleMode: 1
}
image.createPixelMap(buffer, opt).then((pixelMap) => {
var pasteData = pasteboard.createPixelMapData(pixelMap);
})
```
## pasteboard.createData<sup>9+</sup>
createData(mimeType: string, value: ArrayBuffer): PasteData;
Creates a **PasteData** object of a custom type.
**System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| mimeType | string | Yes| MIME type of custom data.|
| value | ArrayBuffer | Yes| Content of custom data.|
**Return value**
| Type| Description|
| -------- | -------- |
| [PasteData](#pastedata) | **PasteData** object.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt"); var dataXml = new ArrayBuffer(256)
var pasteData = pasteboard.createData('app/xml', dataXml)
``` ```
## pasteboard.createPlainTextRecord<sup>7+</sup> ## pasteboard.createPlainTextRecord<sup>7+</sup>
createPlainTextRecord(text:string): PasteDataRecord createPlainTextRecord(text: string): PasteDataRecord
Creates a **PasteDataRecord** object of the plain text type. Creates a **PasteDataRecord** object of the plain text type.
...@@ -151,26 +216,26 @@ Creates a **PasteDataRecord** object of the plain text type. ...@@ -151,26 +216,26 @@ Creates a **PasteDataRecord** object of the plain text type.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| text | string | Yes | Plain text. | | text | string | Yes| Plain text.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| [PasteDataRecord](#pastedatarecord7) | New plain text record. | | [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the plain text type.|
**Example** **Example**
```js ```js
var record = pasteboard.createPlainTextRecord("hello"); var record = pasteboard.createPlainTextRecord("hello");
``` ```
## pasteboard.createHtmlTextRecord<sup>7+</sup> ## pasteboard.createHtmlTextRecord<sup>7+</sup>
createHtmlTextRecord(htmlText:string): PasteDataRecord createHtmlTextRecord(htmlText: string): PasteDataRecord
Creates a **PasteDataRecord** object of the HTML text type. Creates a **PasteDataRecord** object of the HTML text type.
...@@ -178,172 +243,277 @@ Creates a **PasteDataRecord** object of the HTML text type. ...@@ -178,172 +243,277 @@ Creates a **PasteDataRecord** object of the HTML text type.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| htmlText | string | Yes | HTML text. | | htmlText | string | Yes| HTML content.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| [PasteDataRecord](#pastedatarecord7) | New HTML record. | | [PasteDataRecord](#pastedatarecord7) | **PasteDataRecord** object of the HTML text type.|
**Example** **Example**
```js ```js
var 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>"; var 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>";
var record = pasteboard.createHtmlTextRecord(html); var record = pasteboard.createHtmlTextRecord(html);
``` ```
## pasteboard.createWantRecord<sup>7+</sup> ## pasteboard.createWantRecord<sup>7+</sup>
createWantRecord(want:Want): PasteDataRecord createWantRecord(want: Want): PasteDataRecord
Creates a **PasteDataRecord** object of the Want text type. Creates a **PasteDataRecord** object of the Want type.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes | Want text. | | want | [Want](js-apis-application-Want.md) | Yes| Want content.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| [PasteDataRecord](#pastedatarecord7) | New Want record. | | [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the Want type.|
**Example** **Example**
```js ```js
var object = { var object = {
bundleName: "com.example.aafwk.test", bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility" abilityName: "com.example.aafwk.test.TwoAbility"
}; };
var record = pasteboard.createWantRecord(object); var record = pasteboard.createWantRecord(object);
``` ```
## pasteboard.createUriRecord<sup>7+</sup> ## pasteboard.createUriRecord<sup>7+</sup>
createUriRecord(uri:string): PasteDataRecord createUriRecord(uri: string): PasteDataRecord
Creates a **PasteDataRecord** object of the URI text type. Creates a **PasteDataRecord** object of the URI type.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uri | string | Yes | URI text. | | uri | string | Yes| URI content.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| [PasteDataRecord](#pastedatarecord7) | New URI record. | | [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the URI type.|
**Example**
```js
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1/user.txt");
```
## pasteboard.createPixelMapRecord<sup>9+</sup>
createPixelMapRecord(pixelMap: image.PixelMap): PasteDataRecord
Creates a **PasteDataRecord** object of the pixel map type.
**System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pixelMap | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| Pixel map.|
**Return value**
| Type| Description|
| -------- | -------- |
| [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the pixel map type.|
**Example**
```js
import image from '@ohos.multimedia.image';
var buffer = new ArrayBuffer(128)
var opt = {
size: { height: 3, width: 5 },
pixelFormat: 3,
editable: true,
alphaType: 1,
scaleMode: 1
}
image.createPixelMap(buffer, opt).then((pixelMap) => {
var record = pasteboard.createPixelMapRecord(pixelMap);
})
```
## pasteboard.createRecord<sup>9+</sup>
createRecord(mimeType: string, value: ArrayBuffer):PasteDataRecord;
Creates a **PasteDataRecord** object of the custom type.
**System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| mimeType | string | Yes| MIME type of custom data.|
| value | ArrayBuffer | Yes| Content of custom data.|
**Return value**
| Type| Description|
| -------- | -------- |
| [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the custom type.|
**Example** **Example**
```js ```js
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt"); var dataXml = new ArrayBuffer(256)
var pasteDataRecord = pasteboard.createRecord('app/xml', dataXml);
``` ```
## pasteboard.getSystemPasteboard
getSystemPasteboard(): SystemPasteboard
Obtains this **SystemPasteboard** object.
**System capability**: SystemCapability.MiscServices.Pasteboard
**Return value**
| Type| Description|
| -------- | -------- |
| [SystemPasteboard](#systempasteboard) | **SystemPasteboard** object.|
**Example**
```js
var systemPasteboard = pasteboard.getSystemPasteboard();
```
## ShareOption<sup>9+</sup>
Enumerates the paste options of data.
**System capability**: SystemCapability.MiscServices.Pasteboard
| Name | Description |
| ----- | ----------------------- |
| InApp |Only intra-application pasting is allowed. |
| LocalDevice |Paste is allowed in any application on the local device. |
| CrossDevice |Paste is allowed in any application across devices. |
## PasteDataProperty<sup>7+</sup> ## PasteDataProperty<sup>7+</sup>
Defines the properties of all data records on the pasteboard, including the timestamp, data type, and additional data. Defines the properties of all data records on the pasteboard, including the timestamp, data type, and additional data.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
| Name | Type | Readable | Writable | Description | | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| additions | {[key: string]: object} | Yes | Yes | Additional property data. | | additions<sup>7+</sup> | {[key:string]:object} | Yes| Yes| Additional data.|
| mimeTypes | 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 | string | Yes | Yes | User-defined tag. | | tag<sup>7+</sup> | string | Yes| Yes| Custom tag.|
| timestamp | number | Yes | No | Timestamp at which the data is written to the pasteboard, in milliseconds. | | timestamp<sup>7+</sup> | number | Yes| No| Timestamp when data is written to the pasteboard (unit: ms).|
| localOnly | boolean | Yes | Yes | Whether local access only is set for the pasteboard.<br/>- The default value is **true**.<br/>- **true**: The **PasteData** is set for local access only.<br/>- **false**: The **PasteData** 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.|
## PasteDataRecord<sup>7+</sup> ## PasteDataRecord<sup>7+</sup>
A data record is an abstract definition of the content on the pasteboard. The pasteboard content consists of one or more plain text, HTML, URI, or Want records. Provides **PasteDataRecord** APIs. A **PasteDataRecord** is an abstract definition of the content on the pasteboard. The pasteboard content consists of one or more plain text, HTML, URI, or Want records.
### Attributes ### Attributes
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
| Name | Type | Readable | Writable | Description | | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| htmlText<sup>7+</sup> | string | Yes | No | HTML text. | | htmlText<sup>7+</sup> | string | Yes| No| HTML content.|
| want<sup>7+</sup> | [Want](js-apis-application-Want.md) | Yes | No | Want text. | | want<sup>7+</sup> | [Want](js-apis-application-Want.md) | Yes| No| Want content.|
| mimeType<sup>7+</sup> | string | Yes | No | Data type. | | mimeType<sup>7+</sup> | string | Yes| No| Data type.|
| plainText<sup>7+</sup> | string | Yes | No | Plain text. | | plainText<sup>7+</sup> | string | Yes| No| Plain text.|
| uri<sup>7+</sup> | string | Yes | No | URI text. | | uri<sup>7+</sup> | string | Yes| No| URI content.|
| pixelMap<sup>9+</sup> | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| No| Pixel map.|
| data<sup>9+</sup> | {[mimeType:&nbsp;string]:&nbsp;ArrayBuffer} | Yes| No| Content of custom data.|
### convertToText<sup>7+</sup> ### convertToText<sup>7+</sup>
convertToText(): Promise&lt;string&gt; convertToText(): Promise&lt;string&gt;
Forcibly converts the content in this **PasteData** object to the plain 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.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result. If the operation is successful, the plain text content after conversion is returned. Otherwise, error information is returned. | | Promise&lt;string&gt; | Promise used to return the text obtained from the conversion.|
**Example** **Example**
```js ```js
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt"); var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1/user.txt");
record.convertToText().then((data) => { record.convertToText().then((data) => {
console.info('convertToText success data : ' + JSON.stringify(data)); console.info('Succeeded in converting to text. Data: ' + JSON.stringify(data));
}).catch((error) => { }).catch((err) => {
console.error('convertToText failed because ' + JSON.stringify(error)); console.error('Failed to convert to text. Cause: ' + JSON.stringify(err));
}); });
``` ```
### convertToText<sup>7+</sup> ### convertToText<sup>7+</sup>
convertToText(callback: AsyncCallback&lt;string&gt;): void convertToText(callback: AsyncCallback&lt;string&gt;): void
Forcibly converts the content in this **PasteData** object to the plain 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.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the result. If this callback is successful, the plain text content after conversion is returned. Otherwise, error information is returned. | | 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** **Example**
```js ```js
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt"); var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1/user.txt");
record.convertToText((err, data) => { record.convertToText((err, data) => {
if (err) { if (err) {
console.error('convertToText failed because ' + JSON.stringify(err)); console.error('Failed to convert to text. Cause: ' + JSON.stringify(err));
return; return;
} }
console.info('convertToText success data : ' + JSON.stringify(data)); console.info('Succeeded in converting to text. Data: ' + JSON.stringify(data));
}); });
``` ```
## PasteData ## PasteData
Before calling any **PasteData** method, you must obtain a **PasteData** object. Provides **PasteData** APIs.
Before calling any **PasteData** API, you must obtain a **PasteData** object.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
...@@ -356,93 +526,126 @@ getPrimaryText(): string ...@@ -356,93 +526,126 @@ getPrimaryText(): string
Obtains the plain text of the primary record. Obtains the plain text of the primary record.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Return value**
**Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Plain text. | | string | Plain text.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createPlainTextData("hello"); var pasteData = pasteboard.createPlainTextData("hello");
var plainText = pasteData.getPrimaryText(); var plainText = pasteData.getPrimaryText();
``` ```
### getPrimaryHtml<sup>7+</sup> ### getPrimaryHtml<sup>7+</sup>
getPrimaryHtml(): string getPrimaryHtml(): string
Obtains the HTML text of the primary record. Obtains the HTML content of the primary record.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | HTML text. | | string | HTML content.|
**Example** **Example**
```js ```js
var 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>"; var 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>";
var pasteData = pasteboard.createHtmlData(html); var pasteData = pasteboard.createHtmlData(html);
var htmlText = pasteData.getPrimaryHtml(); var htmlText = pasteData.getPrimaryHtml();
``` ```
### getPrimaryWant<sup>7+</sup> ### getPrimaryWant<sup>7+</sup>
getPrimaryWant(): Want getPrimaryWant(): Want
Obtains the **Want** object of the primary record. Obtains the Want object of the primary record.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| [Want](js-apis-application-Want.md) | Want object. | | [Want](js-apis-application-Want.md) | Want object.|
**Example** **Example**
```js ```js
var object = { var object = {
bundleName: "com.example.aafwk.test", bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility" abilityName: "com.example.aafwk.test.TwoAbility"
}; };
var pasteData = pasteboard.createWantData(object); var pasteData = pasteboard.createWantData(object);
var want = pasteData.getPrimaryWant(); var want = pasteData.getPrimaryWant();
``` ```
### getPrimaryUri<sup>7+</sup> ### getPrimaryUri<sup>7+</sup>
getPrimaryUri(): string getPrimaryUri(): string
Obtains the URI text of the primary record. Obtains the URI of the primary record.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | URI text. | | string | URI content.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt"); var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1/user.txt");
var uri = pasteData.getPrimaryUri(); var uri = pasteData.getPrimaryUri();
``` ```
### getPrimaryPixelMap<sup>9+</sup>
getPrimaryPixelMap(): image.PixelMap
Obtains the pixel map of the primary record.
**System capability**: SystemCapability.MiscServices.Pasteboard
**Return value**
| Type| Description|
| -------- | -------- |
| [image.PixelMap](js-apis-image.md#pixelmap7) | Pixel map.|
**Example**
```js
import image from '@ohos.multimedia.image';
var buffer = new ArrayBuffer(128)
var opt = {
size: { height: 3, width: 5 },
pixelFormat: 3,
editable: true,
alphaType: 1,
scaleMode: 1
}
image.createPixelMap(buffer, opt).then((pixelMap) => {
var pasteData = pasteboard.createPixelMapData(pixelMap);
var pixelMap = pasteData.getPrimaryPixelMap();
})
```
### addTextRecord<sup>7+</sup> ### addTextRecord<sup>7+</sup>
...@@ -451,98 +654,158 @@ addTextRecord(text: string): void ...@@ -451,98 +654,158 @@ addTextRecord(text: string): void
Adds a plain text record to this pasteboard, and adds **MIME_TEXT_PLAIN** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails. Adds a plain text record to this pasteboard, and adds **MIME_TEXT_PLAIN** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
The pasteboard supports a maximum number of 128 data records. The pasteboard supports a maximum number of 512 data records.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| text | string | Yes | Plain text. | | text | string | Yes| Plain text.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createPlainTextData("hello"); var pasteData = pasteboard.createPlainTextData("hello");
pasteData.addTextRecord("good"); pasteData.addTextRecord("good");
``` ```
### addHtmlRecord<sup>7+</sup> ### addHtmlRecord<sup>7+</sup>
addHtmlRecord(htmlText: string): void addHtmlRecord(htmlText: string): void
Adds an HTML text record to this pasteboard, and adds **MIMETYPE_TEXT_HTML** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails. Adds an HTML record to this pasteboard, and adds **MIMETYPE_TEXT_HTML** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
The pasteboard supports a maximum number of 128 data records. The pasteboard supports a maximum number of 512 data records.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| htmlText | string | Yes | HTML text. | | htmlText | string | Yes| HTML content.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createPlainTextData("hello"); var pasteData = pasteboard.createPlainTextData("hello");
var 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>"; var 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>";
pasteData.addHtmlRecord(html); pasteData.addHtmlRecord(html);
``` ```
### addWantRecord<sup>7+</sup> ### addWantRecord<sup>7+</sup>
addWantRecord(want: Want): void addWantRecord(want: Want): void
Adds a Want text record to this pasteboard, and adds **MIMETYPE_TEXT_WANT** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails. Adds a Want record to this pasteboard, and adds **MIMETYPE_TEXT_WANT** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
The pasteboard supports a maximum number of 128 data records. The pasteboard supports a maximum number of 512 data records.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes | Want object. | | want | [Want](js-apis-application-Want.md) | Yes| Want object.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createPlainTextData("hello"); var pasteData = pasteboard.createPlainTextData("hello");
var object = { var 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);
``` ```
### addUriRecord<sup>7+</sup> ### addUriRecord<sup>7+</sup>
addUriRecord(uri: string): void addUriRecord(uri: string): void
Adds a URI text record to this pasteboard, and adds **MIMETYPE_TEXT_URI** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails. Adds a URI record to this pasteboard, and adds **MIMETYPE_TEXT_URI** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
The pasteboard supports a maximum number of 512 data records.
**System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| uri | string | Yes| URI content.|
**Example**
```js
var pasteData = pasteboard.createPlainTextData("hello");
pasteData.addUriRecord("dataability:///com.example.myapplication1/user.txt");
```
### addPixelMapRecord<sup>9+</sup>
addPixelMapRecord(pixelMap: image.PixelMap): void
Adds a pixel map record to this pasteboard, and adds **MIMETYPE_PIXELMAP** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
The pasteboard supports a maximum number of 512 data records.
**System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pixelMap | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| Pixel map.|
**Example**
```js
import image from '@ohos.multimedia.image';
var buffer = new ArrayBuffer(128)
var opt = {
size: { height: 3, width: 5 },
pixelFormat: 3,
editable: true,
alphaType: 1,
scaleMode: 1
}
image.createPixelMap(buffer, opt).then((pixelMap) => {
var record = pasteboard.createPlainTextData("hello").addPixelMapRecord(pixelMap);
})
```
### addRecord<sup>9+</sup>
The pasteboard supports a maximum number of 128 data records. addRecord(mimeType: string, value: ArrayBuffer): void
Adds a custom-type record to this pasteboard, and adds the custom type to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
The pasteboard supports a maximum number of 512 data records.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uri | string | Yes | URI text. | | mimeType | string | Yes| MIME type of custom data.|
| value | ArrayBuffer | Yes| Content of custom data.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createPlainTextData("hello"); var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1/user.txt");
pasteData.addUriRecord("dataability:///com.example.myapplication1?user.txt"); var dataXml = new ArrayBuffer(256)
pasteData.addRecord('app/xml', dataXml);
``` ```
...@@ -552,423 +815,427 @@ addRecord(record: PasteDataRecord): void ...@@ -552,423 +815,427 @@ addRecord(record: PasteDataRecord): void
Adds a data record to this pasteboard, and adds its type to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails. Adds a data record to this pasteboard, and adds its type to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
The pasteboard supports a maximum number of 128 data records. The pasteboard supports a maximum number of 512 data records.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| record | [PasteDataRecord](#pastedatarecord7) | Yes | Record to add. | | record | [PasteDataRecord](#pastedatarecord7) | Yes| Record to add.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt"); var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1/user.txt");
var textRecord = pasteboard.createPlainTextRecord("hello"); var textRecord = pasteboard.createPlainTextRecord("hello");
var 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>"; var 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>";
var htmlRecord = pasteboard.createHtmlTextRecord(html); var htmlRecord = pasteboard.createHtmlTextRecord(html);
pasteData.addRecord(textRecord); pasteData.addRecord(textRecord);
pasteData.addRecord(htmlRecord); pasteData.addRecord(htmlRecord);
``` ```
### getMimeTypes<sup>7+</sup> ### getMimeTypes<sup>7+</sup>
getMimeTypes(): Array&lt;string&gt; getMimeTypes(): Array&lt;string&gt;
Obtains **mimeTypes** in [PasteDataProperty](#pastedataproperty7) from this pasteboard. If the pasteboard is empty, the returned list is also empty. Obtains a list of **mimeTypes** objects in [PasteDataProperty](#pastedataproperty7) from this pasteboard. If the pasteboard is empty, the returned list is also empty.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| Array&lt;string&gt; | List of non-duplicate MIME types. | | Array&lt;string&gt; | Non-repeating data types of the data records on the pasteboard.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createPlainTextData("hello"); var pasteData = pasteboard.createPlainTextData("hello");
var types = pasteData.getMimeTypes(); var types = pasteData.getMimeTypes();
``` ```
### getPrimaryMimeType<sup>7+</sup> ### getPrimaryMimeType<sup>7+</sup>
getPrimaryMimeType(): string getPrimaryMimeType(): string
Obtains the data type of the primary record. Obtains the data type of the primary record in this pasteboard.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Data type of the primary record. | | string | Data type of the primary record.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createPlainTextData("hello"); var pasteData = pasteboard.createPlainTextData("hello");
var type = pasteData.getPrimaryMimeType(); var type = pasteData.getPrimaryMimeType();
``` ```
### getProperty<sup>7+</sup> ### getProperty<sup>7+</sup>
getProperty(): PasteDataProperty getProperty(): PasteDataProperty
Obtains the property description object. Obtains the property of the pasteboard data.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| [PasteDataProperty](#pastedataproperty7) | Property description object. | | [PasteDataProperty](#pastedataproperty7) | Property of the pasteboard data.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createPlainTextData("hello"); var pasteData = pasteboard.createPlainTextData("hello");
var property = pasteData.getProperty(); var property = pasteData.getProperty();
``` ```
### setProperty<sup>9+</sup>
setProperty(property: PasteDataProperty): void
Sets the property (attributes) for the pasteboard data. Currently, only the **shareOption** attribute is supported.
**System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| property | [PasteDataProperty](#pastedataproperty7) | Yes| Property of the pasteboard data.|
**Example**
```js
var pasteData = pasteboard.createHtmlData('application/xml');
let prop = pasteData.getProperty();
prop.shareOption = pasteboard.ShareOption.InApp;
pasteData.setProperty(prop);
```
### getRecordAt<sup>7+</sup> ### getRecordAt<sup>7+</sup>
getRecordAt(index: number): PasteDataRecord getRecordAt(index: number): PasteDataRecord
Obtains the record with the specified index. Obtains the specified record in the pasteboard.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| index | number | Yes | Index of the specified record. | | index | number | Yes| Index of the target record.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| [PasteDataRecord](#pastedatarecord7) | Record with the specified index. | | [PasteDataRecord](#pastedatarecord7) | Record with the specified index.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createPlainTextData("hello"); var pasteData = pasteboard.createPlainTextData("hello");
var record = pasteData.getRecordAt(0); var record = pasteData.getRecordAt(0);
``` ```
### getRecordCount<sup>7+</sup> ### getRecordCount<sup>7+</sup>
getRecordCount(): number getRecordCount(): number
Obtains the number of data records in this pasteboard. Obtains the number of records in the pasteboard.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Number of records. | | number | Number of records.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createPlainTextData("hello"); var pasteData = pasteboard.createPlainTextData("hello");
var count = pasteData.getRecordCount(); var count = pasteData.getRecordCount();
``` ```
### getTag<sup>7+</sup> ### getTag<sup>7+</sup>
getTag(): string getTag(): string
Obtains the user-defined tag content. If the tag content is not set, null is returned. Obtains the custom tag from the pasteboard. If no custom tag is set, null is returned.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | User-defined tag content if obtained and null if no tag is set. | | string | Custom tag. If no custom tag is set, null is returned.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createPlainTextData("hello"); var pasteData = pasteboard.createPlainTextData("hello");
var tag = pasteData.getTag(); var tag = pasteData.getTag();
``` ```
### hasMimeType<sup>7+</sup> ### hasMimeType<sup>7+</sup>
hasMimeType(mimeType: string): boolean hasMimeType(mimeType: string): boolean
Checks whether the content of this pasteboard contains the specified data type. Checks whether the pasteboard contains data of the specified type.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| mimeType | string | Yes | Type of the data to query. | | mimeType | string | Yes| Type of the data to query.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the specified data type exists; returns **false** otherwise. | | boolean | Returns **true** if the specified data type exists; returns **false** otherwise.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createPlainTextData("hello"); var pasteData = pasteboard.createPlainTextData("hello");
var hasType = pasteData.hasMimeType(pasteboard.MIMETYPE_TEXT_PLAIN); var hasType = pasteData.hasMimeType(pasteboard.MIMETYPE_TEXT_PLAIN);
``` ```
### removeRecordAt<sup>7+</sup> ### removeRecordAt<sup>7+</sup>
removeRecordAt(index: number): boolean removeRecordAt(index: number): boolean
Removes the data record with a specified index from this pasteboard. Removes the record with the specified index from the pasteboard.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| index | number | Yes | Specified index. | | index | number | Yes| Specified index.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise. | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createPlainTextData("hello"); var pasteData = pasteboard.createPlainTextData("hello");
var isRemove = pasteData.removeRecordAt(0); var isRemove = pasteData.removeRecordAt(0);
``` ```
### replaceRecordAt<sup>7+</sup> ### replaceRecordAt<sup>7+</sup>
replaceRecordAt(index: number, record: PasteDataRecord): boolean replaceRecordAt(index: number, record: PasteDataRecord): boolean
Replaces the data record with a specified index in this pasteboard. Replaces the record with the specified index in the pasteboard with a new record.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| index | number | Yes | Specified index. | | index | number | Yes| Specified index.|
| record | [PasteDataRecord](#pastedatarecord7) | Yes | New record. | | record | [PasteDataRecord](#pastedatarecord7) | Yes| New record.|
**Return value**
| Type | Description |
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise. |
**Example**
```js
var pasteData = pasteboard.createPlainTextData("hello");
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
var isReplace = pasteData.replaceRecordAt(0, record);
```
## pasteboard.getSystemPasteboard
getSystemPasteboard(): SystemPasteboard
Obtains the system pasteboard.
**System capability**: SystemCapability.MiscServices.Pasteboard
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| [SystemPasteboard](#systempasteboard) | System pasteboard. | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example** **Example**
```js ```js
var systemPasteboard = pasteboard.getSystemPasteboard(); var pasteData = pasteboard.createPlainTextData("hello");
``` var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1/user.txt");
var isReplace = pasteData.replaceRecordAt(0, record);
```
## SystemPasteboard ## SystemPasteboard
Before calling any **SystemPasteboard** method, you must obtain a **SystemPasteboard** object using [getSystemPasteboard](#pasteboardgetsystempasteboard). Provides **SystemPasteboard** APIs.
``` Before calling any **SystemPasteboard** API, you must obtain a **SystemPasteboard** object using [getSystemPasteboard](#pasteboardgetsystempasteboard).
```js
var systemPasteboard = pasteboard.getSystemPasteboard(); var systemPasteboard = pasteboard.getSystemPasteboard();
``` ```
### setPasteData ### setPasteData
setPasteData(data:PasteData, callback:AsyncCallback&lt;void&gt;): void setPasteData(data: PasteData, callback: AsyncCallback&lt;void&gt;): void
Writes data to a pasteboard. This API uses an asynchronous callback to return the result. Writes a **PasteData** object to the pasteboard. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| data | [PasteData](#pastedata) | Yes | **PasteData** object. | | data | [PasteData](#pastedata) | Yes| **PasteData** object.|
| callback | AsyncCallback&lt;void> | Yes | Callback used to return the data write result. | | callback | AsyncCallback&lt;void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createPlainTextData("content"); var pasteData = pasteboard.createPlainTextData("content");
var systemPasteboard = pasteboard.getSystemPasteboard(); var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.setPasteData(pasteData, (error, data) => { systemPasteboard.setPasteData(pasteData, (err, data) => {
if (error) { if (err) {
console.error('Failed to setPasteData. Cause: ' + error.message); console.error('Failed to set PasteData. Cause: ' + err.message);
return; return;
} }
console.info('setPasteData successfully.'); console.info('Succeeded in setting PasteData.');
}); });
``` ```
### setPasteData ### setPasteData
setPasteData(data:PasteData): Promise&lt;void&gt; setPasteData(data: PasteData): Promise&lt;void&gt;
Writes data to a pasteboard. This API uses a promise to return the result. Writes a **PasteData** object to the pasteboard. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Description | | Name| Type| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| data | [PasteData](#pastedata) | **PasteData** object. | | data | [PasteData](#pastedata) | **PasteData** object.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the data write result. | | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
var pasteData = pasteboard.createPlainTextData("content"); var pasteData = pasteboard.createPlainTextData("content");
var systemPasteboard = pasteboard.getSystemPasteboard(); var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.setPasteData(pasteData).then((data) => { systemPasteboard.setPasteData(pasteData).then((data) => {
console.info('setPasteData success.'); console.info('Succeeded in setting PasteData.');
}).catch((error) => { }).catch((err) => {
console.error('Failed to setPasteData. Cause: ' + error.message); console.error('Failed to set PasteData. Cause: ' + err.message);
}); });
``` ```
### getPasteData ### getPasteData
getPasteData( callback:AsyncCallback&lt;PasteData&gt;): void getPasteData( callback: AsyncCallback&lt;PasteData&gt;): void
Reads the system pasteboard content. This API uses an asynchronous callback to return the result. Obtains a **PasteData** object from the pasteboard. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[PasteData](#pastedata)&gt; | Yes | Callback used to return the system pasteboard data. | | callback | AsyncCallback&lt;[PasteData](#pastedata)&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the system pasteboard data. Otherwise, **err** is an error object.|
**Example** **Example**
```js ```js
var systemPasteboard = pasteboard.getSystemPasteboard(); var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.getPasteData((error, pasteData) => { systemPasteboard.getPasteData((err, pasteData) => {
if (error) { if (err) {
console.error('Failed to getPasteData. Cause: ' + error.message); console.error('Failed to get PasteData. Cause: ' + err.message);
return; return;
} }
var text = pasteData.getPrimaryText(); var text = pasteData.getPrimaryText();
}); });
``` ```
### getPasteData ### getPasteData
getPasteData(): Promise&lt;PasteData&gt; getPasteData(): Promise&lt;PasteData&gt;
Reads the system pasteboard content. This API uses a promise to return the result. Obtains a **PasteData** object from the pasteboard. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[PasteData](#pastedata)&gt; | Promise used to return the system pasteboard data. | | Promise&lt;[PasteData](#pastedata)&gt; | Promise used to return the system pasteboard data.|
**Example** **Example**
```js ```js
var systemPasteboard = pasteboard.getSystemPasteboard(); var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.getPasteData().then((pasteData) => { systemPasteboard.getPasteData().then((pasteData) => {
var text = pasteData.getPrimaryText(); var text = pasteData.getPrimaryText();
}).catch((error) => { }).catch((err) => {
console.error('Failed to getPasteData. Cause: ' + error.message); console.error('Failed to get PasteData. Cause: ' + err.message);
}) })
``` ```
### on('update')<sup>7+</sup> ### on('update')<sup>7+</sup>
on(type: 'update', callback: () =&gt;void ): void on(type: 'update', callback: () =&gt;void ): void
Subscribes to the content change event of the system pasteboard. If the pasteboard content changes, the callback is triggered. Subscribes to the content change event of the system pasteboard.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Data type. The value **update** indicates the pasteboard content has changed. | | type | string | Yes| Event type. The value **'update'** indicates changes in the pasteboard content.|
| callback | function | Yes | Callback invoked when the pasteboard content changes. | | callback | function | Yes| Callback invoked when the pasteboard content changes.|
**Example** **Example**
```js ```js
var systemPasteboard = pasteboard.getSystemPasteboard(); var systemPasteboard = pasteboard.getSystemPasteboard();
var listener = () => { var listener = () => {
console.info('The system pasteboard has changed'); console.info('The system pasteboard has changed.');
}; };
systemPasteboard.on('update', listener); systemPasteboard.on('update', listener);
``` ```
### off('update')<sup>7+</sup> ### off('update')<sup>7+</sup>
...@@ -981,120 +1248,120 @@ Unsubscribes from the system pasteboard content change event. ...@@ -981,120 +1248,120 @@ Unsubscribes from the system pasteboard content change event.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes | Data type. The value **update** indicates the pasteboard content has changed. | | type | string | Yes| Event type. The value **'update'** indicates changes in the pasteboard content.|
| callback | function | No | Callback invoked when the pasteboard content changes. | | callback | function | No| Callback invoked when the pasteboard content changes.|
**Example** **Example**
```js ```js
let listener = () => { let listener = () => {
console.info('The system pasteboard has changed'); console.info('The system pasteboard has changed.');
}; };
systemPasteboard.off('update', listener); systemPasteboard.off('update', listener);
``` ```
### hasPasteData<sup>7+</sup> ### hasPasteData<sup>7+</sup>
hasPasteData(callback: AsyncCallback&lt;boolean&gt;): void hasPasteData(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether the system pasteboard contains content. This API uses an asynchronous callback to return the result. Checks whether the system pasteboard contains data. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Returns **true** if the pasteboard contains content; returns **false** otherwise. | | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. Returns **true** if the system pasteboard contains data; returns **false** otherwise.|
**Example** **Example**
```js ```js
systemPasteboard.hasPasteData((err, data) => { systemPasteboard.hasPasteData((err, data) => {
if (err) { if (err) {
console.error('failed to hasPasteData because ' + JSON.stringify(err)); console.error('Failed to check the PasteData. Cause: ' + JSON.stringify(err));
return; return;
} }
console.info('success hasPasteData : ' + JSON.stringify(data)); console.info('Succeeded in checking the PasteData. Data: ' + JSON.stringify(data));
}); });
``` ```
### hasPasteData<sup>7+</sup> ### hasPasteData<sup>7+</sup>
hasPasteData(): Promise&lt;boolean&gt; hasPasteData(): Promise&lt;boolean&gt;
Checks whether the system pasteboard contains content. This API uses a promise to return the result. Checks whether the system pasteboard contains data. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Returns **true** if the pasteboard contains content; returns **false** otherwise. | | Promise&lt;boolean&gt; | Promise used to return the result. Returns **true** if the system pasteboard contains data; returns **false** otherwise.|
**Example** **Example**
```js ```js
systemPasteboard.hasPasteData().then((data) => { systemPasteboard.hasPasteData().then((data) => {
console.info('success hasPasteData : ' + JSON.stringify(data)); console.info('Succeeded in checking the PasteData. Data: ' + JSON.stringify(data));
}).catch((error) => { }).catch((err) => {
console.error('failed to hasPasteData because ' + JSON.stringify(error)); console.error('Failed to check the PasteData. Cause: ' + JSON.stringify(err));
}); });
``` ```
### clear<sup>7+</sup> ### clear<sup>7+</sup>
clear(callback: AsyncCallback&lt;void&gt;): void clear(callback: AsyncCallback&lt;void&gt;): void
Clears the system pasteboard content. This API uses an asynchronous callback to return the result. Clears the system pasteboard. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
**Example** **Example**
```js ```js
systemPasteboard.clear((err, data) => { systemPasteboard.clear((err, data) => {
if (err) { if (err) {
console.error('failed to clear because ' + JSON.stringify(err)); console.error('Failed to clear the PasteData. Cause: ' + JSON.stringify(err));
return; return;
} }
console.info('success clear'); console.info('Succeeded in clearing the PasteData.');
}); });
``` ```
### clear<sup>7+</sup> ### clear<sup>7+</sup>
clear(): Promise&lt;void&gt; clear(): Promise&lt;void&gt;
Clears the system pasteboard content. This API uses a promise to return the result. Clears the system pasteboard. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Return value** **Return value**
| Type | Description | | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result. | | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
systemPasteboard.clear().then((data) => { systemPasteboard.clear().then((data) => {
console.info('success clear'); console.info('Succeeded in clearing the PasteData.');
}).catch((error) => { }).catch((err) => {
console.error('failed to clear because ' + JSON.stringify(error)); console.error('Failed to clear the PasteData. Cause: ' + JSON.stringify(err));
}); });
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册