提交 806ef4a5 编写于 作者: W wusongqing

updated docs

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 23ff4f88
# FeatureAbility Module (JavaScript) # FeatureAbility Module (JavaScript)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> 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.
## Constraints ## Constraints
...@@ -17,7 +17,7 @@ import featureAbility from '@ohos.ability.featureAbility' ...@@ -17,7 +17,7 @@ import featureAbility from '@ohos.ability.featureAbility'
startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<number>): void startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<number>): void
Starts an ability. This method uses a callback to return the result. Starts an ability. This API uses a callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -42,8 +42,9 @@ featureAbility.startAbility( ...@@ -42,8 +42,9 @@ featureAbility.startAbility(
type: "", type: "",
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "", deviceId: "",
bundleName: "com.example.startability", bundleName: "com.example.myapplication",
abilityName: "com.example.startability.MainAbility", /* In the FA model, abilityName consists of package and ability name. */
abilityName: "com.example.entry.secondAbility",,
uri: "" uri: ""
}, },
}, },
...@@ -56,7 +57,7 @@ featureAbility.startAbility( ...@@ -56,7 +57,7 @@ featureAbility.startAbility(
startAbility(parameter: StartAbilityParameter): Promise\<number> startAbility(parameter: StartAbilityParameter): Promise\<number>
Starts an ability. This method uses a promise to return the result. Starts an ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -80,8 +81,9 @@ featureAbility.startAbility( ...@@ -80,8 +81,9 @@ featureAbility.startAbility(
type: "MIMETYPE", type: "MIMETYPE",
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "", deviceId: "",
bundleName: "com.example.startability", bundleName: "com.example.myapplication",
abilityName: "com.example.startability.MainAbility", /* In the FA model, abilityName consists of package and ability name. */
abilityName: "com.example.entry.secondAbility",
uri: "" uri: ""
}, },
} }
...@@ -123,7 +125,7 @@ featureAbility.acquireDataAbilityHelper( ...@@ -123,7 +125,7 @@ featureAbility.acquireDataAbilityHelper(
startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\<AbilityResult>): void startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\<AbilityResult>): void
Starts an ability. This method uses a callback to return the execution result when the ability is destroyed. Starts an ability. This API uses a callback to return the execution result when the ability is destroyed.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -148,8 +150,9 @@ featureAbility.startAbilityForResult( ...@@ -148,8 +150,9 @@ featureAbility.startAbilityForResult(
type: "MIMETYPE", type: "MIMETYPE",
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "", deviceId: "",
bundleName: "com.example.featureabilitytest", bundleName: "com.example.myapplication",
abilityName: "com.example.featureabilitytest.MainAbility", /* In the FA model, abilityName consists of package and ability name. */
abilityName: "com.example.entry.secondAbility",
uri:"" uri:""
}, },
}, },
...@@ -163,7 +166,7 @@ featureAbility.startAbilityForResult( ...@@ -163,7 +166,7 @@ featureAbility.startAbilityForResult(
startAbilityForResult(parameter: StartAbilityParameter): Promise\<AbilityResult> startAbilityForResult(parameter: StartAbilityParameter): Promise\<AbilityResult>
Starts an ability. This method uses a promise to return the execution result when the ability is destroyed. Starts an ability. This API uses a promise to return the execution result when the ability is destroyed.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -193,8 +196,9 @@ featureAbility.startAbilityForResult( ...@@ -193,8 +196,9 @@ featureAbility.startAbilityForResult(
type: "MIMETYPE", type: "MIMETYPE",
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "", deviceId: "",
bundleName: "com.example.featureabilitytest", bundleName: "com.example.myapplication",
abilityName: "com.example.featureabilitytest.MainAbility", /* In the FA model, abilityName consists of package and ability name. */
abilityName: "com.example.entry.secondAbility",
uri:"", uri:"",
parameters: parameters:
{ {
...@@ -219,7 +223,7 @@ featureAbility.startAbilityForResult( ...@@ -219,7 +223,7 @@ featureAbility.startAbilityForResult(
terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\<void>): void terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\<void>): void
Destroys this Page ability, with the result code and data sent to the caller. This method uses a callback to return the result. Destroys this Page ability, with the result code and data sent to the caller. This API uses a callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -245,8 +249,9 @@ featureAbility.terminateSelfWithResult( ...@@ -245,8 +249,9 @@ featureAbility.terminateSelfWithResult(
type: "MIMETYPE", type: "MIMETYPE",
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "", deviceId: "",
bundleName: "com.example.featureabilitytest", bundleName: "com.example.myapplication",
abilityName: "com.example.featureabilitytest.MainAbility", /* In the FA model, abilityName consists of package and ability name. */
abilityName: "com.example.entry.secondAbility",
uri:"", uri:"",
parameters: { parameters: {
mykey0: 2222, mykey0: 2222,
...@@ -267,7 +272,7 @@ featureAbility.terminateSelfWithResult( ...@@ -267,7 +272,7 @@ featureAbility.terminateSelfWithResult(
terminateSelfWithResult(parameter: AbilityResult): Promise\<void> terminateSelfWithResult(parameter: AbilityResult): Promise\<void>
Destroys this Page ability, with the result code and data sent to the caller. This method uses a promise to return the result. Destroys this Page ability, with the result code and data sent to the caller. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -298,8 +303,9 @@ featureAbility.terminateSelfWithResult( ...@@ -298,8 +303,9 @@ featureAbility.terminateSelfWithResult(
type: "MIMETYPE", type: "MIMETYPE",
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "", deviceId: "",
bundleName: "com.example.featureabilitytest", bundleName: "com.example.myapplication",
abilityName: "com.example.featureabilitytest.MainAbility", /* In the FA model, abilityName consists of package and ability name. */
abilityName: "com.example.entry.secondAbility",
uri:"", uri:"",
parameters: { parameters: {
mykey0: 2222, mykey0: 2222,
...@@ -324,7 +330,7 @@ featureAbility.terminateSelfWithResult( ...@@ -324,7 +330,7 @@ featureAbility.terminateSelfWithResult(
hasWindowFocus(callback: AsyncCallback\<boolean>): void hasWindowFocus(callback: AsyncCallback\<boolean>): void
Checks whether the main window of this ability has the focus. This method uses a callback to return the result. Checks whether the main window of this ability has the focus. This API uses a callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -347,7 +353,7 @@ featureAbility.hasWindowFocus() ...@@ -347,7 +353,7 @@ featureAbility.hasWindowFocus()
hasWindowFocus(): Promise\<boolean> hasWindowFocus(): Promise\<boolean>
Checks whether the main window of this ability has the focus. This method uses a promise to return the result. Checks whether the main window of this ability has the focus. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -372,7 +378,7 @@ featureAbility.hasWindowFocus().then((data) => { ...@@ -372,7 +378,7 @@ featureAbility.hasWindowFocus().then((data) => {
getWant(callback: AsyncCallback\<Want>): void getWant(callback: AsyncCallback\<Want>): void
Obtains the **Want** object sent from this ability. This method uses a callback to return the result. Obtains the **Want** object sent from this ability. This API uses a callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -395,7 +401,7 @@ featureAbility.getWant() ...@@ -395,7 +401,7 @@ featureAbility.getWant()
getWant(): Promise\<Want> getWant(): Promise\<Want>
Obtains the **Want** object sent from this ability. This method uses a promise to return the result. Obtains the **Want** object sent from this ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -442,7 +448,7 @@ context.getBundleName() ...@@ -442,7 +448,7 @@ context.getBundleName()
terminateSelf(callback: AsyncCallback\<void>): void terminateSelf(callback: AsyncCallback\<void>): void
Destroys this Page ability, with the result code and data sent to the caller. This method uses a callback to return the result. Destroys this Page ability, with the result code and data sent to the caller. This API uses a callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -465,7 +471,7 @@ featureAbility.terminateSelf() ...@@ -465,7 +471,7 @@ featureAbility.terminateSelf()
terminateSelf(): Promise\<void> terminateSelf(): Promise\<void>
Destroys this Page ability, with the result code and data sent to the caller. This method uses a promise to return the result. Destroys this Page ability, with the result code and data sent to the caller. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -488,7 +494,7 @@ featureAbility.terminateSelf().then((data) => { ...@@ -488,7 +494,7 @@ featureAbility.terminateSelf().then((data) => {
connectAbility(request: Want, options:ConnectOptions): number connectAbility(request: Want, options:ConnectOptions): number
Connects this ability to a specific Service ability. This method uses a callback to return the result. Connects this ability to a specific Service ability. This API uses a callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -557,7 +563,7 @@ var connId = featureAbility.connectAbility( ...@@ -557,7 +563,7 @@ var connId = featureAbility.connectAbility(
disconnectAbility(connection: number, callback:AsyncCallback\<void>): void disconnectAbility(connection: number, callback:AsyncCallback\<void>): void
Disconnects this ability from a specific Service ability. This method uses a callback to return the result. Disconnects this ability from a specific Service ability. This API uses a callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -604,7 +610,7 @@ var result = featureAbility.disconnectAbility(connId, ...@@ -604,7 +610,7 @@ var result = featureAbility.disconnectAbility(connId,
disconnectAbility(connection: number): Promise\<void> disconnectAbility(connection: number): Promise\<void>
Disconnects this ability from a specific Service ability. This method uses a promise to return the result. Disconnects this ability from a specific Service ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -656,7 +662,7 @@ featureAbility.disconnectAbility(connId).then((error,data) => { ...@@ -656,7 +662,7 @@ featureAbility.disconnectAbility(connId).then((error,data) => {
getWindow(callback: AsyncCallback\<window.Window>): void getWindow(callback: AsyncCallback\<window.Window>): void
Obtains the window corresponding to this ability. This method uses a callback to return the result. Obtains the window corresponding to this ability. This API uses a callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -676,7 +682,7 @@ featureAbility.getWindow() ...@@ -676,7 +682,7 @@ featureAbility.getWindow()
getWindow(): Promise\<window.Window>; getWindow(): Promise\<window.Window>;
Obtains the window corresponding to this ability. This method uses a promise to return the result. Obtains the window corresponding to this ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
......
# Pasteboard # Pasteboard
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>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
...@@ -20,11 +19,11 @@ import pasteboard from '@ohos.pasteboard'; ...@@ -20,11 +19,11 @@ import pasteboard from '@ohos.pasteboard';
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| MAX_RECORD_NUM<sup>7+</sup> | number | Yes | No | Maximum&nbsp;number&nbsp;of&nbsp;records&nbsp;allowed&nbsp;in&nbsp;a&nbsp;**PasteData**&nbsp;object. | | MAX_RECORD_NUM<sup>7+</sup> | number | Yes | No | Maximum number of records allowed in a **PasteData** object. |
| MIMETYPE_TEXT_HTML<sup>7+</sup> | string | Yes | No | MIME&nbsp;type&nbsp;of&nbsp;the&nbsp;HTML&nbsp;text. | | MIMETYPE_TEXT_HTML<sup>7+</sup> | string | Yes | No | MIME type of the HTML text. |
| MIMETYPE_TEXT_WANT<sup>7+</sup> | string | Yes | No | MIME&nbsp;type&nbsp;of&nbsp;the&nbsp;Want&nbsp;text. | | MIMETYPE_TEXT_WANT<sup>7+</sup> | string | Yes | No | MIME type of the Want text. |
| MIMETYPE_TEXT_PLAIN<sup>7+</sup> | string | Yes | No | MIME&nbsp;type&nbsp;of&nbsp;the&nbsp;plain&nbsp;text. | | MIMETYPE_TEXT_PLAIN<sup>7+</sup> | string | Yes | No | MIME type of the plain text. |
| MIMETYPE_TEXT_URI<sup>7+</sup> | string | Yes | No | MIME&nbsp;type&nbsp;of&nbsp;the&nbsp;URI&nbsp;text. | | MIMETYPE_TEXT_URI<sup>7+</sup> | string | Yes | No | MIME type of the URI text. |
## pasteboard.createPlainTextData ## pasteboard.createPlainTextData
...@@ -35,21 +34,23 @@ Creates a **PasteData** object for plain text. ...@@ -35,21 +34,23 @@ Creates a **PasteData** object for plain text.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| text | string | Yes | Plain&nbsp;text. |
- Return values | Name | Type | Mandatory | Description |
| Type | Description | | -------- | -------- | -------- | -------- |
| -------- | -------- | | text | string | Yes | Plain text. |
| [PasteData](#pastedata) | **PasteData**&nbsp;object&nbsp;with&nbsp;the&nbsp;specified&nbsp;content. |
- Example **Return value**
``` | Type | Description |
var pasteData = pasteboard.createPlainTextData("content"); | -------- | -------- |
``` | [PasteData](#pastedata) | **PasteData** object with the specified content. |
**Example**
```js
var pasteData = pasteboard.createPlainTextData("content");
```
## pasteboard.createHtmlData<sup>7+</sup> ## pasteboard.createHtmlData<sup>7+</sup>
...@@ -60,22 +61,24 @@ Creates a **PasteData** object for HTML text. ...@@ -60,22 +61,24 @@ Creates a **PasteData** object for HTML text.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | Name | Type | Mandatory | Description |
| htmlText | string | Yes | HTML&nbsp;text. | | -------- | -------- | -------- | -------- |
| htmlText | string | Yes | HTML text. |
- Return values **Return value**
| Type | Description |
| -------- | -------- |
| [PasteData](#pastedata) | **PasteData**&nbsp;object&nbsp;with&nbsp;the&nbsp;specified&nbsp;content. |
- Example | Type | Description |
| -------- | -------- |
``` | [PasteData](#pastedata) | **PasteData** object with the specified content. |
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); **Example**
```
```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 pasteData = pasteboard.createHtmlData(html);
```
## pasteboard.createWantData<sup>7+</sup> ## pasteboard.createWantData<sup>7+</sup>
...@@ -86,25 +89,27 @@ Creates a **PasteData** object for Want text. ...@@ -86,25 +89,27 @@ Creates a **PasteData** object for Want text.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes | Want&nbsp;text. |
- Return values | Name | Type | Mandatory | Description |
| Type | Description | | -------- | -------- | -------- | -------- |
| -------- | -------- | | want | [Want](js-apis-application-Want.md) | Yes | Want text. |
| [PasteData](#pastedata) | **PasteData**&nbsp;object&nbsp;with&nbsp;the&nbsp;specified&nbsp;content. |
- Example **Return value**
``` | Type | Description |
var object = { | -------- | -------- |
bundleName: "com.example.aafwk.test", | [PasteData](#pastedata) | **PasteData** object with the specified content. |
abilityName: "com.example.aafwk.test.TwoAbility"
}; **Example**
var pasteData = pasteboard.createWantData(object);
``` ```js
var object = {
bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility"
};
var pasteData = pasteboard.createWantData(object);
```
## pasteboard.createUriData<sup>7+</sup> ## pasteboard.createUriData<sup>7+</sup>
...@@ -115,21 +120,23 @@ Creates a **PasteData** object for URI text. ...@@ -115,21 +120,23 @@ Creates a **PasteData** object for URI text.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | Name | Type | Mandatory | Description |
| uri | string | Yes | URI&nbsp;text. | | -------- | -------- | -------- | -------- |
| uri | string | Yes | URI text. |
- Return values **Return value**
| Type | Description |
| -------- | -------- |
| [PasteData](#pastedata) | **PasteData**&nbsp;object&nbsp;with&nbsp;the&nbsp;specified&nbsp;content. |
- Example | Type | Description |
| -------- | -------- |
``` | [PasteData](#pastedata) | **PasteData** object with the specified content. |
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt");
``` **Example**
```js
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt");
```
## pasteboard.createPlainTextRecord<sup>7+</sup> ## pasteboard.createPlainTextRecord<sup>7+</sup>
...@@ -140,21 +147,23 @@ Creates a **PasteDataRecord** object of the plain text type. ...@@ -140,21 +147,23 @@ Creates a **PasteDataRecord** 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&nbsp;text. | | -------- | -------- | -------- | -------- |
| text | string | Yes | Plain text. |
- Return values **Return value**
| Type | Description |
| -------- | -------- |
| [PasteDataRecord](#pastedatarecord7) | New&nbsp;plain&nbsp;text&nbsp;record. |
- Example | Type | Description |
| -------- | -------- |
``` | [PasteDataRecord](#pastedatarecord7) | New plain text record. |
var record = pasteboard.createPlainTextRecord("hello");
``` **Example**
```js
var record = pasteboard.createPlainTextRecord("hello");
```
## pasteboard.createHtmlTextRecord<sup>7+</sup> ## pasteboard.createHtmlTextRecord<sup>7+</sup>
...@@ -165,22 +174,24 @@ Creates a **PasteDataRecord** object of the HTML text type. ...@@ -165,22 +174,24 @@ Creates a **PasteDataRecord** object of the HTML text 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&nbsp;text. | | -------- | -------- | -------- | -------- |
| htmlText | string | Yes | HTML text. |
**Return value**
- Return values | Type | Description |
| Type | Description | | -------- | -------- |
| -------- | -------- | | [PasteDataRecord](#pastedatarecord7) | New HTML record. |
| [PasteDataRecord](#pastedatarecord7) | New&nbsp;HTML&nbsp;record. |
- Example **Example**
``` ```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>
...@@ -191,25 +202,27 @@ Creates a **PasteDataRecord** object of the Want text type. ...@@ -191,25 +202,27 @@ Creates a **PasteDataRecord** object of the Want text type.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes | Want&nbsp;text. |
- Return values | Name | Type | Mandatory | Description |
| Type | Description | | -------- | -------- | -------- | -------- |
| -------- | -------- | | want | [Want](js-apis-application-Want.md) | Yes | Want text. |
| [PasteDataRecord](#pastedatarecord7) | New&nbsp;Want&nbsp;record. |
- Example **Return value**
``` | Type | Description |
var object = { | -------- | -------- |
bundleName: "com.example.aafwk.test", | [PasteDataRecord](#pastedatarecord7) | New Want record. |
abilityName: "com.example.aafwk.test.TwoAbility"
}; **Example**
var record = pasteboard.createWantRecord(object);
``` ```js
var object = {
bundleName: "com.example.aafwk.test",
abilityName: "com.example.aafwk.test.TwoAbility"
};
var record = pasteboard.createWantRecord(object);
```
## pasteboard.createUriRecord<sup>7+</sup> ## pasteboard.createUriRecord<sup>7+</sup>
...@@ -220,21 +233,23 @@ Creates a **PasteDataRecord** object of the URI text type. ...@@ -220,21 +233,23 @@ Creates a **PasteDataRecord** object of the URI text type.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;text. |
- Return values | Name | Type | Mandatory | Description |
| Type | Description | | -------- | -------- | -------- | -------- |
| -------- | -------- | | uri | string | Yes | URI text. |
| [PasteDataRecord](#pastedatarecord7) | New&nbsp;URI&nbsp;record. |
- Example **Return value**
``` | Type | Description |
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt"); | -------- | -------- |
``` | [PasteDataRecord](#pastedatarecord7) | New URI record. |
**Example**
```js
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
```
## PasteDataProperty<sup>7+</sup> ## PasteDataProperty<sup>7+</sup>
...@@ -245,11 +260,11 @@ Defines the properties of all data records on the pasteboard, including the time ...@@ -245,11 +260,11 @@ Defines the properties of all data records on the pasteboard, including the time
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| additions | {[key:&nbsp;string]:&nbsp;object} | Yes | Yes | Additional&nbsp;property&nbsp;data. | | additions | {[key: string]: object} | Yes | Yes | Additional property data. |
| mimeTypes | Array&lt;string&gt; | Yes | No | Non-repeating&nbsp;data&nbsp;types&nbsp;of&nbsp;the&nbsp;data&nbsp;records&nbsp;on&nbsp;the&nbsp;pasteboard. | | mimeTypes | Array&lt;string&gt; | Yes | No | Non-repeating data types of the data records on the pasteboard. |
| tag | string | Yes | Yes | User-defined&nbsp;tag. | | tag | string | Yes | Yes | User-defined tag. |
| timestamp | number | Yes | No | Timestamp&nbsp;at&nbsp;which&nbsp;the&nbsp;data&nbsp;is&nbsp;written&nbsp;to&nbsp;the&nbsp;pasteboard,&nbsp;in&nbsp;milliseconds. | | timestamp | number | Yes | No | Timestamp at which the data is written to the pasteboard, in milliseconds. |
| localOnly | boolean | Yes | Yes | Whether&nbsp;local&nbsp;access&nbsp;only&nbsp;is&nbsp;set&nbsp;for&nbsp;the&nbsp;pasteboard.<br/>-&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**true**.<br/>-&nbsp;**true**:&nbsp;The&nbsp;**PasteData**&nbsp;is&nbsp;set&nbsp;for&nbsp;local&nbsp;access&nbsp;only.<br/>-&nbsp;**false**:&nbsp;The&nbsp;**PasteData**&nbsp;can&nbsp;be&nbsp;shared&nbsp;between&nbsp;devices. | | 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. |
## PasteDataRecord<sup>7+</sup> ## PasteDataRecord<sup>7+</sup>
...@@ -263,63 +278,65 @@ A data record is an abstract definition of the content on the pasteboard. The pa ...@@ -263,63 +278,65 @@ A data record is an abstract definition of the content on the pasteboard. The pa
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| htmlText<sup>7+</sup> | string | Yes | No | HTML&nbsp;text. | | htmlText<sup>7+</sup> | string | Yes | No | HTML text. |
| want<sup>7+</sup> | [Want](js-apis-application-Want.md) | Yes | No | Want&nbsp;text. | | want<sup>7+</sup> | [Want](js-apis-application-Want.md) | Yes | No | Want text. |
| mimeType<sup>7+</sup> | string | Yes | No | Data&nbsp;type. | | mimeType<sup>7+</sup> | string | Yes | No | Data type. |
| plainText<sup>7+</sup> | string | Yes | No | Plain&nbsp;text. | | plainText<sup>7+</sup> | string | Yes | No | Plain text. |
| uri<sup>7+</sup> | string | Yes | No | URI&nbsp;text. | | uri<sup>7+</sup> | string | Yes | No | URI text. |
### 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 method uses a promise to return the result. Forcibly converts the content in this **PasteData** object to the plain text. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Return values **Return value**
| Type | Description |
| -------- | -------- |
| Promise&lt;void&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result.&nbsp;If&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful,&nbsp;the&nbsp;plain&nbsp;text&nbsp;content&nbsp;after&nbsp;conversion&nbsp;is&nbsp;returned.&nbsp;Otherwise,&nbsp;error&nbsp;information&nbsp;is&nbsp;returned. |
- Example | 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. |
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
record.convertToText().then((data) => { **Example**
console.info('convertToText success data : ' + JSON.stringify(data));
}).catch((error) => { ```js
console.error('convertToText failed because ' + JSON.stringify(error)); var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
}); record.convertToText().then((data) => {
``` console.info('convertToText success data : ' + JSON.stringify(data));
}).catch((error) => {
console.error('convertToText failed because ' + JSON.stringify(error));
});
```
### 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 method uses an asynchronous callback to return the result. Forcibly converts the content in this **PasteData** object to the plain 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&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result.&nbsp;If&nbsp;this&nbsp;callback&nbsp;is&nbsp;successful,&nbsp;the&nbsp;plain&nbsp;text&nbsp;content&nbsp;after&nbsp;conversion&nbsp;is&nbsp;returned.&nbsp;Otherwise,&nbsp;error&nbsp;information&nbsp;is&nbsp;returned. | | -------- | -------- | -------- | -------- |
| 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. |
- Example
**Example**
```
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt"); ```js
record.convertToText((err, data) => { var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt");
if (err) { record.convertToText((err, data) => {
console.error('convertToText failed because ' + JSON.stringify(err)); if (err) {
return; console.error('convertToText failed because ' + JSON.stringify(err));
} return;
console.info('convertToText success data : ' + JSON.stringify(data)); }
}); console.info('convertToText success data : ' + JSON.stringify(data));
``` });
```
## PasteData ## PasteData
...@@ -340,22 +357,19 @@ Obtains the plain text of the primary record. ...@@ -340,22 +357,19 @@ Obtains the plain text of the primary record.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
**Return value**
- Parameters
None
| Type | Description |
| -------- | -------- |
| string | Plain text. |
- Return values **Example**
| Type | Description |
| -------- | -------- |
| string | Plain&nbsp;text. |
- Example ```js
var pasteData = pasteboard.createPlainTextData("hello");
``` var plainText = pasteData.getPrimaryText();
var pasteData = pasteboard.createPlainTextData("hello"); ```
var plainText = pasteData.getPrimaryText();
```
### getPrimaryHtml<sup>7+</sup> ### getPrimaryHtml<sup>7+</sup>
...@@ -366,18 +380,19 @@ Obtains the HTML text of the primary record. ...@@ -366,18 +380,19 @@ Obtains the HTML text of the primary record.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Return values **Return value**
| Type | Description |
| -------- | -------- |
| string | HTML&nbsp;text. |
- Example | Type | Description |
| -------- | -------- |
``` | string | HTML text. |
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); **Example**
var htmlText = pasteData.getPrimaryHtml();
``` ```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 pasteData = pasteboard.createHtmlData(html);
var htmlText = pasteData.getPrimaryHtml();
```
### getPrimaryWant<sup>7+</sup> ### getPrimaryWant<sup>7+</sup>
...@@ -388,21 +403,22 @@ Obtains the **Want** object of the primary record. ...@@ -388,21 +403,22 @@ Obtains the **Want** object of the primary record.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Return values **Return value**
| Type | Description |
| -------- | -------- | | Type | Description |
| [Want](js-apis-featureAbility.md#want) | Want&nbsp;object. | | -------- | -------- |
| [Want](js-apis-application-Want.md) | Want object. |
**Example**
- Example ```js
var object = {
``` bundleName: "com.example.aafwk.test",
var object = { abilityName: "com.example.aafwk.test.TwoAbility"
bundleName: "com.example.aafwk.test", };
abilityName: "com.example.aafwk.test.TwoAbility" var pasteData = pasteboard.createWantData(object);
}; var want = pasteData.getPrimaryWant();
var pasteData = pasteboard.createWantData(object); ```
var want = pasteData.getPrimaryWant();
```
### getPrimaryUri<sup>7+</sup> ### getPrimaryUri<sup>7+</sup>
...@@ -413,17 +429,18 @@ Obtains the URI text of the primary record. ...@@ -413,17 +429,18 @@ Obtains the URI text of the primary record.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Return values **Return value**
| Type | Description |
| -------- | -------- | | Type | Description |
| string | URI&nbsp;text. | | -------- | -------- |
| string | URI text. |
- Example **Example**
``` ```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();
``` ```
### addTextRecord<sup>7+</sup> ### addTextRecord<sup>7+</sup>
...@@ -436,17 +453,18 @@ The pasteboard supports a maximum number of 128 data records. ...@@ -436,17 +453,18 @@ The pasteboard supports a maximum number of 128 data records.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| text | string | Yes | Plain&nbsp;text. |
- Example | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
``` | text | string | Yes | Plain text. |
var pasteData = pasteboard.createPlainTextData("hello");
pasteData.addTextRecord("good"); **Example**
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
pasteData.addTextRecord("good");
```
### addHtmlRecord<sup>7+</sup> ### addHtmlRecord<sup>7+</sup>
...@@ -459,18 +477,19 @@ The pasteboard supports a maximum number of 128 data records. ...@@ -459,18 +477,19 @@ The pasteboard supports a maximum number of 128 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&nbsp;text. | | -------- | -------- | -------- | -------- |
| htmlText | string | Yes | HTML text. |
**Example**
- Example ```js
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 pasteData = pasteboard.createPlainTextData("hello"); pasteData.addHtmlRecord(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);
```
### addWantRecord<sup>7+</sup> ### addWantRecord<sup>7+</sup>
...@@ -483,21 +502,22 @@ The pasteboard supports a maximum number of 128 data records. ...@@ -483,21 +502,22 @@ The pasteboard supports a maximum number of 128 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-featureAbility.md#want) | Yes | Want&nbsp;object. | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes | Want object. |
- Example **Example**
``` ```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>
...@@ -510,17 +530,18 @@ The pasteboard supports a maximum number of 128 data records. ...@@ -510,17 +530,18 @@ The pasteboard supports a maximum number of 128 data records.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;text. |
- Example | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
``` | uri | string | Yes | URI text. |
var pasteData = pasteboard.createPlainTextData("hello");
pasteData.addUriRecord("dataability:///com.example.myapplication1?user.txt"); **Example**
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
pasteData.addUriRecord("dataability:///com.example.myapplication1?user.txt");
```
### addRecord<sup>7+</sup> ### addRecord<sup>7+</sup>
...@@ -533,21 +554,22 @@ The pasteboard supports a maximum number of 128 data records. ...@@ -533,21 +554,22 @@ The pasteboard supports a maximum number of 128 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&nbsp;to&nbsp;add. | | -------- | -------- | -------- | -------- |
| record | [PasteDataRecord](#pastedatarecord7) | Yes | Record to add. |
**Example**
- Example ```js
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt");
``` var textRecord = pasteboard.createPlainTextRecord("hello");
var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt"); 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 textRecord = pasteboard.createPlainTextRecord("hello"); var htmlRecord = pasteboard.createHtmlTextRecord(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.addRecord(textRecord);
var htmlRecord = pasteboard.createHtmlTextRecord(html); pasteData.addRecord(htmlRecord);
pasteData.addRecord(textRecord); ```
pasteData.addRecord(htmlRecord);
```
### getMimeTypes<sup>7+</sup> ### getMimeTypes<sup>7+</sup>
...@@ -558,17 +580,18 @@ Obtains **mimeTypes** in [PasteDataProperty](#pastedataproperty7) from this past ...@@ -558,17 +580,18 @@ Obtains **mimeTypes** in [PasteDataProperty](#pastedataproperty7) from this past
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Return values **Return value**
| Type | Description |
| -------- | -------- | | Type | Description |
| Array&lt;string&gt; | List&nbsp;of&nbsp;non-duplicate&nbsp;MIME&nbsp;types. | | -------- | -------- |
| Array&lt;string&gt; | List of non-duplicate MIME types. |
- Example **Example**
``` ```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>
...@@ -579,17 +602,18 @@ Obtains the data type of the primary record. ...@@ -579,17 +602,18 @@ Obtains the data type of the primary record.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Return values **Return value**
| Type | Description |
| -------- | -------- |
| string | Data&nbsp;type&nbsp;of&nbsp;the&nbsp;primary&nbsp;record. |
- Example | Type | Description |
| -------- | -------- |
``` | string | Data type of the primary record. |
var pasteData = pasteboard.createPlainTextData("hello");
var type = pasteData.getPrimaryMimeType(); **Example**
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
var type = pasteData.getPrimaryMimeType();
```
### getProperty<sup>7+</sup> ### getProperty<sup>7+</sup>
...@@ -600,17 +624,18 @@ Obtains the property description object. ...@@ -600,17 +624,18 @@ Obtains the property description object.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Return values **Return value**
| Type | Description |
| -------- | -------- | | Type | Description |
| [PasteDataProperty](#pastedataproperty7) | Property&nbsp;description&nbsp;object. | | -------- | -------- |
| [PasteDataProperty](#pastedataproperty7) | Property description object. |
**Example**
- Example ```js
var pasteData = pasteboard.createPlainTextData("hello");
``` var property = pasteData.getProperty();
var pasteData = pasteboard.createPlainTextData("hello"); ```
var property = pasteData.getProperty();
```
### getRecordAt<sup>7+</sup> ### getRecordAt<sup>7+</sup>
...@@ -621,22 +646,24 @@ Obtains the record with the specified index. ...@@ -621,22 +646,24 @@ Obtains the record with the specified index.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | Name | Type | Mandatory | Description |
| index | number | Yes | Index&nbsp;of&nbsp;the&nbsp;specified&nbsp;record. | | -------- | -------- | -------- | -------- |
| index | number | Yes | Index of the specified record. |
**Return value**
- Return values | Type | Description |
| Type | Description | | -------- | -------- |
| -------- | -------- | | [PasteDataRecord](#pastedatarecord7) | Record with the specified index. |
| [PasteDataRecord](#pastedatarecord7) | Record&nbsp;with&nbsp;the&nbsp;specified&nbsp;index. |
- Example **Example**
``` ```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>
...@@ -647,17 +674,18 @@ Obtains the number of data records in this pasteboard. ...@@ -647,17 +674,18 @@ Obtains the number of data records in this pasteboard.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Return values **Return value**
| Type | Description |
| -------- | -------- |
| number | Number&nbsp;of&nbsp;records. |
- Example | Type | Description |
| -------- | -------- |
``` | number | Number of records. |
var pasteData = pasteboard.createPlainTextData("hello");
var count = pasteData.getRecordCount(); **Example**
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
var count = pasteData.getRecordCount();
```
### getTag<sup>7+</sup> ### getTag<sup>7+</sup>
...@@ -668,17 +696,18 @@ Obtains the user-defined tag content. If the tag content is not set, null is ret ...@@ -668,17 +696,18 @@ Obtains the user-defined tag content. If the tag content is not set, null is ret
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Return values **Return value**
| Type | Description |
| -------- | -------- |
| string | User-defined&nbsp;tag&nbsp;content&nbsp;if&nbsp;obtained&nbsp;and&nbsp;null&nbsp;if&nbsp;no&nbsp;tag&nbsp;is&nbsp;set. |
- Example | Type | Description |
| -------- | -------- |
``` | string | User-defined tag content if obtained and null if no tag is set. |
var pasteData = pasteboard.createPlainTextData("hello");
var tag = pasteData.getTag(); **Example**
```
```js
var pasteData = pasteboard.createPlainTextData("hello");
var tag = pasteData.getTag();
```
### hasMimeType<sup>7+</sup> ### hasMimeType<sup>7+</sup>
...@@ -689,22 +718,24 @@ Checks whether the content of this pasteboard contains the specified data type. ...@@ -689,22 +718,24 @@ Checks whether the content of this pasteboard contains the specified data 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&nbsp;of&nbsp;the&nbsp;data&nbsp;to&nbsp;query. | | -------- | -------- | -------- | -------- |
| mimeType | string | Yes | Type of the data to query. |
**Return value**
- Return values | Type | Description |
| Type | Description | | -------- | -------- |
| -------- | -------- | | boolean | Returns **true** if the specified data type exists; returns **false** otherwise. |
| boolean | Returns&nbsp;**true**&nbsp;if&nbsp;the&nbsp;specified&nbsp;data&nbsp;type&nbsp;exists;&nbsp;returns&nbsp;**false**&nbsp;otherwise. |
- Example **Example**
``` ```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>
...@@ -715,22 +746,24 @@ Removes the data record with a specified index from this pasteboard. ...@@ -715,22 +746,24 @@ Removes the data record with a specified index from this pasteboard.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| index | number | Yes | Specified&nbsp;index. |
- Return values | Name | Type | Mandatory | Description |
| Type | Description | | -------- | -------- | -------- | -------- |
| -------- | -------- | | index | number | Yes | Specified index. |
| boolean | Returns&nbsp;**true**&nbsp;if&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful;&nbsp;returns&nbsp;**false**&nbsp;otherwise. |
- Example **Return value**
``` | Type | Description |
var pasteData = pasteboard.createPlainTextData("hello"); | -------- | -------- |
var isRemove = pasteData.removeRecordAt(0); | boolean | Returns **true** if the operation is successful; returns **false** otherwise. |
```
**Example**
```js
var pasteData = pasteboard.createPlainTextData("hello");
var isRemove = pasteData.removeRecordAt(0);
```
### replaceRecordAt<sup>7+</sup> ### replaceRecordAt<sup>7+</sup>
...@@ -741,24 +774,26 @@ Replaces the data record with a specified index in this pasteboard. ...@@ -741,24 +774,26 @@ Replaces the data record with a specified index in this pasteboard.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| index | number | Yes | Specified&nbsp;index. |
| record | [PasteDataRecord](#pastedatarecord7) | Yes | New&nbsp;record. |
- Return values | Name | Type | Mandatory | Description |
| Type | Description | | -------- | -------- | -------- | -------- |
| -------- | -------- | | index | number | Yes | Specified index. |
| boolean | Returns&nbsp;**true**&nbsp;if&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful;&nbsp;returns&nbsp;**false**&nbsp;otherwise. | | record | [PasteDataRecord](#pastedatarecord7) | Yes | New record. |
- Example **Return value**
``` | Type | Description |
var pasteData = pasteboard.createPlainTextData("hello"); | -------- | -------- |
var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt"); | boolean | Returns **true** if the operation is successful; returns **false** otherwise. |
var isReplace = pasteData.replaceRecordAt(0, record);
``` **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 ## pasteboard.getSystemPasteboard
...@@ -769,21 +804,22 @@ Obtains the system pasteboard. ...@@ -769,21 +804,22 @@ Obtains the system pasteboard.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Return values **Return value**
| Type | Description |
| -------- | -------- |
| [SystemPasteboard](#systempasteboard) | System&nbsp;pasteboard. |
- Example | Type | Description |
| -------- | -------- |
``` | [SystemPasteboard](#systempasteboard) | System pasteboard. |
var systemPasteboard = pasteboard.getSystemPasteboard();
``` **Example**
```js
var systemPasteboard = pasteboard.getSystemPasteboard();
```
## SystemPasteboard ## SystemPasteboard
Before calling any **SystemPasteboard** method, you must obtain a **SystemPasteboard** object using [getSystemPasteboard](#pasteboardgetsystempasteboard). Before calling any **SystemPasteboard** method, you must obtain a **SystemPasteboard** object using [getSystemPasteboard](#pasteboardgetsystempasteboard).
``` ```
var systemPasteboard = pasteboard.getSystemPasteboard(); var systemPasteboard = pasteboard.getSystemPasteboard();
...@@ -794,112 +830,117 @@ var systemPasteboard = pasteboard.getSystemPasteboard(); ...@@ -794,112 +830,117 @@ var systemPasteboard = pasteboard.getSystemPasteboard();
setPasteData(data:PasteData, callback:AsyncCallback&lt;void&gt;): void setPasteData(data:PasteData, callback:AsyncCallback&lt;void&gt;): void
Writes data to a pasteboard. This method uses an asynchronous callback to return the result. Writes data to a 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**&nbsp;object. | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;data&nbsp;write&nbsp;result. | | data | [PasteData](#pastedata) | Yes | **PasteData** object. |
| callback | AsyncCallback&lt;void> | Yes | Callback used to return the data write result. |
- Example
**Example**
```
var pasteData = pasteboard.createPlainTextData("content"); ```js
var systemPasteboard = pasteboard.getSystemPasteboard(); var pasteData = pasteboard.createPlainTextData("content");
systemPasteboard.setPasteData(pasteData, (error, data) => { var systemPasteboard = pasteboard.getSystemPasteboard();
if (error) { systemPasteboard.setPasteData(pasteData, (error, data) => {
console.error('Failed to setPasteData. Cause: ' + error.message); if (error) {
return; console.error('Failed to setPasteData. Cause: ' + error.message);
} return;
console.info('setPasteData successfully.'); }
}); console.info('setPasteData successfully.');
``` });
```
### setPasteData ### setPasteData
setPasteData(data:PasteData): Promise&lt;void&gt; setPasteData(data:PasteData): Promise&lt;void&gt;
Writes data to a pasteboard. This method uses a promise to return the result. Writes data to a 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**&nbsp;object. | | -------- | -------- | -------- |
| data | [PasteData](#pastedata) | **PasteData** object. |
- Return values
| Type | Description | **Return value**
| -------- | -------- |
| Promise&lt;void&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;data&nbsp;write&nbsp;result. | | Type | Description |
| -------- | -------- |
- Example | Promise&lt;void&gt; | Promise used to return the data write result. |
``` **Example**
var pasteData = pasteboard.createPlainTextData("content");
var systemPasteboard = pasteboard.getSystemPasteboard(); ```js
systemPasteboard.setPasteData(pasteData).then((data) => { var pasteData = pasteboard.createPlainTextData("content");
console.info('setPasteData success.'); var systemPasteboard = pasteboard.getSystemPasteboard();
}).catch((error) => { systemPasteboard.setPasteData(pasteData).then((data) => {
console.error('Failed to setPasteData. Cause: ' + error.message); console.info('setPasteData success.');
}); }).catch((error) => {
``` console.error('Failed to setPasteData. Cause: ' + error.message);
});
```
### getPasteData ### getPasteData
getPasteData( callback:AsyncCallback&lt;PasteData&gt;): void getPasteData( callback:AsyncCallback&lt;PasteData&gt;): void
Reads the system pasteboard content. This method uses an asynchronous callback to return the result. Reads the system pasteboard content. 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&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;system&nbsp;pasteboard&nbsp;data. | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[PasteData](#pastedata)&gt; | Yes | Callback used to return the system pasteboard data. |
- Example
**Example**
```
var systemPasteboard = pasteboard.getSystemPasteboard(); ```js
systemPasteboard.getPasteData((error, pasteData) => { var systemPasteboard = pasteboard.getSystemPasteboard();
if (error) { systemPasteboard.getPasteData((error, pasteData) => {
console.error('Failed to getPasteData. Cause: ' + error.message); if (error) {
return; console.error('Failed to getPasteData. Cause: ' + error.message);
} 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 method uses a promise to return the result. Reads the system pasteboard content. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Return values **Return value**
| Type | Description |
| -------- | -------- |
| Promise&lt;[PasteData](#pastedata)&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;system&nbsp;pasteboard&nbsp;data. |
- Example | Type | Description |
| -------- | -------- |
``` | Promise&lt;[PasteData](#pastedata)&gt; | Promise used to return the system pasteboard data. |
var systemPasteboard = pasteboard.getSystemPasteboard();
systemPasteboard.getPasteData().then((pasteData) => { **Example**
var text = pasteData.getPrimaryText();
}).catch((error) => { ```js
console.error('Failed to getPasteData. Cause: ' + error.message); var systemPasteboard = pasteboard.getSystemPasteboard();
}) systemPasteboard.getPasteData().then((pasteData) => {
``` var text = pasteData.getPrimaryText();
}).catch((error) => {
console.error('Failed to getPasteData. Cause: ' + error.message);
})
```
### on('update')<sup>7+</sup> ### on('update')<sup>7+</sup>
...@@ -910,21 +951,22 @@ Subscribes to the content change event of the system pasteboard. If the pasteboa ...@@ -910,21 +951,22 @@ Subscribes to the content change event of the system pasteboard. If the pasteboa
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| type | string | Yes | Data&nbsp;type.&nbsp;The&nbsp;value&nbsp;**update**&nbsp;indicates&nbsp;the&nbsp;pasteboard&nbsp;content&nbsp;has&nbsp;changed. |
| callback | function | Yes | Callback&nbsp;invoked&nbsp;when&nbsp;the&nbsp;pasteboard&nbsp;content&nbsp;changes. |
- Example | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
``` | type | string | Yes | Data type. The value **update** indicates the pasteboard content has changed. |
var systemPasteboard = pasteboard.getSystemPasteboard(); | callback | function | Yes | Callback invoked when the pasteboard content changes. |
var listener = ()=>{
console.info('The system pasteboard has changed'); **Example**
};
systemPasteboard.on('update', listener); ```js
``` var systemPasteboard = pasteboard.getSystemPasteboard();
var listener = ()=>{
console.info('The system pasteboard has changed');
};
systemPasteboard.on('update', listener);
```
### off('update')<sup>7+</sup> ### off('update')<sup>7+</sup>
...@@ -935,114 +977,119 @@ Unsubscribes from the system pasteboard content change event. ...@@ -935,114 +977,119 @@ Unsubscribes from the system pasteboard content change event.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | Name | Type | Mandatory | Description |
| type | string | Yes | Data&nbsp;type.&nbsp;The&nbsp;value&nbsp;**update**&nbsp;indicates&nbsp;the&nbsp;pasteboard&nbsp;content&nbsp;has&nbsp;changed. | | -------- | -------- | -------- | -------- |
| callback | function | No | Callback&nbsp;invoked&nbsp;when&nbsp;the&nbsp;pasteboard&nbsp;content&nbsp;changes. | | type | string | Yes | Data type. The value **update** indicates the pasteboard content has changed. |
| callback | function | No | Callback invoked when the pasteboard content changes. |
- Example **Example**
``` ```js
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 method uses an asynchronous callback to return the result. Checks whether the system pasteboard contains content. 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&nbsp;**true**&nbsp;if&nbsp;the&nbsp;pasteboard&nbsp;contains&nbsp;content;&nbsp;returns&nbsp;**false**&nbsp;otherwise. | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Returns **true** if the pasteboard contains content; returns **false** otherwise. |
- Example
**Example**
```
systemPasteboard.hasPasteData((err, data) => { ```js
if (err) { systemPasteboard.hasPasteData((err, data) => {
console.error('failed to hasPasteData because ' + JSON.stringify(err)); if (err) {
return; console.error('failed to hasPasteData because ' + JSON.stringify(err));
} return;
console.info('success hasPasteData : ' + JSON.stringify(data)); }
}); console.info('success hasPasteData : ' + 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 method uses a promise to return the result. Checks whether the system pasteboard contains content. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Return values **Return value**
| Type | Description |
| -------- | -------- | | Type | Description |
| Promise&lt;boolean&gt; | Returns&nbsp;**true**&nbsp;if&nbsp;the&nbsp;pasteboard&nbsp;contains&nbsp;content;&nbsp;returns&nbsp;**false**&nbsp;otherwise. | | -------- | -------- |
| Promise&lt;boolean&gt; | Returns **true** if the pasteboard contains content; returns **false** otherwise. |
**Example**
- Example ```js
systemPasteboard.hasPasteData().then((data) => {
``` console.info('Operation succeeded. ' + JSON.stringify(data));
systemPasteboard.hasPasteData().then((data) => { }).catch((error) => {
console.info('Operation succeeded. ' + JSON.stringify(data)); console.error('failed to hasPasteData because ' + JSON.stringify(error));
}).catch((error) => { });
console.error('failed to hasPasteData because ' + JSON.stringify(error)); ```
});
```
### 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 method uses an asynchronous callback to return the result. Clears the system pasteboard content. 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&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result. | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
- Example
**Example**
```
systemPasteboard.clear((err, data) => { ```js
if (err) { systemPasteboard.clear((err, data) => {
console.error('failed to clear because ' + JSON.stringify(err)); if (err) {
return; console.error('failed to clear because ' + JSON.stringify(err));
} return;
console.info('success clear'); }
}); console.info('success clear');
``` });
```
### clear<sup>7+</sup> ### clear<sup>7+</sup>
clear(): Promise&lt;void&gt; clear(): Promise&lt;void&gt;
Clears the system pasteboard content. This method uses a promise to return the result. Clears the system pasteboard content. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Pasteboard **System capability**: SystemCapability.MiscServices.Pasteboard
- Return values **Return value**
| Type | Description |
| -------- | -------- | | Type | Description |
| Promise&lt;void&gt; | Promise&nbsp;used&nbsp;to&nbsp;return&nbsp;the&nbsp;result. | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result. |
- Example
**Example**
```
systemPasteboard.clear().then((data) => { ```js
console.info('success clear'); systemPasteboard.clear().then((data) => {
}).catch((error) => { console.info('success clear');
console.error('failed to clear because ' + JSON.stringify(error)); }).catch((error) => {
}); console.error('failed to clear because ' + JSON.stringify(error));
``` });
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册