提交 d9d17be2 编写于 作者: W wusongqing

updated docs against 4749

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 fba44f02
# Context Module # Context
> **NOTE**<br/> > **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.
>
> The APIs of this module can be used only in the FA module.
## Modules to Import ## Modules to Import
...@@ -96,8 +99,8 @@ Verifies whether a specific PID and UID have the given permission. This API uses ...@@ -96,8 +99,8 @@ Verifies whether a specific PID and UID have the given permission. This API uses
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
import bundle from '@ohos.bundle' import bundle from '@ohos.bundle'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
bundle.getBundleInfo('com.context.test', 1, (datainfo) =>{ bundle.getBundleInfo('com.context.test', 1, (err,datainfo) =>{
context.verifyPermission("com.example.permission", datainfo.uid); context.verifyPermission("com.example.permission", {uid:datainfo.uid});
}); });
``` ```
...@@ -152,7 +155,7 @@ Verifies whether a specific PID and UID have the given permission. This API uses ...@@ -152,7 +155,7 @@ Verifies whether a specific PID and UID have the given permission. This API uses
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
var Permission = context.PermissionOptions(1,1); var Permission = {pid:1};
context.verifyPermission('com.context.permission',Permission).then((data) => { context.verifyPermission('com.context.permission',Permission).then((data) => {
console.info("======================>verifyPermissionCallback====================>"); console.info("======================>verifyPermissionCallback====================>");
console.info("====>data====>" + JSON.stringify(data)); console.info("====>data====>" + JSON.stringify(data));
......
# DataUriUtils Module # DataUriUtils
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 7. 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 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -32,7 +33,7 @@ Obtains the ID attached to the end of a given URI. ...@@ -32,7 +33,7 @@ Obtains the ID attached to the end of a given URI.
**Example** **Example**
```js ```js
dataUriUtils.getIdSync("com.example.dataUriUtils/1221") dataUriUtils.getId("com.example.dataUriUtils/1221")
``` ```
......
# AbilityContext # AbilityContext
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs of this module can be used only in the stage model.
Implements the ability context. This module is inherited from **Context**. Implements the ability context. This module is inherited from **Context**.
## Modules to Import
```js
import Ability from '@ohos.application.Ability'
```
## Usage ## Usage
Before using the **AbilityContext** module, you must define a child class that inherits from **Ability**. Before using the **AbilityContext** module, you must define a child class that inherits from **Ability**.
```js ```js
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
class MainAbility extends Ability { class MainAbility extends Ability {
...@@ -28,10 +34,10 @@ class MainAbility extends Ability { ...@@ -28,10 +34,10 @@ class MainAbility extends Ability {
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| abilityInfo | AbilityInfo | Yes| No| Ability information.| | abilityInfo | AbilityInfo | Yes| No| Ability information.|
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.| | currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.|
## AbilityContext.startAbility ## AbilityContext.startAbility
...@@ -44,10 +50,10 @@ Starts an ability. This API uses a callback to return the result. ...@@ -44,10 +50,10 @@ Starts an ability. This API uses a callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.| | want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -55,7 +61,7 @@ Starts an ability. This API uses a callback to return the result. ...@@ -55,7 +61,7 @@ Starts an ability. This API uses a callback to return the result.
var want = { var want = {
"deviceId": "", "deviceId": "",
"bundleName": "com.extreme.test", "bundleName": "com.extreme.test",
"abilityName": "com.extreme.test.MainAbility" "abilityName": "MainAbility"
}; };
this.context.startAbility(want, (error) => { this.context.startAbility(want, (error) => {
console.log("error.code = " + error.code) console.log("error.code = " + error.code)
...@@ -73,11 +79,11 @@ Starts an ability. This API uses a callback to return the result. ...@@ -73,11 +79,11 @@ Starts an ability. This API uses a callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.| | want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | Yes| Parameters used for starting the ability.| | options | StartOptions | Yes| Parameters used for starting the ability.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -85,7 +91,7 @@ Starts an ability. This API uses a callback to return the result. ...@@ -85,7 +91,7 @@ Starts an ability. This API uses a callback to return the result.
var want = { var want = {
"deviceId": "", "deviceId": "",
"bundleName": "com.extreme.test", "bundleName": "com.extreme.test",
"abilityName": "com.extreme.test.MainAbility" "abilityName": "MainAbility"
}; };
var options = { var options = {
windowMode: 0, windowMode: 0,
...@@ -106,16 +112,16 @@ Starts an ability. This API uses a promise to return the result. ...@@ -106,16 +112,16 @@ Starts an ability. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.| | want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | No| Parameters used for starting the ability.| | options | StartOptions | No| Parameters used for starting the ability.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -123,7 +129,7 @@ Starts an ability. This API uses a promise to return the result. ...@@ -123,7 +129,7 @@ Starts an ability. This API uses a promise to return the result.
var want = { var want = {
"deviceId": "", "deviceId": "",
"bundleName": "com.extreme.test", "bundleName": "com.extreme.test",
"abilityName": "com.extreme.test.MainAbility" "abilityName": "MainAbility"
}; };
var options = { var options = {
windowMode: 0, windowMode: 0,
...@@ -147,10 +153,10 @@ Starts an ability. This API uses a callback to return the execution result when ...@@ -147,10 +153,10 @@ Starts an ability. This API uses a callback to return the execution result when
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want |[Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.| | want |[Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
| callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -175,11 +181,11 @@ Starts an ability. This API uses a callback to return the execution result when ...@@ -175,11 +181,11 @@ Starts an ability. This API uses a callback to return the execution result when
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want |[Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.| | want |[Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | Yes| Parameters used for starting the ability.| | options | StartOptions | Yes| Parameters used for starting the ability.|
| callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -208,17 +214,17 @@ Starts an ability. This API uses a promise to return the execution result when t ...@@ -208,17 +214,17 @@ Starts an ability. This API uses a promise to return the execution result when t
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.| | want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | No| Parameters used for starting the ability.| | options | StartOptions | No| Parameters used for starting the ability.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------- | -------- | | -------- | -------- |
| Promise&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Promise used to return the result.| | Promise&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -244,9 +250,9 @@ Terminates this ability. This API uses a callback to return the result. ...@@ -244,9 +250,9 @@ Terminates this ability. This API uses a callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.|
**Example** **Example**
...@@ -267,9 +273,9 @@ Terminates this ability. This API uses a promise to return the result. ...@@ -267,9 +273,9 @@ Terminates this ability. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Example** **Example**
...@@ -292,10 +298,10 @@ Terminates this ability. This API uses a callback to return the information to t ...@@ -292,10 +298,10 @@ Terminates this ability. This API uses a callback to return the information to t
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.| | parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -321,15 +327,15 @@ Terminates this ability. This API uses a promise to return information to the ca ...@@ -321,15 +327,15 @@ Terminates this ability. This API uses a promise to return information to the ca
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.| | parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -355,18 +361,18 @@ Obtains the caller interface of the specified ability, and if the specified abil ...@@ -355,18 +361,18 @@ Obtains the caller interface of the specified ability, and if the specified abil
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the ability to start, including the ability name, bundle name, and device ID. If the device ID is left blank or the default value is used, the local ability will be started.| | want | [Want](js-apis-application-Want.md) | Yes| Information about the ability to start, including the ability name, bundle name, and device ID. If the device ID is left blank or the default value is used, the local ability will be started.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------- | -------- | | -------- | -------- |
| Promise&lt;Caller&gt; | Promise used to return the caller object to communicate with.| | Promise&lt;Caller&gt; | Promise used to return the caller object to communicate with.|
**Example** **Example**
```js ```js
import Ability from '@ohos.application.Ability'; import Ability from '@ohos.application.Ability';
var caller; var caller;
...@@ -374,11 +380,11 @@ Obtains the caller interface of the specified ability, and if the specified abil ...@@ -374,11 +380,11 @@ Obtains the caller interface of the specified ability, and if the specified abil
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: "com.example.myservice", bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility", abilityName: "MainAbility",
deviceId: "" deviceId: ""
}).then((obj) => { }).then((obj) => {
caller = obj; caller = obj;
console.log('Caller GetCaller Get ' + call); console.log('Caller GetCaller Get ' + caller);
}).catch((e) => { }).catch((e) => {
console.log('Caller GetCaller error ' + e); console.log('Caller GetCaller error ' + e);
}); });
...@@ -397,17 +403,19 @@ Requests permissions from the user by displaying a pop-up window. This API uses ...@@ -397,17 +403,19 @@ Requests permissions from the user by displaying a pop-up window. This API uses
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| Permissions to request.| | permissions | Array&lt;string&gt; | Yes| Permissions to request.|
| callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.| | callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.|
**Example** **Example**
``` ```js
this.context.requestPermissionsFromUser(permissions,(result) => { var permissions=['com.example.permission']
console.log('requestPermissionsFromUserresult:' + JSON.stringify(result)); this.context.requestPermissionsFromUser(permissions,(result) => {
console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
}); });
``` ```
...@@ -421,24 +429,26 @@ Requests permissions from the user by displaying a pop-up window. This API uses ...@@ -421,24 +429,26 @@ Requests permissions from the user by displaying a pop-up window. This API uses
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| Permissions to request.| | permissions | Array&lt;string&gt; | Yes| Permissions to request.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------- | -------- | | -------- | -------- |
| Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Example** **Example**
``` ```js
this.context.requestPermissionsFromUser(permissions).then((data) => { var permissions=['com.example.permission']
this.context.requestPermissionsFromUser(permissions).then((data) => {
console.log('success:' + JSON.stringify(data)); console.log('success:' + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringify(error)); console.log('failed:' + JSON.stringify(error));
}); });
``` ```
...@@ -452,13 +462,13 @@ Sets the label of the ability displayed in the task. This API uses a callback to ...@@ -452,13 +462,13 @@ Sets the label of the ability displayed in the task. This API uses a callback to
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| label | string | Yes| Label of the ability to set.| | label | string | Yes| Label of the ability to set.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.|
**Example**
**Example**
```js ```js
this.context.setMissionLabel("test",(result) => { this.context.setMissionLabel("test",(result) => {
console.log('requestPermissionsFromUserresult:' + JSON.stringify(result)); console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
...@@ -476,18 +486,18 @@ Sets the label of the ability displayed in the task. This API uses a promise to ...@@ -476,18 +486,18 @@ Sets the label of the ability displayed in the task. This API uses a promise to
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| label | string | Yes| Label of the ability to set.| | label | string | Yes| Label of the ability to set.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Example**
**Example**
```js ```js
this.context.setMissionLabel("test").then((data) => { this.context.setMissionLabel("test").then((data) => {
console.log('success:' + JSON.stringify(data)); console.log('success:' + JSON.stringify(data));
...@@ -495,3 +505,4 @@ Sets the label of the ability displayed in the task. This API uses a promise to ...@@ -495,3 +505,4 @@ Sets the label of the ability displayed in the task. This API uses a promise to
console.log('failed:' + JSON.stringify(error)); console.log('failed:' + JSON.stringify(error));
}); });
``` ```
# Ability Access Control # AbilityAccessCtrl
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 8. 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 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -20,9 +21,9 @@ Creates an **AtManager** instance, which is used for ability access control. ...@@ -20,9 +21,9 @@ Creates an **AtManager** instance, which is used for ability access control.
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------- | -------- | | -------- | -------- |
| [AtManager](#atmanager) | **AtManager** instance obtained. | | [AtManager](#atmanager) | **AtManager** instance obtained. |
**Example** **Example**
...@@ -44,16 +45,16 @@ Checks whether an application has been granted the specified permission. This AP ...@@ -44,16 +45,16 @@ Checks whether an application has been granted the specified permission. This AP
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------- | ---- | ------------------------------------------ | | -------- | ------------------- | ---- | ------------------------------------------ |
| tokenID | number | Yes | ID of the application. | | tokenID | number | Yes | ID of the application. |
| permissionName | string | Yes | Name of the permission to verify. | | permissionName | string | Yes | Name of the permission to verify. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| :------------ | :---------------------------------- | | :------------ | :---------------------------------- |
| Promise&lt;GrantStatus&gt; | Promise used to return the result. | | Promise&lt;GrantStatus&gt; | Promise used to return the result. |
**Example** **Example**
...@@ -78,24 +79,25 @@ Grants a user granted permission to an application. This API uses a promise to r ...@@ -78,24 +79,25 @@ Grants a user granted permission to an application. This API uses a promise to r
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ------------------- | ---- | ------------------------------------------------------------ | | --------- | ------------------- | ---- | ------------------------------------------------------------ |
| tokenID | number | Yes | ID of the application. | | tokenID | number | Yes | ID of the application. |
| permissionName | string | Yes | Name of the permission to grant. | | permissionName | string | Yes | Name of the permission to grant. |
| permissionFlag | number | Yes | Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. | | permissionFlag | number | Yes | Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| :------------ | :---------------------------------- | | :------------ | :---------------------------------- |
| Promise&lt;number&gt; | Promise used to return the result. | | Promise&lt;number&gt; | Promise used to return the result. |
**Example** **Example**
```js ```js
var AtManager = abilityAccessCtrl.createAtManager(); var AtManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; let tokenID = 0;
let promise = AtManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS"); let permissionFlag = 1;
let promise = AtManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",permissionFlag);
promise.then(data => { promise.then(data => {
console.log(`promise: data->${JSON.stringify(data)}`); console.log(`promise: data->${JSON.stringify(data)}`);
}); });
...@@ -115,12 +117,12 @@ Grants a user granted permission to an application. This API uses an asynchronou ...@@ -115,12 +117,12 @@ Grants a user granted permission to an application. This API uses an asynchronou
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ------------------- | ---- | ------------------------------------------------------------ | | --------- | ------------------- | ---- | ------------------------------------------------------------ |
| tokenID | number | Yes | ID of the application. | | tokenID | number | Yes | ID of the application. |
| permissionName | string | Yes | Name of the permission to grant. | | permissionName | string | Yes | Name of the permission to grant. |
| permissionFlag | number | Yes | Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. | | permissionFlag | number | Yes | Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -145,17 +147,17 @@ Revokes a user granted permission given to an application. This API uses a promi ...@@ -145,17 +147,17 @@ Revokes a user granted permission given to an application. This API uses a promi
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ------------------- | ---- | ------------------------------------------------------------ | | --------- | ------------------- | ---- | ------------------------------------------------------------ |
| tokenID | number | Yes | ID of the application. | | tokenID | number | Yes | ID of the application. |
| permissionName | string | Yes | Name of the permission to revoke. | | permissionName | string | Yes | Name of the permission to revoke. |
| permissionFlag | number | Yes | Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. | | permissionFlag | number | Yes | Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| :------------ | :---------------------------------- | | :------------ | :---------------------------------- |
| Promise&lt;number&gt; | Promise used to return the result. | | Promise&lt;number&gt; | Promise used to return the result. |
**Example** **Example**
...@@ -181,18 +183,19 @@ Revokes a user granted permission given to an application. This API uses an asyn ...@@ -181,18 +183,19 @@ Revokes a user granted permission given to an application. This API uses an asyn
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ------------------- | ---- | ------------------------------------------------------------ | | --------- | ------------------- | ---- | ------------------------------------------------------------ |
| tokenID | number | Yes | ID of the application. | | tokenID | number | Yes | ID of the application. |
| permissionName | string | Yes | Name of the permission to revoke. | | permissionName | string | Yes | Name of the permission to revoke. |
| permissionFlag | number | Yes | Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. | | permissionFlag | number | Yes | Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
var AtManager = abilityAccessCtrl.createAtManager(); var AtManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; let tokenID = 0;
let permissionFlag = 1;
AtManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",permissionFlag, data => { AtManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",permissionFlag, data => {
console.log(`callback: data->${JSON.stringify(data)}`); console.log(`callback: data->${JSON.stringify(data)}`);
}); });
...@@ -210,16 +213,16 @@ Obtains the flags of the specified permission of a given application. This API u ...@@ -210,16 +213,16 @@ Obtains the flags of the specified permission of a given application. This API u
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ------------------- | ---- | ------------------------------------------------------------ | | --------- | ------------------- | ---- | ------------------------------------------------------------ |
| tokenID | number | Yes | ID of the application. | | tokenID | number | Yes | ID of the application. |
| permissionName | string | Yes | Name of the permission to query. | | permissionName | string | Yes | Name of the permission to query. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| :------------ | :---------------------------------- | | :------------ | :---------------------------------- |
| Promise&lt;number&gt; | Promise used to return the result. | | Promise&lt;number&gt; | Promise used to return the result. |
**Example** **Example**
...@@ -238,7 +241,7 @@ Enumerates the permission grant states. ...@@ -238,7 +241,7 @@ Enumerates the permission grant states.
**System capability**: SystemCapability.Security.AccessToken **System capability**: SystemCapability.Security.AccessToken
| Name | Default Value | Description | | Name | Default Value | Description |
| ----------------------------- | ---------------------- | ----------------------- | | ----------------------------- | ---------------------- | ----------------------- |
| PERMISSION_DENIED | -1 | Permission denied. | | PERMISSION_DENIED | -1 | Permission denied. |
| PERMISSION_GRANTED | 0 | Permission granted. | | PERMISSION_GRANTED | 0 | Permission granted. |
# AbilityRunningInfo # AbilityRunningInfo
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 8. 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 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Provides ability running information. Provides ability running information.
## Modules to Import
## Usage
The ability running information is obtained by using the **getAbilityRunningInfos** API in **abilityManager**. ```js
import abilitymanager from '@ohos.application.abilityManager';
```
## Usage
The ability running information is obtained by using the **getAbilityRunningInfos** API in **abilityManager**.
```js ```js
import abilitymanager from '@ohos.application.abilityManager'; import abilitymanager from '@ohos.application.abilityManager';
...@@ -25,14 +28,14 @@ abilitymanager.getAbilityRunningInfos((err,data) => { ...@@ -25,14 +28,14 @@ abilitymanager.getAbilityRunningInfos((err,data) => {
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| ability | ElementName | Yes | No | Information that matches an ability. | | ability | ElementName | Yes | No | Information that matches an ability. |
| pid | number | Yes | No | Process ID. | | pid | number | Yes | No | Process ID. |
| uid | number | Yes | No | User ID. | | uid | number | Yes | No | User ID. |
| processName | string | Yes | No | Process name. | | processName | string | Yes | No | Process name. |
| startTime | number | Yes | No | Ability start time. | | startTime | number | Yes | No | Ability start time. |
| abilityState | [abilityManager.AbilityState](#abilitymanagerabilitystate) | Yes | No | Ability state. | | abilityState | [abilityManager.AbilityState](#abilitymanagerabilitystate) | Yes | No | Ability state. |
## abilityManager.AbilityState ## abilityManager.AbilityState
...@@ -41,10 +44,10 @@ Enumerates the ability states. ...@@ -41,10 +44,10 @@ Enumerates the ability states.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description | | Name | Value | Description |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| INITIAL | 0 | The ability is in the initial state. | | INITIAL | 0 | The ability is in the initial state. |
| FOREGROUND | 9 | The ability is in the foreground state. | | FOREGROUND | 9 | The ability is in the foreground state. |
| BACKGROUND | 10 | The ability is in the background state. | | BACKGROUND | 10 | The ability is in the background state. |
| FOREGROUNDING | 11 | The ability is in the foregrounding state. | | FOREGROUNDING | 11 | The ability is in the foregrounding state. |
| BACKGROUNDING | 12 | The ability is in the backgrounding state. | | BACKGROUNDING | 12 | The ability is in the backgrounding state. |
# AbilityStageContext # AbilityStageContext
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Implements the context of an ability stage. This module is inherited from [Context](js-apis-application-context.md). Implements the context of an ability stage. This module is inherited from [Context](js-apis-application-context.md).
## Modules to Import
```js
import AbilityStage from '@ohos.application.AbilityStage';
```
## Usage ## Usage
...@@ -13,7 +19,7 @@ Implements the context of an ability stage. This module is inherited from [Conte ...@@ -13,7 +19,7 @@ Implements the context of an ability stage. This module is inherited from [Conte
The ability stage context is obtained through an **AbilityStage** instance. The ability stage context is obtained through an **AbilityStage** instance.
```js ```js
import AbilityStage from '@ohos.application.AbilityStage'; import AbilityStage from '@ohos.application.AbilityStage';
class MyAbilityStage extends AbilityStage { class MyAbilityStage extends AbilityStage {
...@@ -28,7 +34,7 @@ class MyAbilityStage extends AbilityStage { ...@@ -28,7 +34,7 @@ class MyAbilityStage extends AbilityStage {
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type | Readable | Writable | Description | | Name| Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| currentHapModuleInfo | HapModuleInfo | Yes | No | **ModuleInfo** object corresponding to the **AbilityStage**. | | currentHapModuleInfo | HapModuleInfo | Yes | No | **ModuleInfo** object corresponding to the **AbilityStage**. |
| config | [Configuration](js-apis-configuration.md) | Yes| No| Configuration for the environment where the application is running. | | config | [Configuration](js-apis-configuration.md) | Yes| No| Configuration for the environment where the application is running. |
# MissionSnapshot # MissionSnapshot
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 8. 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 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -12,8 +13,9 @@ Provides the snapshot of a mission. ...@@ -12,8 +13,9 @@ Provides the snapshot of a mission.
``` ```
import { ElementName } from '../bundle/elementName'; import missionManager from '@ohos.application.missionManager'
import { image } from '../@ohos.multimedia.image'; import ElementName from '@ohos.bundle';
import image from '@ohos.multimedia.image';
``` ```
......
# Ability # Ability
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs of this module can be used only in the stage model.
Manages the ability lifecycle and context. Manages the ability lifecycle and context.
...@@ -9,7 +12,7 @@ Manages the ability lifecycle and context. ...@@ -9,7 +12,7 @@ Manages the ability lifecycle and context.
## Modules to Import ## Modules to Import
``` ```
import Ability from '@ohos.application.Ability'; import Ability from '@ohos.application.Ability';
``` ```
...@@ -18,11 +21,12 @@ import Ability from '@ohos.application.Ability'; ...@@ -18,11 +21,12 @@ import Ability from '@ohos.application.Ability';
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| context | [AbilityContext](js-apis-ability-context.md) | Yes | No | Context of an ability. | | context | [AbilityContext](js-apis-ability-context.md) | Yes | No | Context of an ability. |
| launchWant | [Want](js-apis-application-Want.md) | Yes | No | Parameters for starting the ability. | | launchWant | [Want](js-apis-application-Want.md) | Yes | No | Parameters for starting the ability. |
| lastRequestWant | [Want](js-apis-application-Want.md) | Yes | No | Parameters used when the ability was started last time. | | lastRequestWant | [Want](js-apis-application-Want.md) | Yes | No | Parameters used when the ability was started last time. |
| callee | [Callee](#callee) | Yes | No | Object that invokes the stub service. |
## Ability.onCreate ## Ability.onCreate
...@@ -35,10 +39,10 @@ Called to initialize the service logic when an ability is created. ...@@ -35,10 +39,10 @@ Called to initialize the service logic when an ability is created.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes | Information related to this ability, including the ability name and bundle name. | | want | [Want](js-apis-application-Want.md) | Yes | Information related to this ability, including the ability name and bundle name. |
| param | AbilityConstant.LaunchParam | Yes | Parameters for starting the ability, and the reason for the last abnormal exit. | | param | AbilityConstant.LaunchParam | Yes | Parameters for starting the ability, and the reason for the last abnormal exit. |
**Example** **Example**
...@@ -61,9 +65,9 @@ Called when a **WindowStage** is created for this ability. ...@@ -61,9 +65,9 @@ Called when a **WindowStage** is created for this ability.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| windowStage | window.WindowStage | Yes | **WindowStage** information. | | windowStage | window.WindowStage | Yes | **WindowStage** information. |
**Example** **Example**
...@@ -105,9 +109,9 @@ Called when the **WindowStage** is restored during the migration of this ability ...@@ -105,9 +109,9 @@ Called when the **WindowStage** is restored during the migration of this ability
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| windowStage | window.WindowStage | Yes | **WindowStage** information. | | windowStage | window.WindowStage | Yes | **WindowStage** information. |
**Example** **Example**
...@@ -187,24 +191,25 @@ Called to save data during the ability migration preparation process. ...@@ -187,24 +191,25 @@ Called to save data during the ability migration preparation process.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| wantParam | {[key:&nbsp;string]:&nbsp;any} | Yes | **want** parameter. | | wantParam | {[key:&nbsp;string]:&nbsp;any} | Yes | **want** parameter. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------- | -------- | | -------- | -------- |
| AbilityConstant.OnContinueResult | Continuation result. | | AbilityConstant.OnContinueResult | Continuation result. |
**Example** **Example**
```js ```js
import AbilityConstant from "@ohos.application.AbilityConstant"
class myAbility extends Ability { class myAbility extends Ability {
onContinue(wantParams) { onContinue(wantParams) {
console.log('onContinue'); console.log('onContinue');
wantParams["myData"] = "my1234567"; wantParams["myData"] = "my1234567";
return true; return AbilityConstant.OnContinueResult.AGREE;
} }
} }
``` ```
...@@ -220,9 +225,9 @@ Called when the ability startup mode is set to singleton. ...@@ -220,9 +225,9 @@ Called when the ability startup mode is set to singleton.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes | Want parameters, such as the ability name and bundle name. | | want | [Want](js-apis-application-Want.md) | Yes | Want parameters, such as the ability name and bundle name. |
**Example** **Example**
...@@ -245,12 +250,12 @@ Called when the configuration of the environment where the ability is running is ...@@ -245,12 +250,12 @@ Called when the configuration of the environment where the ability is running is
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [Configuration](js-apis-configuration.md) | Yes | New configuration. | | config | [Configuration](js-apis-configuration.md) | Yes | New configuration. |
**Example**
**Example**
```js ```js
class myAbility extends Ability { class myAbility extends Ability {
onConfigurationUpdated(config) { onConfigurationUpdated(config) {
...@@ -259,6 +264,32 @@ Called when the configuration of the environment where the ability is running is ...@@ -259,6 +264,32 @@ Called when the configuration of the environment where the ability is running is
} }
``` ```
## Ability.dump
dump(params: Array\<string>): Array\<string>;
Called when the client information is dumped.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| params | Array\<string> | Yes | Parameters in the form of a command. |
**Example**
```js
class myAbility extends Ability {
dump(params) {
console.log('dump, params:' + JSON.stringify(params));
return ["params"]
}
}
```
## Caller ## Caller
...@@ -275,22 +306,25 @@ Sends sequenceable data to the target ability. ...@@ -275,22 +306,25 @@ Sends sequenceable data to the target ability.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| method | string | Yes | Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data. | | method | string | Yes | Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data. |
| data | rpc.Sequenceable | Yes | Sequenceable data. You need to customize the data. | | data | rpc.Sequenceable | Yes | Sequenceable data. You need to customize the data. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return a response. | | Promise&lt;void&gt; | Promise used to return a response. |
**Example** **Example**
```js ```js
import Ability from '@ohos.application.Ability'; import Ability from '@ohos.application.Ability';
class MyMessageAble{ // Custom sequenceable data structure class MyMessageAble{ // Custom sequenceable data structure
name:""
str:""
num: 1
constructor(name, str) { constructor(name, str) {
this.name = name; this.name = name;
this.str = str; this.str = str;
...@@ -314,7 +348,7 @@ Sends sequenceable data to the target ability. ...@@ -314,7 +348,7 @@ Sends sequenceable data to the target ability.
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: "com.example.myservice", bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility", abilityName: "MainAbility",
deviceId: "" deviceId: ""
}).then((obj) => { }).then((obj) => {
caller = obj; caller = obj;
...@@ -345,22 +379,25 @@ Sends sequenceable data to the target ability and obtains the sequenceable data ...@@ -345,22 +379,25 @@ Sends sequenceable data to the target ability and obtains the sequenceable data
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| method | string | Yes | Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data. | | method | string | Yes | Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data. |
| data | rpc.Sequenceable | Yes | Sequenceable data. You need to customize the data. | | data | rpc.Sequenceable | Yes | Sequenceable data. You need to customize the data. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------- | -------- | | -------- | -------- |
| Promise&lt;rpc.MessageParcel&gt; | Promise used to return the sequenceable data from the target ability. | | Promise&lt;rpc.MessageParcel&gt; | Promise used to return the sequenceable data from the target ability. |
**Example** **Example**
```js ```js
import Ability from '@ohos.application.Ability'; import Ability from '@ohos.application.Ability';
class MyMessageAble{ class MyMessageAble{
name:""
str:""
num: 1
constructor(name, str) { constructor(name, str) {
this.name = name; this.name = name;
this.str = str; this.str = str;
...@@ -384,7 +421,7 @@ Sends sequenceable data to the target ability and obtains the sequenceable data ...@@ -384,7 +421,7 @@ Sends sequenceable data to the target ability and obtains the sequenceable data
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: "com.example.myservice", bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility", abilityName: "MainAbility",
deviceId: "" deviceId: ""
}).then((obj) => { }).then((obj) => {
caller = obj; caller = obj;
...@@ -423,7 +460,7 @@ Releases the caller interface of the target ability. ...@@ -423,7 +460,7 @@ Releases the caller interface of the target ability.
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: "com.example.myservice", bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility", abilityName: "MainAbility",
deviceId: "" deviceId: ""
}).then((obj) => { }).then((obj) => {
caller = obj; caller = obj;
...@@ -451,9 +488,9 @@ Registers a callback that is invoked when the Stub on the target ability is disc ...@@ -451,9 +488,9 @@ Registers a callback that is invoked when the Stub on the target ability is disc
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | OnReleaseCallBack | Yes | Callback used for the **onRelease** API. | | callback | OnReleaseCallBack | Yes | Callback used for the **onRelease** API. |
**Example** **Example**
...@@ -464,7 +501,7 @@ Registers a callback that is invoked when the Stub on the target ability is disc ...@@ -464,7 +501,7 @@ Registers a callback that is invoked when the Stub on the target ability is disc
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: "com.example.myservice", bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility", abilityName: "MainAbility",
deviceId: "" deviceId: ""
}).then((obj) => { }).then((obj) => {
caller = obj; caller = obj;
...@@ -499,16 +536,19 @@ Registers a caller notification callback, which is invoked when the target abili ...@@ -499,16 +536,19 @@ Registers a caller notification callback, which is invoked when the target abili
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| method | string | Yes | Notification message string negotiated between the two abilities. | | method | string | Yes | Notification message string negotiated between the two abilities. |
| callback | CaleeCallBack | Yes | JS notification synchronization callback of the **rpc.MessageParcel** type. The callback must return at least one empty **rpc.Sequenceable** object. Otherwise, the function execution fails. | | callback | CaleeCallBack | Yes | JS notification synchronization callback of the **rpc.MessageParcel** type. The callback must return at least one empty **rpc.Sequenceable** object. Otherwise, the function execution fails. |
**Example** **Example**
```js ```js
import Ability from '@ohos.application.Ability'; import Ability from '@ohos.application.Ability';
class MyMessageAble{ class MyMessageAble{
name:""
str:""
num: 1
constructor(name, str) { constructor(name, str) {
this.name = name; this.name = name;
this.str = str; this.str = str;
...@@ -552,9 +592,9 @@ Unregisters a caller notification callback, which is invoked when the target abi ...@@ -552,9 +592,9 @@ Unregisters a caller notification callback, which is invoked when the target abi
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| method | string | Yes | Registered notification message string. | | method | string | Yes | Registered notification message string. |
**Example** **Example**
...@@ -575,10 +615,10 @@ Unregisters a caller notification callback, which is invoked when the target abi ...@@ -575,10 +615,10 @@ Unregisters a caller notification callback, which is invoked when the target abi
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| (msg: string) | function | Yes | No | Prototype of the listener function interface registered by the caller. | | (msg: string) | function | Yes | No | Prototype of the listener function interface registered by the caller. |
## CaleeCallBack ## CaleeCallBack
...@@ -586,6 +626,6 @@ Unregisters a caller notification callback, which is invoked when the target abi ...@@ -586,6 +626,6 @@ Unregisters a caller notification callback, which is invoked when the target abi
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| (indata: rpc.MessageParcel) | rpc.Sequenceable | Yes | No | Prototype of the message listener function interface registered by the callee. | | (indata: rpc.MessageParcel) | rpc.Sequenceable | Yes | No | Prototype of the message listener function interface registered by the callee. |
# AbilityDelegator # AbilityDelegator
> **NOTE**<br/> > **NOTE**
> >
> The initial APIs of this module are supported since API version 8. 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 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -747,7 +747,7 @@ abilityDelegator.executeShellCommand(cmd, timeout, (err : any, data : any) => { ...@@ -747,7 +747,7 @@ abilityDelegator.executeShellCommand(cmd, timeout, (err : any, data : any) => {
### executeShellCommand ### executeShellCommand
executeShellCommand(cmd: string, timeoutSecs: number): Promise\<ShellCmdResult> executeShellCommand(cmd: string, timeoutSecs?: number): Promise\<ShellCmdResult>
Executes a shell command with the timeout period specified. This API uses a promise to return the result. Executes a shell command with the timeout period specified. This API uses a promise to return the result.
......
# Context # Context
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Provides the context for running code, including **applicationInfo** and **resourceManager**. Provides the context for running code, including **applicationInfo** and **resourceManager**.
## Modules to Import
```
import AbilityContext from '@ohos.application.Ability';
```
## Usage ## Usage
...@@ -17,18 +23,19 @@ You must extend **AbilityContext** to implement this module. ...@@ -17,18 +23,19 @@ You must extend **AbilityContext** to implement this module.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| resourceManager | ResourceManager | Yes | No | **ResourceManager** object. | | resourceManager | ResourceManager | Yes | No | **ResourceManager** object. |
| applicationInfo | ApplicationInfo | Yes | No | Information about the application. | | applicationInfo | ApplicationInfo | Yes | No | Information about the application. |
| cacheDir | string | Yes | No | Cache directory of the application on the internal storage. | | cacheDir | string | Yes | No | Cache directory of the application on the internal storage. |
| tempDir | string | Yes | No | Temporary file directory of the application. | | tempDir | string | Yes | No | Temporary file directory of the application. |
| filesDir | string | Yes | No | File directory of the application on the internal storage. | | filesDir | string | Yes | No | File directory of the application on the internal storage. |
| databaseDir | string | Yes | No | Storage directory of local data. | | databaseDir | string | Yes | No | Storage directory of local data. |
| storageDir | string | Yes | No | Storage directory of lightweight data. | | storageDir | string | Yes | No | Storage directory of lightweight data. |
| bundleCodeDir | string | Yes | No | Application installation path. | | bundleCodeDir | string | Yes | No | Application installation path. |
| distributedFilesDir | string | Yes | No | Storage directory of distributed application data files. | | distributedFilesDir | string | Yes | No | Storage directory of distributed application data files. |
| eventHub | [EventHub](js-apis-eventhub.md) | Yes | No | Event hub information. | | eventHub | [EventHub](js-apis-eventhub.md) | Yes | No | Event hub information. |
| area | [AreaMode](#areamode) | Yes | Yes | Area in which the file to be access is located. |
## Context.createBundleContext ## Context.createBundleContext
...@@ -41,27 +48,33 @@ Creates an application context. ...@@ -41,27 +48,33 @@ Creates an application context.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| bundleName | string | Yes | Application bundle name. | | bundleName | string | Yes | Application bundle name. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------- | -------- | | -------- | -------- |
| Context | Context of the application created. | | Context | Context of the application created. |
**Example** **Example**
```js ```js
let test = "com.example.test"; import AbilityContext from '@ohos.application.Ability'
let context = this.context.createBundleContext(test); class MainAbility extends AbilityContext {
onWindowStageCreate(windowStage) {
let test = "com.example.test";
let context = this.context.createBundleContext(test);
}
}
``` ```
## Context.getApplicationContext ## Context.getApplicationContext
getApplicationContext(): Context; getApplicationContext(): ApplicationContext;
Obtains the context of this application. Obtains the context of this application.
...@@ -69,13 +82,25 @@ Obtains the context of this application. ...@@ -69,13 +82,25 @@ Obtains the context of this application.
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------- | -------- | | -------- | -------- |
| Context | Context obtained. | | ApplicationContext | Application context obtained. |
**Example** **Example**
```js ```js
// This part is mandatory. // This part is mandatory.
let context = this.context.getApplicationContext(); let applicationContext = this.context.getApplicationContext();
``` ```
## AreaMode
Defines the area where the file to be access is located. Each area has its own content.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| --------------- | ---- | --------------- |
| EL1 | 0 | Device-level encryption area. |
| EL2 | 1 | User credential encryption area. The default value is **EL2**. |
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
``` ```
## ShellCmdResult ## ShellCmdResult
Describes the shell command execution result. Describes the shell command execution result.
......
# appManager # appManager
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 7. 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 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -25,16 +26,16 @@ Checks whether this application is undergoing a stability test. This API uses an ...@@ -25,16 +26,16 @@ Checks whether this application is undergoing a stability test. This API uses an
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| | callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
**Example** **Example**
```js ```js
import app from '@ohos.application.appManager'; import app from '@ohos.application.appManager';
app.isRunningInStabilityTest((err, flag) => { app.isRunningInStabilityTest((err, flag) => {
console.log('startAbility result:' + JSON.stringfy(err)); console.log('startAbility result:' + JSON.stringify(err));
}) })
``` ```
...@@ -49,18 +50,18 @@ Checks whether this application is undergoing a stability test. This API uses a ...@@ -49,18 +50,18 @@ Checks whether this application is undergoing a stability test. This API uses a
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| | Promise&lt;boolean&gt; | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
**Example** **Example**
```js ```js
import app from '@ohos.application.appManager'; import app from '@ohos.application.appManager';
app.isRunningInStabilityTest().then((flag) => { app.isRunningInStabilityTest().then((flag) => {
console.log('success:' + JSON.stringfy(flag)); console.log('success:' + JSON.stringify(flag));
}).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringfy(error)); console.log('failed:' + JSON.stringify(error));
}); });
``` ```
...@@ -75,14 +76,14 @@ Checks whether this application is running on a RAM constrained device. This API ...@@ -75,14 +76,14 @@ Checks whether this application is running on a RAM constrained device. This API
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| | Promise&lt;boolean&gt; | Promise used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
**Example** **Example**
```js ```js
app.isRamConstrainedDevicePromise().then((data) => { app.isRamConstrainedDevice().then((data) => {
console.log('success:' + JSON.stringify(data)); console.log('success:' + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringify(error)); console.log('failed:' + JSON.stringify(error));
...@@ -99,14 +100,14 @@ Checks whether this application is running on a RAM constrained device. This API ...@@ -99,14 +100,14 @@ Checks whether this application is running on a RAM constrained device. This API
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| | callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
**Example** **Example**
```js ```js
app.isRamConstrainedDevicePromise((err, data) => { app.isRamConstrainedDevice((err, data) => {
console.log('startAbility result failed:' + JSON.stringify(err)); console.log('startAbility result failed:' + JSON.stringify(err));
console.log('startAbility result success:' + JSON.stringify(data)); console.log('startAbility result success:' + JSON.stringify(data));
}) })
...@@ -122,9 +123,9 @@ Obtains the memory size of this application. This API uses a promise to return t ...@@ -122,9 +123,9 @@ Obtains the memory size of this application. This API uses a promise to return t
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt; | Size of the application memory.| | Promise&lt;number&gt; | Size of the application memory.|
**Example** **Example**
...@@ -146,9 +147,9 @@ Obtains the memory size of this application. This API uses an asynchronous callb ...@@ -146,9 +147,9 @@ Obtains the memory size of this application. This API uses an asynchronous callb
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | No| Size of the application memory.| | callback | AsyncCallback&lt;number&gt; | No| Size of the application memory.|
**Example** **Example**
...@@ -160,7 +161,7 @@ Obtains the memory size of this application. This API uses an asynchronous callb ...@@ -160,7 +161,7 @@ Obtains the memory size of this application. This API uses an asynchronous callb
``` ```
## appManager.getProcessRunningInfos<sup>8+</sup> ## appManager.getProcessRunningInfos<sup>8+</sup>
getProcessRunningInfos(): Promise<Array<ProcessRunningInfo>>; getProcessRunningInfos(): Promise<Array\<ProcessRunningInfo>>;
Obtains information about the running processes. This API uses a promise to return the result. Obtains information about the running processes. This API uses a promise to return the result.
...@@ -168,14 +169,14 @@ Obtains information about the running processes. This API uses a promise to retu ...@@ -168,14 +169,14 @@ Obtains information about the running processes. This API uses a promise to retu
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise<Array\<ProcessRunningInfo>> | Promise used to return the process information.| | Promise<Array\<ProcessRunningInfo>> | Promise used to return the process information.|
**Example** **Example**
```js ```js
app.GetProcessRunningInfos().then((data) => { app.getProcessRunningInfos().then((data) => {
console.log('success:' + JSON.stringify(data)); console.log('success:' + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringify(error)); console.log('failed:' + JSON.stringify(error));
...@@ -184,7 +185,7 @@ Obtains information about the running processes. This API uses a promise to retu ...@@ -184,7 +185,7 @@ Obtains information about the running processes. This API uses a promise to retu
## appManager.getProcessRunningInfos<sup>8+</sup> ## appManager.getProcessRunningInfos<sup>8+</sup>
getProcessRunningInfos(callback: AsyncCallback<Array<ProcessRunningInfo>>): void; getProcessRunningInfos(callback: AsyncCallback<Array\<ProcessRunningInfo>>): void;
Obtains information about the running processes. This API uses an asynchronous callback to return the result. Obtains information about the running processes. This API uses an asynchronous callback to return the result.
...@@ -192,14 +193,14 @@ Obtains information about the running processes. This API uses an asynchronous c ...@@ -192,14 +193,14 @@ Obtains information about the running processes. This API uses an asynchronous c
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback<Array\<ProcessRunningInfo>> | No| Callback used to return the process information.| | callback | AsyncCallback<Array\<ProcessRunningInfo>> | No| Callback used to return the process information.|
**Example** **Example**
```js ```js
app.GetProcessRunningInfos((err, data) => { app.getProcessRunningInfos((err, data) => {
console.log('startAbility result failed :' + JSON.stringify(err)); console.log('startAbility result failed :' + JSON.stringify(err));
console.log('startAbility result success:' + JSON.stringify(data)); console.log('startAbility result success:' + JSON.stringify(data));
}) })
......
# DataAbilityHelper Module (JavaScript SDK APIs) # DataAbilityHelper
> ![icon-note.gif](public_sys-resources/icon-note.gif)**NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 7. 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 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs of this module can be used only in the stage model.
## Modules to Import ## Modules to Import
``` ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
import ohos_data_ability from '@ohos.data.dataability' import ohos_data_ability from '@ohos.data.dataAbility'
import ohos_data_rdb from '@ohos.data.rdb' import ohos_data_rdb from '@ohos.data.rdb'
``` ```
## DataAbilityHelper.openFile ## DataAbilityHelper.openFile
openFile(uri: string, mode: string, callback: AsyncCallback\<number>): void openFile(uri: string, mode: string, callback: AsyncCallback\<number>): void
...@@ -21,11 +23,11 @@ Opens a file with a specified URI. This API uses an asynchronous callback to ret ...@@ -21,11 +23,11 @@ Opens a file with a specified URI. This API uses an asynchronous callback to ret
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | ---------------------------------- | | -------- | ---------------------- | --------- | ---------------------------------------------------- |
| uri | string | Yes | URI of the file to open. | | uri | string | Yes | URI of the file to open. |
| mode | string | Yes | Mode for opening the file. The value can be **rwt**. | | mode | string | Yes | Mode for opening the file. The value can be **rwt**. |
| callback | AsyncCallback\<number> | Yes | Callback used to return the file descriptor.| | callback | AsyncCallback\<number> | Yes | Callback used to return the file descriptor. |
**Example** **Example**
...@@ -499,7 +501,7 @@ const valueBucket = { ...@@ -499,7 +501,7 @@ const valueBucket = {
"name": "rose", "name": "rose",
"age": 22, "age": 22,
"salary": 200.5, "salary": 200.5,
"blobType": u8, "blobType": "u8",
} }
DAHelper.insert( DAHelper.insert(
"dataability:///com.example.DataAbility", "dataability:///com.example.DataAbility",
...@@ -541,7 +543,7 @@ const valueBucket = { ...@@ -541,7 +543,7 @@ const valueBucket = {
"name": "rose1", "name": "rose1",
"age": 221, "age": 221,
"salary": 20.5, "salary": 20.5,
"blobType": u8, "blobType": "u8",
} }
DAHelper.insert( DAHelper.insert(
"dataability:///com.example.DataAbility", "dataability:///com.example.DataAbility",
...@@ -574,9 +576,9 @@ import featureAbility from '@ohos.ability.featureAbility' ...@@ -574,9 +576,9 @@ import featureAbility from '@ohos.ability.featureAbility'
var DAHelper = featureAbility.acquireDataAbilityHelper( var DAHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility" "dataability:///com.example.DataAbility"
); );
var cars = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": u8,}, var cars = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": "u8",},
{"name": "roe12", "age": 21, "salary": 20.5, "blobType": u8,}, {"name": "roe12", "age": 21, "salary": 20.5, "blobType": "u8",},
{"name": "roe13", "age": 21, "salary": 20.5, "blobType": u8,}) {"name": "roe13", "age": 21, "salary": 20.5, "blobType": "u8",})
DAHelper.batchInsert( DAHelper.batchInsert(
"dataability:///com.example.DataAbility", "dataability:///com.example.DataAbility",
cars, cars,
...@@ -613,9 +615,9 @@ import featureAbility from '@ohos.ability.featureAbility' ...@@ -613,9 +615,9 @@ import featureAbility from '@ohos.ability.featureAbility'
var DAHelper = featureAbility.acquireDataAbilityHelper( var DAHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility" "dataability:///com.example.DataAbility"
); );
var cars = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": u8,}, var cars = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": "u8",},
{"name": "roe12", "age": 21, "salary": 20.5, "blobType": u8,}, {"name": "roe12", "age": 21, "salary": 20.5, "blobType": "u8",},
{"name": "roe13", "age": 21, "salary": 20.5, "blobType": u8,}) {"name": "roe13", "age": 21, "salary": 20.5, "blobType": "u8",})
DAHelper.batchInsert( DAHelper.batchInsert(
"dataability:///com.example.DataAbility", "dataability:///com.example.DataAbility",
cars cars
...@@ -682,6 +684,7 @@ Deletes one or more data records from the database. This API uses a promise to r ...@@ -682,6 +684,7 @@ Deletes one or more data records from the database. This API uses a promise to r
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
import ohos_data_ability from '@ohos.data.dataability'
var DAHelper = featureAbility.acquireDataAbilityHelper( var DAHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility" "dataability:///com.example.DataAbility"
); );
...@@ -723,7 +726,7 @@ const va = { ...@@ -723,7 +726,7 @@ const va = {
"name": "roe1", "name": "roe1",
"age": 21, "age": 21,
"salary": 20.5, "salary": 20.5,
"blobType": u8, "blobType": "u8",
} }
let da = new ohos_data_ability.DataAbilityPredicates() let da = new ohos_data_ability.DataAbilityPredicates()
DAHelper.update( DAHelper.update(
...@@ -769,7 +772,7 @@ const va = { ...@@ -769,7 +772,7 @@ const va = {
"name": "roe1", "name": "roe1",
"age": 21, "age": 21,
"salary": 20.5, "salary": 20.5,
"blobType": u8, "blobType": "u8",
} }
let da = new ohos_data_ability.DataAbilityPredicates() let da = new ohos_data_ability.DataAbilityPredicates()
DAHelper.update( DAHelper.update(
......
# EventHub # EventHub
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs of this module can be used only in the stage model.
Implements event subscription, unsubscription, and triggering. Implements event subscription, unsubscription, and triggering.
## Modules to Import
```js
import Ability from '@ohos.application.Ability'
```
## Usage ## Usage
Before using any APIs in the **EventHub**, you must obtain an **EventHub** instance through the member variable **context** of the **Ability** instance. Before using any APIs in the **EventHub**, you must obtain an **EventHub** instance through the member variable **context** of the **Ability** instance.
```js ```js
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
func1(){
console.log("func1 is called");
}
onForeground() { onForeground() {
this.context.eventHub.on("123", this.func1); this.context.eventHub.on("123", this.func1);
} }
...@@ -34,10 +43,10 @@ Subscribes to an event. ...@@ -34,10 +43,10 @@ Subscribes to an event.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| event | string | Yes | Event name. | | event | string | Yes | Event name. |
| callback | Function | Yes | Callback invoked when the event is triggered. | | callback | Function | Yes | Callback invoked when the event is triggered. |
**Example** **Example**
...@@ -72,10 +81,10 @@ Unsubscribes from an event. If **callback** is specified, this API unsubscribes ...@@ -72,10 +81,10 @@ Unsubscribes from an event. If **callback** is specified, this API unsubscribes
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| event | string | Yes | Event name. | | event | string | Yes | Event name. |
| callback | Function | No | Callback for the event. If **callback** is unspecified, all callbacks of the event are unsubscribed. | | callback | Function | No | Callback for the event. If **callback** is unspecified, all callbacks of the event are unsubscribed. |
**Example** **Example**
...@@ -110,10 +119,10 @@ Triggers an event. ...@@ -110,10 +119,10 @@ Triggers an event.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| event | string | Yes | Event name. | | event | string | Yes | Event name. |
| ...args | Object[] | Yes | Variable parameters, which are passed to the callback when the event is triggered. | | ...args | Object[] | Yes | Variable parameters, which are passed to the callback when the event is triggered. |
**Example** **Example**
......
# ExtensionContext # ExtensionContext
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**
>
> The initial APIs of this module are supported since API version 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs of this module can be used only in the stage model.
Implements the extension context. This module is inherited from **Context**. Implements the extension context. This module is inherited from **Context**.
## Modules to Import
```js
import DataShareExtensionAbility from '@ohos.application.DataShareExtensionAbility';
```
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| currentHapModuleInfo | HapModuleInfo | Yes| No | Information about the current HAP. | | currentHapModuleInfo | HapModuleInfo | Yes| No | Information about the current HAP. |
| config | Configuration | Yes| No | Module configuration information. | | config | Configuration | Yes| No | Module configuration information. |
# ExtensionRunningInfo # ExtensionRunningInfo
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**
>
> The initial APIs of this module are supported since API version 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Provides extension running information. Provides extension running information.
## Modules to Import
```js
import abilitymanager from '@ohos.application.abilityManager';
```
## Usage ## Usage
The extension running information is obtained through an **abilityManager** instance. The extension running information is obtained through an **abilityManager** instance.
```js
```
import abilitymanager from '@ohos.application.abilityManager'; import abilitymanager from '@ohos.application.abilityManager';
let upperLimit=1
abilitymanager.getExtensionRunningInfos(upperLimit, (err,data) => { abilitymanager.getExtensionRunningInfos(upperLimit, (err,data) => {
console.log("getExtensionRunningInfos err: " + err + " data: " + JSON.stringify(data)); console.log("getExtensionRunningInfos err: " + err + " data: " + JSON.stringify(data));
}); });
...@@ -43,15 +48,15 @@ Enumerates extension types. ...@@ -43,15 +48,15 @@ Enumerates extension types.
**System capability**: SystemCapability.BundleManager.BundleFramework **System capability**: SystemCapability.BundleManager.BundleFramework
| Name| Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| FORM | 0 | Extension information of the form type.< | | FORM | 0 | Extension information of the form type.< |
| WORK_SCHEDULER | 1 | Extension information of the work scheduler type.< | | WORK_SCHEDULER | 1 | Extension information of the work scheduler type.< |
| INPUT_METHOD | 2 | Extension information of the input method type.< | | INPUT_METHOD | 2 | Extension information of the input method type.< |
| SERVICE | 3 | Extension information of the service type.< | | SERVICE | 3 | Extension information of the service type.< |
| ACCESSIBILITY | 4 | Extension information of the accessibility type.< | | ACCESSIBILITY | 4 | Extension information of the accessibility type.< |
| DATA_SHARE | 5 | Extension information of the data share type.< | | DATA_SHARE | 5 | Extension information of the data share type.< |
| FILE_SHARE | 6 | Extension information of the file share type.< | | FILE_SHARE | 6 | Extension information of the file share type.< |
| STATIC_SUBSCRIBER | 7 | Extension information of the static subscriber type.< | | STATIC_SUBSCRIBER | 7 | Extension information of the static subscriber type.< |
| WALLPAPER | 8 | Extension information of the wallpaper type.< | | WALLPAPER | 8 | Extension information of the wallpaper type.< |
| UNSPECIFIED | 9 | Extension information of the unspecified type.< | | UNSPECIFIED | 9 | Extension information of the unspecified type.< |
# FeatureAbility Module (JavaScript) # FeatureAbility
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **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.
>
> The APIs of this module can be used only in the FA model.
## Constraints ## Usage
APIs of the **FeatureAbility** module can be called only by Page abilities. APIs of the **FeatureAbility** module can be called only by Page abilities.
...@@ -139,7 +142,7 @@ Starts an ability. This API uses a callback to return the execution result when ...@@ -139,7 +142,7 @@ Starts an ability. This API uses a callback to return the execution result when
**Example** **Example**
```javascript ```javascript
import featureAbility from '@ohos.ability.featureability'; import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant' import wantConstant from '@ohos.ability.wantConstant'
featureAbility.startAbilityForResult( featureAbility.startAbilityForResult(
{ {
...@@ -157,7 +160,7 @@ featureAbility.startAbilityForResult( ...@@ -157,7 +160,7 @@ featureAbility.startAbilityForResult(
}, },
}, },
(err, data) => { (err, data) => {
console.info("err: " + JSON.stringfy(err) + "data: " + JSON.stringfy(data)) console.info("err: " + JSON.stringify(err) + "data: " + JSON.stringify(data))
} }
) )
``` ```
...@@ -185,7 +188,7 @@ Starts an ability. This API uses a promise to return the execution result when t ...@@ -185,7 +188,7 @@ Starts an ability. This API uses a promise to return the execution result when t
**Example** **Example**
```javascript ```javascript
import featureAbility from '@ohos.ability.featureability'; import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant' import wantConstant from '@ohos.ability.wantConstant'
featureAbility.startAbilityForResult( featureAbility.startAbilityForResult(
{ {
...@@ -291,7 +294,7 @@ Destroys this Page ability, with the result code and data sent to the caller. Th ...@@ -291,7 +294,7 @@ Destroys this Page ability, with the result code and data sent to the caller. Th
**Example** **Example**
```javascript ```javascript
import featureAbility from '@ohos.ability.featureability'; import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant' import wantConstant from '@ohos.ability.wantConstant'
featureAbility.terminateSelfWithResult( featureAbility.terminateSelfWithResult(
{ {
...@@ -343,7 +346,7 @@ Checks whether the main window of this ability has the focus. This API uses a ca ...@@ -343,7 +346,7 @@ Checks whether the main window of this ability has the focus. This API uses a ca
**Example** **Example**
```javascript ```javascript
import featureAbility from '@ohos.ability.featureability'; import featureAbility from '@ohos.ability.featureAbility';
featureAbility.hasWindowFocus() featureAbility.hasWindowFocus()
``` ```
...@@ -391,7 +394,7 @@ Obtains the **Want** object sent from this ability. This API uses a callback to ...@@ -391,7 +394,7 @@ Obtains the **Want** object sent from this ability. This API uses a callback to
**Example** **Example**
```javascript ```javascript
import featureAbility from '@ohos.ability.featureability'; import featureAbility from '@ohos.ability.featureAbility';
featureAbility.getWant() featureAbility.getWant()
``` ```
...@@ -414,7 +417,7 @@ Obtains the **Want** object sent from this ability. This API uses a promise to r ...@@ -414,7 +417,7 @@ Obtains the **Want** object sent from this ability. This API uses a promise to r
**Example** **Example**
```javascript ```javascript
import featureAbility from '@ohos.ability.featureability'; import featureAbility from '@ohos.ability.featureAbility';
featureAbility.getWant().then((data) => { featureAbility.getWant().then((data) => {
console.info("==========================>getWantCallBack=======================>"); console.info("==========================>getWantCallBack=======================>");
}); });
...@@ -437,7 +440,7 @@ Obtains the application context. ...@@ -437,7 +440,7 @@ Obtains the application context.
**Example** **Example**
```javascript ```javascript
import featureAbility from '@ohos.ability.featureability'; import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext() var context = featureAbility.getContext()
context.getBundleName() context.getBundleName()
``` ```
...@@ -461,7 +464,7 @@ Destroys this Page ability, with the result code and data sent to the caller. Th ...@@ -461,7 +464,7 @@ Destroys this Page ability, with the result code and data sent to the caller. Th
**Example** **Example**
```javascript ```javascript
import featureAbility from '@ohos.ability.featureability'; import featureAbility from '@ohos.ability.featureAbility';
featureAbility.terminateSelf() featureAbility.terminateSelf()
``` ```
...@@ -484,7 +487,7 @@ Destroys this Page ability, with the result code and data sent to the caller. Th ...@@ -484,7 +487,7 @@ Destroys this Page ability, with the result code and data sent to the caller. Th
**Example** **Example**
```javascript ```javascript
import featureAbility from '@ohos.ability.featureability'; import featureAbility from '@ohos.ability.featureAbility';
featureAbility.terminateSelf().then((data) => { featureAbility.terminateSelf().then((data) => {
console.info("==========================>terminateSelfCallBack=======================>"); console.info("==========================>terminateSelfCallBack=======================>");
}); });
......
# FormBindingData # FormBindingData
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 8. 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 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -38,12 +39,20 @@ Creates a **FormBindingData** object. ...@@ -38,12 +39,20 @@ Creates a **FormBindingData** object.
**Example** **Example**
```js ```js
let fd = fileio.openSync(path); import featureAbility from '@ohos.ability.featureAbility';
let obj = { import fileio from '@ohos.fileio';
"temperature": "21°", let context=featureAbility.getContext();
"formImages": {"image": fd} context.getOrCreateLocalDir((err,data)=>{
}; let path=data+"/xxx.jpg";
let formBindingDataObj = formBindingData.createFormBindingData(obj); let fd = fileio.openSync(path);
let obj = {
"temperature": "21°",
"formImages": {"image": fd}
};
let formBindingDataObj = formBindingData.createFormBindingData(obj);
})
``` ```
## Attributes ## Attributes
......
# FormExtension # FormExtension
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**
>
> The initial APIs of this module are supported since API version 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs of this module can be used only in the stage model.
Provides **FormExtension** APIs. Provides **FormExtension** APIs.
...@@ -33,19 +36,20 @@ Called to notify the widget provider that a **Form** instance (widget) has been ...@@ -33,19 +36,20 @@ Called to notify the widget provider that a **Form** instance (widget) has been
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | -------------------------------------- | ---- | ------------------------------------------------------------ | | ------ | -------------------------------------- | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-Want.md) | Yes | Information related to the extension, including the widget ID, name, and style. The information must be managed as persistent data to facilitate subsequent widget update and deletion.| | want | [Want](js-apis-application-Want.md) | Yes | Information related to the extension, including the widget ID, name, and style. The information must be managed as persistent data to facilitate subsequent widget update and deletion.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------------------------------------ | ----------------------------------------------------------- | | ------------------------------------------------------------ | ----------------------------------------------------------- |
| [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | A **formBindingData.FormBindingData** object containing the data to be displayed on the widget.| | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | A **formBindingData.FormBindingData** object containing the data to be displayed on the widget.|
**Example** **Example**
```js ```js
import formBindingData from '@ohos.application.formBindingData'
export default class MyFormExtension extends FormExtension { export default class MyFormExtension extends FormExtension {
onCreate(want) { onCreate(want) {
console.log('FormExtension onCreate, want:' + want.abilityName); console.log('FormExtension onCreate, want:' + want.abilityName);
...@@ -69,9 +73,9 @@ Called to notify the widget provider that a temporary widget has been converted ...@@ -69,9 +73,9 @@ Called to notify the widget provider that a temporary widget has been converted
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------ | | ------ | ------ | ---- | ------------------------ |
| formId | string | Yes | ID of the widget that requests to be converted to a normal one.| | formId | string | Yes | ID of the widget that requests to be converted to a normal one.|
**Example** **Example**
...@@ -93,13 +97,14 @@ Called to notify the widget provider that a widget has been updated. After obtai ...@@ -93,13 +97,14 @@ Called to notify the widget provider that a widget has been updated. After obtai
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ | | ------ | ------ | ---- | ------------------ |
| formId | string | Yes | ID of the widget that requests to be updated.| | formId | string | Yes | ID of the widget that requests to be updated.|
**Example** **Example**
```js ```js
import formBindingData from '@ohos.application.formBindingData'
export default class MyFormExtension extends FormExtension { export default class MyFormExtension extends FormExtension {
onUpdate(formId) { onUpdate(formId) {
console.log('FormExtension onUpdate, formId:' + formId); console.log('FormExtension onUpdate, formId:' + formId);
...@@ -123,13 +128,14 @@ Called to notify the widget provider of the change of visibility. ...@@ -123,13 +128,14 @@ Called to notify the widget provider of the change of visibility.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ---------------------------- | | --------- | ------------------------- | ---- | ---------------------------- |
| newStatus | { [key: string]: number } | Yes | ID and visibility status of the widget to be changed.| | newStatus | { [key: string]: number } | Yes | ID and visibility status of the widget to be changed.|
**Example** **Example**
```js ```js
import formBindingData from '@ohos.application.formBindingData'
export default class MyFormExtension extends FormExtension { export default class MyFormExtension extends FormExtension {
onVisibilityChange(newStatus) { onVisibilityChange(newStatus) {
console.log('FormExtension onVisibilityChange, newStatus:' + newStatus); console.log('FormExtension onVisibilityChange, newStatus:' + newStatus);
...@@ -157,10 +163,10 @@ Called to instruct the widget provider to receive and process the widget event. ...@@ -157,10 +163,10 @@ Called to instruct the widget provider to receive and process the widget event.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------- | | ------- | ------ | ---- | ---------------------- |
| formId | string | Yes | ID of the widget that requests the event.| | formId | string | Yes | ID of the widget that requests the event.|
| message | string | Yes | Event message. | | message | string | Yes | Event message. |
**Example** **Example**
...@@ -182,9 +188,9 @@ Called to notify the widget provider that a **Form** instance (widget) has been ...@@ -182,9 +188,9 @@ Called to notify the widget provider that a **Form** instance (widget) has been
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ | | ------ | ------ | ---- | ------------------ |
| formId | string | Yes | ID of the widget to be destroyed.| | formId | string | Yes | ID of the widget to be destroyed.|
**Example** **Example**
...@@ -206,16 +212,42 @@ Called when the configuration of the environment where the ability is running is ...@@ -206,16 +212,42 @@ Called when the configuration of the environment where the ability is running is
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [Configuration](#section188911144124715) | Yes| New configuration.| | config | [Configuration](#section188911144124715) | Yes| New configuration.|
**Example**
**Example**
```js ```js
class MyFormExtension extends MyFormExtension { class MyFormExtension extends FormExtension {
onConfigurationUpdated(config) { onConfigurationUpdated(config) {
console.log('onConfigurationUpdated, config:' + JSON.stringify(config)); console.log('onConfigurationUpdated, config:' + JSON.stringify(config));
} }
} }
``` ```
## FormExtension.onAcquireFormState
onAcquireFormState?(want: Want): formInfo.FormState;
Called when the widget provider receives the status query result of a specified service widget. By default, the initial state is returned.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | No | Description of the widget state, including the bundle name, ability name, module name, widget name, and widget dimension. |
**Example**
```js
import fromInfo from '@ohos.application.fromInfo'
class MyFormExtension extends FormExtension {
onAcquireFormState(want) {
console.log('FormExtension onAcquireFormState, want:' + want);
return fromInfo.FormState.UNKNOWN;
}
}
```
\ No newline at end of file
# FormExtensionContext # FormExtensionContext
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**
>
> The initial APIs of this module are supported since API version 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs of this module can be used only in the stage model.
Implements the context that provides the capabilities and APIs of **FormExtension**. This class is inherited from **ExtensionContext**. Implements the context that provides the capabilities and APIs of **FormExtension**. This class is inherited from **ExtensionContext**.
## Modules to Import
```js
import FormExtension from '@ohos.application.FormExtension';
```
## FormExtensionContext.updateForm ## FormExtensionContext.updateForm
updateForm(formId: string, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback\<void>): void updateForm(formId: string, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback\<void>): void
...@@ -15,19 +24,27 @@ Updates a widget. This method uses a callback to return the result. ...@@ -15,19 +24,27 @@ Updates a widget. This method uses a callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------------- | ------------------------------------------------------------ | ---- | -------------------------------------- | | --------------- | ------------------------------------------------------------ | ---- | -------------------------------------- |
| formId | string | Yes | ID of the widget that requests to be updated. | | formId | string | Yes | ID of the widget that requests to be updated. |
| formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes | New data of the widget. | | formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes | New data of the widget. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result indicating whether the method is successfully called.| | callback | AsyncCallback\<void> | Yes | Callback used to return the result indicating whether the method is successfully called.|
**Example** **Example**
```js ```js
let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"}); import formBindingData from '@ohos.application.formBindingData'
this.context.updateForm(formId, obj2, (data)=>{ export default class MyFormExtension extends FormExtension {
console.log('FormExtension context updateForm, data:' + data); onUpdate(formId) {
}); console.log('FormExtension onUpdate, formId:' + formId);
let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
this.context.updateForm(formId, obj2, (data)=>{
console.log('FormExtension context updateForm, data:' + data);
});
}
}
``` ```
## FormExtensionContext.updateForm ## FormExtensionContext.updateForm
...@@ -40,24 +57,31 @@ Updates a widget. This method uses a promise to return the result. ...@@ -40,24 +57,31 @@ Updates a widget. This method uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------------- | ------------------------------------------------------------ | ---- | ------------------ | | --------------- | ------------------------------------------------------------ | ---- | ------------------ |
| formId | string | Yes | ID of the widget that requests to be updated.| | formId | string | Yes | ID of the widget that requests to be updated.|
| formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes | New data of the widget. | | formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes | New data of the widget. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------------- | | -------------- | --------------------------------- |
| Promise\<void> | Promise returned with the result indicating whether the method is successfully called.| | Promise\<void> | Promise returned with the result indicating whether the method is successfully called.|
**Example** **Example**
``` ```js
let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"}); import formBindingData from '@ohos.application.formBindingData'
this.context.updateForm(formId, obj2) export default class MyFormExtension extends FormExtension {
.then((data)=>{ onUpdate(formId) {
console.log('FormExtension context updateForm, data:' + data); console.log('FormExtension onUpdate, formId:' + formId);
}).catch((error) => { let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
console.error('Operation updateForm failed. Cause: ' + error);}); this.context.updateForm(formId, obj2)
.then((data)=>{
console.log('FormExtension context updateForm, data:' + data);
}).catch((error) => {
console.error('Operation updateForm failed. Cause: ' + error);});
}
}
``` ```
# FormHost # FormHost
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**
>
> The initial APIs of this module are supported since API version 8. 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 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Provides APIs related to the widget host. Provides APIs related to the widget host.
...@@ -57,15 +58,15 @@ SystemCapability.Ability.Form ...@@ -57,15 +58,15 @@ SystemCapability.Ability.Form
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- | | ------ | ------ | ---- | ------- |
| formId | string | Yes | ID of a widget.| | formId | string | Yes | ID of a widget.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Parameters** **Parameters**
...@@ -147,16 +148,16 @@ SystemCapability.Ability.Form ...@@ -147,16 +148,16 @@ SystemCapability.Ability.Form
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------------- | ------ | ---- | ----------- | | -------------- | ------ | ---- | ----------- |
| formId | string | Yes | ID of a widget. | | formId | string | Yes | ID of a widget. |
| isReleaseCache | boolean | No | Whether to release the cache.| | isReleaseCache | boolean | No | Whether to release the cache.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Example** **Example**
...@@ -209,15 +210,15 @@ SystemCapability.Ability.Form ...@@ -209,15 +210,15 @@ SystemCapability.Ability.Form
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- | | ------ | ------ | ---- | ------- |
| formId | string | Yes | ID of a widget.| | formId | string | Yes | ID of a widget.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Example** **Example**
...@@ -270,15 +271,15 @@ SystemCapability.Ability.Form ...@@ -270,15 +271,15 @@ SystemCapability.Ability.Form
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- | | ------ | ------ | ---- | ------- |
| formId | string | Yes | ID of a widget.| | formId | string | Yes | ID of a widget.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Example** **Example**
...@@ -311,7 +312,7 @@ SystemCapability.Ability.Form ...@@ -311,7 +312,7 @@ SystemCapability.Ability.Form
**Example** **Example**
```js ```js
var formId = "12400633174999288"; var formId = ["12400633174999288"];
formHost.notifyVisibleForms(formId, (error, data) => { formHost.notifyVisibleForms(formId, (error, data) => {
if (error.code) { if (error.code) {
console.log('formHost notifyVisibleForms, error:' + JSON.stringify(error)); console.log('formHost notifyVisibleForms, error:' + JSON.stringify(error));
...@@ -337,14 +338,14 @@ SystemCapability.Ability.Form ...@@ -337,14 +338,14 @@ SystemCapability.Ability.Form
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Example** **Example**
```js ```js
var formId = "12400633174999288"; var formId = ["12400633174999288"];
formHost.notifyVisibleForms(formId).then(() => { formHost.notifyVisibleForms(formId).then(() => {
console.log('formHost notifyVisibleForms success'); console.log('formHost notifyVisibleForms success');
}).catch((error) => { }).catch((error) => {
...@@ -372,7 +373,7 @@ SystemCapability.Ability.Form ...@@ -372,7 +373,7 @@ SystemCapability.Ability.Form
**Example** **Example**
```js ```js
var formId = "12400633174999288"; var formId = ["12400633174999288"];
formHost.notifyInvisibleForms(formId, (error, data) => { formHost.notifyInvisibleForms(formId, (error, data) => {
if (error.code) { if (error.code) {
console.log('formHost notifyInvisibleForms, error:' + JSON.stringify(error)); console.log('formHost notifyInvisibleForms, error:' + JSON.stringify(error));
...@@ -398,14 +399,14 @@ SystemCapability.Ability.Form ...@@ -398,14 +399,14 @@ SystemCapability.Ability.Form
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Example** **Example**
```js ```js
var formId = "12400633174999288"; var formId = ["12400633174999288"];
formHost.notifyInvisibleForms(formId).then(() => { formHost.notifyInvisibleForms(formId).then(() => {
console.log('formHost notifyInvisibleForms success'); console.log('formHost notifyInvisibleForms success');
}).catch((error) => { }).catch((error) => {
...@@ -433,7 +434,7 @@ SystemCapability.Ability.Form ...@@ -433,7 +434,7 @@ SystemCapability.Ability.Form
**Example** **Example**
```js ```js
var formId = "12400633174999288"; var formId = ["12400633174999288"];
formHost.enableFormsUpdate(formId, (error, data) => { formHost.enableFormsUpdate(formId, (error, data) => {
if (error.code) { if (error.code) {
console.log('formHost enableFormsUpdate, error:' + JSON.stringify(error)); console.log('formHost enableFormsUpdate, error:' + JSON.stringify(error));
...@@ -459,14 +460,14 @@ SystemCapability.Ability.Form ...@@ -459,14 +460,14 @@ SystemCapability.Ability.Form
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Example** **Example**
```js ```js
var formId = "12400633174999288"; var formId = ["12400633174999288"];
formHost.enableFormsUpdate(formId).then(() => { formHost.enableFormsUpdate(formId).then(() => {
console.log('formHost enableFormsUpdate success'); console.log('formHost enableFormsUpdate success');
}).catch((error) => { }).catch((error) => {
...@@ -494,7 +495,7 @@ SystemCapability.Ability.Form ...@@ -494,7 +495,7 @@ SystemCapability.Ability.Form
**Example** **Example**
```js ```js
var formId = "12400633174999288"; var formId = ["12400633174999288"];
formHost.disableFormsUpdate(formId, (error, data) => { formHost.disableFormsUpdate(formId, (error, data) => {
if (error.code) { if (error.code) {
console.log('formHost disableFormsUpdate, error:' + JSON.stringify(error)); console.log('formHost disableFormsUpdate, error:' + JSON.stringify(error));
...@@ -520,14 +521,14 @@ SystemCapability.Ability.Form ...@@ -520,14 +521,14 @@ SystemCapability.Ability.Form
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Example** **Example**
```js ```js
var formId = "12400633174999288"; var formId = ["12400633174999288"];
formHost.disableFormsUpdate(formId).then(() => { formHost.disableFormsUpdate(formId).then(() => {
console.log('formHost disableFormsUpdate success'); console.log('formHost disableFormsUpdate success');
}).catch((error) => { }).catch((error) => {
...@@ -574,9 +575,9 @@ SystemCapability.Ability.Form ...@@ -574,9 +575,9 @@ SystemCapability.Ability.Form
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Example** **Example**
...@@ -591,7 +592,7 @@ SystemCapability.Ability.Form ...@@ -591,7 +592,7 @@ SystemCapability.Ability.Form
## getAllFormsInfo ## getAllFormsInfo
getAllFormsInfo(callback: AsyncCallback&lt;Array&lt;FormInfo&gt;&gt;): void; getAllFormsInfo(callback: AsyncCallback&lt;Array&lt;formInfo.FormInfo&gt;&gt;): void;
Obtains the widget information provided by all applications on the device. This API uses an asynchronous callback to return the result. Obtains the widget information provided by all applications on the device. This API uses an asynchronous callback to return the result.
...@@ -601,9 +602,9 @@ SystemCapability.Ability.Form ...@@ -601,9 +602,9 @@ SystemCapability.Ability.Form
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- | | ------ | ------ | ---- | ------- |
| callback | AsyncCallback&lt;Array&lt;[FormInfo](./js-apis-formInfo.md#forminfo-1)&gt;&gt; | Yes| Callback used to return the widget information.| | callback | AsyncCallback&lt;Array&lt;[FormInfo](./js-apis-formInfo.md#forminfo-1)&gt;&gt; | Yes| Callback used to return the widget information.|
**Example** **Example**
...@@ -619,7 +620,7 @@ SystemCapability.Ability.Form ...@@ -619,7 +620,7 @@ SystemCapability.Ability.Form
## getAllFormsInfo ## getAllFormsInfo
getAllFormsInfo(): Promise&lt;Array&lt;FormInfo&gt;&gt;; getAllFormsInfo(): Promise&lt;Array&lt;formInfo.FormInfo&gt;&gt;;
Obtains the widget information provided by all applications on the device. This API uses a promise to return the result. Obtains the widget information provided by all applications on the device. This API uses a promise to return the result.
...@@ -645,7 +646,7 @@ SystemCapability.Ability.Form ...@@ -645,7 +646,7 @@ SystemCapability.Ability.Form
## getFormsInfo ## getFormsInfo
getFormsInfo(bundleName: string, callback: AsyncCallback&lt;Array&lt;FormInfo&gt;&gt;): void; getFormsInfo(bundleName: string, callback: AsyncCallback&lt;Array&lt;formInfo.FormInfo&gt;&gt;): void;
Obtains the widget information provided by a given application on the device. This API uses an asynchronous callback to return the result. Obtains the widget information provided by a given application on the device. This API uses an asynchronous callback to return the result.
...@@ -655,10 +656,10 @@ SystemCapability.Ability.Form ...@@ -655,10 +656,10 @@ SystemCapability.Ability.Form
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- | | ------ | ------ | ---- | ------- |
| bundleName | string | Yes| Bundle name of the target application.| | bundleName | string | Yes| Bundle name of the target application.|
| callback | AsyncCallback&lt;Array&lt;[FormInfo](./js-apis-formInfo.md#forminfo-1)&gt;&gt; | Yes| Callback used to return the widget information.| | callback | AsyncCallback&lt;Array&lt;[FormInfo](./js-apis-formInfo.md#forminfo-1)&gt;&gt; | Yes| Callback used to return the widget information.|
**Example** **Example**
...@@ -674,7 +675,7 @@ SystemCapability.Ability.Form ...@@ -674,7 +675,7 @@ SystemCapability.Ability.Form
## getFormsInfo ## getFormsInfo
getFormsInfo(bundleName: string, moduleName: string, callback: AsyncCallback&lt;Array&lt;FormInfo&gt;&gt;): void; getFormsInfo(bundleName: string, moduleName: string, callback: AsyncCallback&lt;Array&lt;formInfo.FormInfo&gt;&gt;): void;
Obtains the widget information provided by a given application on the device. This API uses an asynchronous callback to return the result. Obtains the widget information provided by a given application on the device. This API uses an asynchronous callback to return the result.
...@@ -684,11 +685,11 @@ SystemCapability.Ability.Form ...@@ -684,11 +685,11 @@ SystemCapability.Ability.Form
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- | | ------ | ------ | ---- | ------- |
| bundleName | string | Yes| Bundle name of the target application.| | bundleName | string | Yes| Bundle name of the target application.|
| moduleName | string | Yes| Module name.| | moduleName | string | Yes| Module name.|
| callback | AsyncCallback&lt;Array&lt;[FormInfo](./js-apis-formInfo.md#forminfo-1)&gt;&gt; | Yes| Callback used to return the widget information.| | callback | AsyncCallback&lt;Array&lt;[FormInfo](./js-apis-formInfo.md#forminfo-1)&gt;&gt; | Yes| Callback used to return the widget information.|
**Example** **Example**
...@@ -704,7 +705,7 @@ SystemCapability.Ability.Form ...@@ -704,7 +705,7 @@ SystemCapability.Ability.Form
## getFormsInfo ## getFormsInfo
getFormsInfo(bundleName: string, moduleName?: string): Promise&lt;Array&lt;FormInfo&gt;&gt;; getFormsInfo(bundleName: string, moduleName?: string): Promise&lt;Array&lt;formInfo.FormInfo&gt;&gt;;
Obtains the widget information provided by a given application on the device. This API uses a promise to return the result. Obtains the widget information provided by a given application on the device. This API uses a promise to return the result.
...@@ -714,10 +715,10 @@ SystemCapability.Ability.Form ...@@ -714,10 +715,10 @@ SystemCapability.Ability.Form
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- | | ------ | ------ | ---- | ------- |
| bundleName | string | Yes| Bundle name of the target application.| | bundleName | string | Yes| Bundle name of the target application.|
| moduleName | string | No| Module name.| | moduleName | string | No| Module name.|
**Return value** **Return value**
...@@ -767,7 +768,7 @@ SystemCapability.Ability.Form ...@@ -767,7 +768,7 @@ SystemCapability.Ability.Form
## deleteInvalidForms ## deleteInvalidForms
function deleteInvalidForms(formIds: Array&lt;string&gt;): Promise&lt;number&gt;; deleteInvalidForms(formIds: Array&lt;string&gt;): Promise&lt;number&gt;;
Deletes invalid widgets from the list. This API uses a promise to return the result. Deletes invalid widgets from the list. This API uses a promise to return the result.
...@@ -800,7 +801,7 @@ SystemCapability.Ability.Form ...@@ -800,7 +801,7 @@ SystemCapability.Ability.Form
## acquireFormState ## acquireFormState
acquireFormState(want: Want, callback: AsyncCallback&lt;FormStateInfo&gt;): void; acquireFormState(want: Want, callback: AsyncCallback&lt;formInfo.FormStateInfo&gt;): void;
Obtains the widget state. This API uses an asynchronous callback to return the result. Obtains the widget state. This API uses an asynchronous callback to return the result.
...@@ -834,7 +835,7 @@ SystemCapability.Ability.Form ...@@ -834,7 +835,7 @@ SystemCapability.Ability.Form
## acquireFormState ## acquireFormState
function acquireFormState(want: Want): Promise&lt;FormStateInfo&gt;; acquireFormState(want: Want): Promise&lt;formInfo.FormStateInfo&gt;;
Obtains the widget state. This API uses a promise to return the result. Obtains the widget state. This API uses a promise to return the result.
...@@ -962,16 +963,16 @@ SystemCapability.Ability.Form ...@@ -962,16 +963,16 @@ SystemCapability.Ability.Form
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- | | ------ | ------ | ---- | ------- |
| formIds | Array&lt;string&gt; | Yes | List of widget IDs.| | formIds | Array&lt;string&gt; | Yes | List of widget IDs.|
| isVisible | boolean | Yes | Whether to be visible.| | isVisible | boolean | Yes | Whether to be visible.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Example** **Example**
...@@ -1025,16 +1026,16 @@ SystemCapability.Ability.Form ...@@ -1025,16 +1026,16 @@ SystemCapability.Ability.Form
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------- | | ------ | ------ | ---- | ------- |
| formIds | Array&lt;string&gt; | Yes | List of widget IDs.| | formIds | Array&lt;string&gt; | Yes | List of widget IDs.|
| isEnableUpdate | boolean | Yes | Whether to enable update.| | isEnableUpdate | boolean | Yes | Whether to enable update.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Example** **Example**
......
# ParticleAbility Module # ParticleAbility
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**
>
> The initial APIs of this module are supported since API version 7. 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 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs of this module can be used only in the FA module.
## Constraints ## Usage
The ParticleAbility module is used to perform operations on abilities of the Data and Service types. The ParticleAbility module is used to perform operations on abilities of the Data and Service types.
...@@ -196,11 +199,11 @@ Requests a continuous task from the system. This API uses an asynchronous callba ...@@ -196,11 +199,11 @@ Requests a continuous task from the system. This API uses an asynchronous callba
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| id | number | Yes| Notification ID of a continuous task.| | id | number | Yes| Notification ID of a continuous task.|
| request | NotificationRequest | Yes| Notification parameter, which is used to display information in the notification bar.| | request | NotificationRequest | Yes| Notification parameter, which is used to display information in the notification bar.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -226,7 +229,7 @@ let wantAgentInfo = { ...@@ -226,7 +229,7 @@ let wantAgentInfo = {
], ],
operationType: wantAgent.OperationType.START_ABILITY, operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0, requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG] wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}; };
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
...@@ -235,11 +238,11 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { ...@@ -235,11 +238,11 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
text: "text" text: "text"
}; };
let notificationContent = { let notificationContent = {
contentType: notification.ContentType.NOTIFICATION_CONTENT_TEXT, contentType: notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: basicContent normal: basicContent
}; };
let request = { let request = {
content: notificatonContent, content: notificationContent,
wantAgent: wantAgentObj wantAgent: wantAgentObj
}; };
let id = 1; let id = 1;
...@@ -287,7 +290,7 @@ let wantAgentInfo = { ...@@ -287,7 +290,7 @@ let wantAgentInfo = {
], ],
operationType: wantAgent.OperationType.START_ABILITY, operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0, requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG] wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}; };
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
...@@ -296,11 +299,11 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { ...@@ -296,11 +299,11 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
text: "text" text: "text"
}; };
let notificationContent = { let notificationContent = {
contentType: notification.ContentType.NOTIFICATION_CONTENT_TEXT, contentType: notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: basicContent normal: basicContent
}; };
let request = { let request = {
content: notificatonContent, content: notificationContent,
wantAgent: wantAgentObj wantAgent: wantAgentObj
}; };
let id = 1; let id = 1;
...@@ -323,9 +326,9 @@ Requests to cancel a continuous task from the system. This API uses an asynchron ...@@ -323,9 +326,9 @@ Requests to cancel a continuous task from the system. This API uses an asynchron
**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. |
**Example** **Example**
...@@ -401,6 +404,7 @@ Connects this ability to a specific Service ability. This API uses a callback to ...@@ -401,6 +404,7 @@ Connects this ability to a specific Service ability. This API uses a callback to
**Example** **Example**
```js ```js
import rpc from '@ohos.rpc'
function onConnectCallback(element, remote){ function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy)); console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
} }
...@@ -422,8 +426,10 @@ Connects this ability to a specific Service ability. This API uses a callback to ...@@ -422,8 +426,10 @@ Connects this ability to a specific Service ability. This API uses a callback to
}, },
); );
particleAbility.disconnectAbility(connId).then((error,data)=>{ particleAbility.disconnectAbility(connId).then((data)=>{
console.log('particleAbilityTest result errCode : ' + error.code + " data: " + data); console.log( " data: " + data);
}).catch((error)=>{
console.log('particleAbilityTest result errCode : ' + error.code )
}); });
...@@ -440,13 +446,14 @@ Disconnects this ability from the Service ability. This API uses a callback to r ...@@ -440,13 +446,14 @@ Disconnects this ability from the Service ability. This API uses a callback to r
**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. |
**Example** **Example**
```js ```js
import rpc from '@ohos.rpc'
function onConnectCallback(element, remote){ function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy)); console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
} }
...@@ -467,11 +474,11 @@ Disconnects this ability from the Service ability. This API uses a callback to r ...@@ -467,11 +474,11 @@ Disconnects this ability from the Service ability. This API uses a callback to r
onFailed: onFailedCallback, onFailed: onFailedCallback,
}, },
); );
var result = particleAbility.disconnectAbility(connId, var result = particleAbility.disconnectAbility(connId).then((data)=>{
(error,data) => { console.log( " data: " + data);
console.log('particleAbilityTest DisConnectJsSameBundleName result errCode : ' + error.code + " data: " + data) }).catch((error)=>{
}, console.log('particleAbilityTest result errCode : ' + error.code )
); });
``` ```
...@@ -493,6 +500,7 @@ Disconnects this ability from the Service ability. This API uses a promise to re ...@@ -493,6 +500,7 @@ Disconnects this ability from the Service ability. This API uses a promise to re
**Example** **Example**
```js ```js
import rpc from '@ohos.rpc'
function onConnectCallback(element, remote){ function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy)); console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
} }
...@@ -514,8 +522,10 @@ function onConnectCallback(element, remote){ ...@@ -514,8 +522,10 @@ function onConnectCallback(element, remote){
}, },
); );
particleAbility.disconnectAbility(connId).then((error,data)=>{ particleAbility.disconnectAbility(connId).then((data)=>{
console.log('particleAbilityTest result errCode : ' + error.code + " data: " + data); console.log( " data: " + data);
}).catch((error)=>{
console.log('particleAbilityTest result errCode : ' + error.code )
}); });
``` ```
......
# PermissionRequestResult # PermissionRequestResult
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs of this module can be used only in the stage model.
Provides the permission request result. Provides the permission request result.
## Modules to Import
```js
import Ability from '@ohos.application.Ability'
```
## Usage
The permission request result is obtained through an **AbilityStage** instance.
```js
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
var permissions=['com.example.permission']
var permissionRequestResult;
this.context.requestPermissionsFromUser(permissions,(err,result) => {
if(err){
console.log('requestPermissionsFromUserError: ' + JSON.stringify(err));
}else{
permissionRequestResult=result;
console.log('permissionRequestResult: ' + JSON.stringify(permissionRequestResult));
}
});
}
}
```
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| No| Permissions requested.| | permissions | Array&lt;string&gt; | Yes| No| Permissions requested.|
| authResults | Array&lt;number&gt; | Yes| No| Whether the requested permissions are granted or denied. The value **0** means that the requests permissions are granted, and **-1** means the opposite. | | authResults | Array&lt;number&gt; | Yes| No| Whether the requested permissions are granted or denied. The value **0** means that the requests permissions are granted, and **-1** means the opposite. |
# ProcessRunningInfo # ProcessRunningInfo
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 8. 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 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Provides process running information. Provides process running information.
## Modules to Import
```js
import appManager from '@ohos.application.appManager'
```
## Usage ## Usage
The process running information is obtained through an **appManager** instance. The process running information is obtained through an **appManager** instance.
```js ```js
import appManager from '@ohos.application.appManager'; import appManager from '@ohos.application.appManager';
appManager.getProcessRunningInfos((error,data) => { appManager.getProcessRunningInfos((error,data) => {
...@@ -26,9 +30,9 @@ appManager.getProcessRunningInfos((error,data) => { ...@@ -26,9 +30,9 @@ appManager.getProcessRunningInfos((error,data) => {
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| pid | number | Yes| No| Process ID.| | pid | number | Yes| No| Process ID.|
| uid | number | Yes| No| User ID.| | uid | number | Yes| No| User ID.|
| processName | string | Yes| No| Process name.| | processName | string | Yes| No| Process name.|
| bundleNames | Array&lt;string&gt; | Yes| No| Names of all bundles running in the process.| | bundleNames | Array&lt;string&gt; | Yes| No| Names of all bundles running in the process.|
# ServiceExtensionAbility # ServiceExtensionAbility
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**
>
> The initial APIs of this module are supported since API version 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs of this module can be used only in the stage model.
Provides APIs related to **ServiceExtension**. Provides APIs related to **ServiceExtension**.
...@@ -23,9 +26,9 @@ None. ...@@ -23,9 +26,9 @@ None.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| context | [ServiceExtensionContext](js-apis-service-extension-context.md) | Yes| No| Service extension context, which is inherited from **ExtensionContext**.| | context | [ServiceExtensionContext](js-apis-service-extension-context.md) | Yes| No| Service extension context, which is inherited from **ExtensionContext**.|
## ServiceExtensionAbility.onCreate ## ServiceExtensionAbility.onCreate
...@@ -38,9 +41,9 @@ Called when an extension is created to initialize the service logic. ...@@ -38,9 +41,9 @@ Called when an extension is created to initialize the service logic.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information related to this extension, including the ability name and bundle name.| | want | [Want](js-apis-application-Want.md) | Yes| Information related to this extension, including the ability name and bundle name.|
**Example** **Example**
...@@ -82,10 +85,10 @@ Called after **onCreate** is invoked when an ability is started by calling **sta ...@@ -82,10 +85,10 @@ Called after **onCreate** is invoked when an ability is started by calling **sta
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information related to this extension, including the ability name and bundle name.| | want | [Want](js-apis-application-Want.md) | Yes| Information related to this extension, including the ability name and bundle name.|
| startId | number | Yes| Number of ability start times. The initial value is **1**, and the value is automatically incremented for each ability started.| | startId | number | Yes| Number of ability start times. The initial value is **1**, and the value is automatically incremented for each ability started.|
**Example** **Example**
...@@ -108,15 +111,15 @@ Called after **onCreate** is invoked when an ability is started by calling **con ...@@ -108,15 +111,15 @@ Called after **onCreate** is invoked when an ability is started by calling **con
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md)| Yes| Information related to this extension, including the ability name and bundle name.| | want | [Want](js-apis-application-Want.md)| Yes| Information related to this extension, including the ability name and bundle name.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| rpc.RemoteObject | A **RemoteObject** object used for communication with the client.| | rpc.RemoteObject | A **RemoteObject** object used for communication with the client.|
**Example** **Example**
...@@ -126,7 +129,7 @@ Called after **onCreate** is invoked when an ability is started by calling **con ...@@ -126,7 +129,7 @@ Called after **onCreate** is invoked when an ability is started by calling **con
constructor(des) { constructor(des) {
super(des); super(des);
} }
onRemoteRequest(code, data, reply, option) { onConnect(code, data, reply, option) {
} }
} }
class ServiceExt extends ServiceExtension { class ServiceExt extends ServiceExtension {
...@@ -148,9 +151,9 @@ Called when the ability is disconnected. ...@@ -148,9 +151,9 @@ Called when the ability is disconnected.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want |[Want](js-apis-application-Want.md)| Yes| Information related to this extension, including the ability name and bundle name.| | want |[Want](js-apis-application-Want.md)| Yes| Information related to this extension, including the ability name and bundle name.|
**Example** **Example**
......
# ServiceExtensionContext # ServiceExtensionContext
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**
>
> The initial APIs of this module are supported since API version 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs of this module can be used only in the stage model.
Implements the context that provides the capabilities and APIs of **ServiceExtension**. This class is inherited from **ExtensionContext**. Implements the context that provides the capabilities and APIs of **ServiceExtension**. This class is inherited from **ExtensionContext**.
## Modules to Import
```
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
```
## startAbility ## startAbility
...@@ -17,21 +25,26 @@ Starts an ability. This API uses a callback to return the result. ...@@ -17,21 +25,26 @@ Starts an ability. This API uses a callback to return the result.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the ability to start, such as the ability name and bundle name.| | want | [Want](js-apis-application-Want.md) | Yes| Information about the ability to start, such as the ability name and bundle name.|
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the API is successfully called.| | callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the API is successfully called.|
**Example** **Example**
```js ```js
let want = { import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
"bundleName": "com.example.myapp", class MainAbility extends ExtensionContext {
"abilityName": "com.example.myapp.MyAbility" onWindowStageCreate(windowStage) {
}; let want = {
this.context.startAbility(want, (err) => { "bundleName": "com.example.myapp",
console.log('startAbility result:' + JSON.stringfy(err)); "abilityName": "MyAbility"};
}); this.context.startAbility(want, (err) => {
console.log('startAbility result:' + JSON.stringify(err));
});
}
}
``` ```
...@@ -45,28 +58,35 @@ Starts an ability. This API uses a promise to return the result. ...@@ -45,28 +58,35 @@ Starts an ability. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the ability to start, such as the ability name and bundle name.| | want | [Want](js-apis-application-Want.md) | Yes| Information about the ability to start, such as the ability name and bundle name.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Example** **Example**
```js ```js
let want = { import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
"bundleName": "com.example.myapp", class MainAbility extends ExtensionContext {
"abilityName": "com.example.myapp.MyAbility" onWindowStageCreate(windowStage) {
}; let want = {
this.context.startAbility(want).then((data) => { "bundleName": "com.example.myapp",
console.log('success:' + JSON.stringfy(data)); "abilityName": "MyAbility"
}).catch((error) => { };
console.log('failed:' + JSON.stringfy(error)); this.context.startAbility(want).then((data) => {
}); console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
}
``` ```
...@@ -80,16 +100,23 @@ Terminates this ability. This API uses a callback to return the result. ...@@ -80,16 +100,23 @@ Terminates this ability. This API uses a callback to return the result.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the API is successfully called.| | callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the API is successfully called.|
**Example** **Example**
```js ```js
this.context.terminateSelf((err) => { import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
console.log('terminateSelf result:' + JSON.stringfy(err)); class MainAbility extends ExtensionContext {
}); onWindowStageCreate(windowStage) {
this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringify(err));
});
}
}
``` ```
...@@ -103,18 +130,24 @@ Terminates this ability. This API uses a promise to return the result. ...@@ -103,18 +130,24 @@ Terminates this ability. This API uses a promise to return the result.
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Example** **Example**
```js ```js
this.context.terminateSelf(want).then((data) => { import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
console.log('success:' + JSON.stringfy(data)); class MainAbility extends ExtensionContext {
}).catch((error) => { onWindowStageCreate(windowStage) {
console.log('failed:' + JSON.stringfy(error)); this.context.terminateSelf().then((data) => {
}); console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
}
``` ```
...@@ -128,23 +161,23 @@ Connects this ability to a Service ability. ...@@ -128,23 +161,23 @@ Connects this ability to a Service ability.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the ability to connect to, such as the ability name and bundle name.| | want | [Want](js-apis-application-Want.md) | Yes| Information about the ability to connect to, such as the ability name and bundle name.|
| options | [ConnectOptions](#connectoptions) | Yes| Callback used to return the information indicating that the connection is successful, interrupted, or failed.| | options | [ConnectOptions](#connectoptions) | Yes| Callback used to return the information indicating that the connection is successful, interrupted, or failed.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | A number, based on which the connection will be interrupted.| | number | A number, based on which the connection will be interrupted.|
**Example** **Example**
```js ```js
let want = { let want = {
"bundleName": "com.example.myapp", "bundleName": "com.example.myapp",
"abilityName": "com.example.myapp.MyAbility" "abilityName": "MyAbility"
}; };
let options = { let options = {
onConnect: function(elementName, proxy) {}, onConnect: function(elementName, proxy) {},
...@@ -165,17 +198,26 @@ Disconnects this ability from the Service ability. This API uses a callback to r ...@@ -165,17 +198,26 @@ Disconnects this ability from the Service ability. This API uses a callback to r
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| connection | number | Yes| Number returned after **connectAbility** is called.| | connection | number | Yes| Number returned after **connectAbility** is called.|
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the API is successfully called.| | callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the API is successfully called.|
**Example** **Example**
```js ```js
this.context.disconnectAbility(connection, (err) => { // connection is the return value of connectAbility. import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
console.log('terminateSelf result:' + JSON.stringfy(err)); class MainAbility extends ExtensionContext {
}); onWindowStageCreate(windowStage) {
let connection=1
this.context.disconnectAbility(connection, (err) => {
// connection is the return value of connectAbility.
console.log('terminateSelf result:' + JSON.stringify(err));
});
}
}
``` ```
...@@ -189,24 +231,31 @@ Disconnects this ability from the Service ability. This API uses a promise to re ...@@ -189,24 +231,31 @@ Disconnects this ability from the Service ability. This API uses a promise to re
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| connection | number | Yes| Number returned after **connectAbility** is called.| | connection | number | Yes| Number returned after **connectAbility** is called.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
**Example** **Example**
```js ```js
this.context.disconnectAbility(connection).then((data) => { // connection is the return value of connectAbility. import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
console.log('success:' + JSON.stringfy(data)); class MainAbility extends ExtensionContext {
}).catch((error) => { onWindowStageCreate(windowStage) {
console.log('failed:' + JSON.stringfy(error)); let connection=1
}); this.context.disconnectAbility(connection).then((data) => { // connection is the return value of connectAbility.
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
}
``` ```
...@@ -216,8 +265,8 @@ Defines the **ConnectOptions** data structure. ...@@ -216,8 +265,8 @@ Defines the **ConnectOptions** data structure.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| onConnect(elementName:ElementName,&nbsp;remote:IRemoteObject) | Called when this ability is connected to a Service ability.| | onConnect(elementName:ElementName,&nbsp;remote:IRemoteObject) | Called when this ability is connected to a Service ability.|
| onDisconnect(elementName:ElementName) | Called when the peer service is abnormal or killed.| | onDisconnect(elementName:ElementName) | Called when the peer service is abnormal or killed.|
| onFailed(code:&nbsp;number) | Called when the connection fails.| | onFailed(code:&nbsp;number) | Called when the connection fails.|
# uriPermissionManager # uriPermissionManager
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -11,7 +12,7 @@ Implements URI permission management. ...@@ -11,7 +12,7 @@ Implements URI permission management.
``` ```
import uriPermissionManager from '@ohos.application.uriPermissionManager'; import UriPermissionManager from '@ohos.application.uriPermissionManager';
``` ```
...@@ -27,18 +28,20 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -27,18 +28,20 @@ SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uri | string | Yes | URI of a file, for example, **fileshare:///com.samples.filesharetest.FileShare/person/10**. | | uri | string | Yes | URI of a file, for example, **fileshare:///com.samples.filesharetest.FileShare/person/10**. |
| flag | wantConstant.Flags | Yes | Read or write permission on the file specified by the URI. | | flag | wantConstant.Flags | Yes | Read or write permission on the file specified by the URI. |
| accessTokenId | number | Yes | Unique ID of an application, which is obtained through the **BundleManager** API. | | accessTokenId | number | Yes | Unique ID of an application, which is obtained through the **BundleManager** API. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the check result. The value **0** means that the application has the specified permission, and **-1** means the opposite. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the check result. The value **0** means that the application has the specified permission, and **-1** means the opposite. |
**Example** **Example**
``` ```js
import WantConstant from '@ohos.ability.wantConstant';
let accessTokenId =1
let uri = "fileshare:///com.samples.filesharetest.FileShare/person/10" let uri = "fileshare:///com.samples.filesharetest.FileShare/person/10"
UriPermissionManager.verifyUriPermission(uri, wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, accessTokenId, (result) => { UriPermissionManager.verifyUriPermission(uri, WantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, accessTokenId, (result) => {
console.log("result.code = " + result.code) console.log("result.code = " + result.code)
}) // accessTokenId is obtained through the **BundleManager** API. }) // accessTokenId is obtained through the **BundleManager** API.
``` ```
...@@ -56,21 +59,23 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -56,21 +59,23 @@ SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uri | string | Yes | URI of a file, for example, **fileshare:///com.samples.filesharetest.FileShare/person/10**. | | uri | string | Yes | URI of a file, for example, **fileshare:///com.samples.filesharetest.FileShare/person/10**. |
| flag | wantConstant.Flags | Yes | Read or write permission on the file specified by the URI. | | flag | wantConstant.Flags | Yes | Read or write permission on the file specified by the URI. |
| accessTokenId | number | Yes | Unique ID of an application, which is obtained through the **BundleManager** API. | | accessTokenId | number | Yes | Unique ID of an application, which is obtained through the **BundleManager** API. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the check result. The value **0** means that the application has the specified permission, and **-1** means the opposite. | | Promise&lt;number&gt; | Promise used to return the check result. The value **0** means that the application has the specified permission, and **-1** means the opposite. |
**Example** **Example**
``` ```js
import WantConstant from '@ohos.ability.wantConstant';
let accessTokenId =1
let uri = "fileshare:///com.samples.filesharetest.FileShare/person/10" let uri = "fileshare:///com.samples.filesharetest.FileShare/person/10"
UriPermissionManager.verifyUriPermission(uri, wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, accessTokenId) UriPermissionManager.verifyUriPermission(uri, wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, accessTokenId)
.then((data) => { .then((data) => {
......
...@@ -29,7 +29,6 @@ Obtains a **WantAgent** object. This API uses an asynchronous callback to return ...@@ -29,7 +29,6 @@ Obtains a **WantAgent** object. This API uses an asynchronous callback to return
```js ```js
import WantAgent from '@ohos.wantAgent'; import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// getWantAgent callback // getWantAgent callback
function getWantAgentCallback(err, data) { function getWantAgentCallback(err, data) {
...@@ -58,9 +57,9 @@ var wantAgentInfo = { ...@@ -58,9 +57,9 @@ var wantAgentInfo = {
} }
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
...@@ -92,7 +91,7 @@ Obtains a **WantAgent** object. This API uses a promise to return the result. ...@@ -92,7 +91,7 @@ Obtains a **WantAgent** object. This API uses a promise to return the result.
```js ```js
import WantAgent from '@ohos.wantAgent'; import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgentInfo object // WantAgentInfo object
var wantAgentInfo = { var wantAgentInfo = {
...@@ -117,9 +116,9 @@ var wantAgentInfo = { ...@@ -117,9 +116,9 @@ var wantAgentInfo = {
} }
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
WantAgent.getWantAgent(wantAgentInfo).then((data) => { WantAgent.getWantAgent(wantAgentInfo).then((data) => {
...@@ -148,7 +147,7 @@ Obtains the bundle name of a **WantAgent** object. This API uses an asynchronous ...@@ -148,7 +147,7 @@ Obtains the bundle name of a **WantAgent** object. This API uses an asynchronous
```js ```js
import WantAgent from '@ohos.wantAgent'; import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object // WantAgent object
var wantAgent; var wantAgent;
...@@ -185,9 +184,9 @@ var wantAgentInfo = { ...@@ -185,9 +184,9 @@ var wantAgentInfo = {
} }
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
...@@ -225,7 +224,7 @@ Obtains the bundle name of a **WantAgent** object. This API uses a promise to re ...@@ -225,7 +224,7 @@ Obtains the bundle name of a **WantAgent** object. This API uses a promise to re
```js ```js
import WantAgent from '@ohos.wantAgent'; import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object // WantAgent object
var wantAgent; var wantAgent;
...@@ -253,9 +252,9 @@ var wantAgentInfo = { ...@@ -253,9 +252,9 @@ var wantAgentInfo = {
} }
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
WantAgent.getWantAgent(wantAgentInfo).then((data) => { WantAgent.getWantAgent(wantAgentInfo).then((data) => {
...@@ -289,7 +288,7 @@ Obtains the user ID of a **WantAgent** object. This API uses an asynchronous cal ...@@ -289,7 +288,7 @@ Obtains the user ID of a **WantAgent** object. This API uses an asynchronous cal
```js ```js
import WantAgent from '@ohos.wantAgent'; import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object // WantAgent object
var wantAgent; var wantAgent;
...@@ -326,9 +325,9 @@ var wantAgentInfo = { ...@@ -326,9 +325,9 @@ var wantAgentInfo = {
} }
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
...@@ -366,7 +365,7 @@ Obtains the user ID of a **WantAgent** object. This API uses a promise to return ...@@ -366,7 +365,7 @@ Obtains the user ID of a **WantAgent** object. This API uses a promise to return
```js ```js
import WantAgent from '@ohos.wantAgent'; import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object // WantAgent object
var wantAgent; var wantAgent;
...@@ -394,9 +393,9 @@ var wantAgentInfo = { ...@@ -394,9 +393,9 @@ var wantAgentInfo = {
} }
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
WantAgent.getWantAgent(wantAgentInfo).then((data) => { WantAgent.getWantAgent(wantAgentInfo).then((data) => {
...@@ -430,7 +429,7 @@ Obtains the want in a **WantAgent** object. This API uses an asynchronous callba ...@@ -430,7 +429,7 @@ Obtains the want in a **WantAgent** object. This API uses an asynchronous callba
```js ```js
import WantAgent from '@ohos.wantAgent'; import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object // WantAgent object
var wantAgent; var wantAgent;
...@@ -467,9 +466,9 @@ var wantAgentInfo = { ...@@ -467,9 +466,9 @@ var wantAgentInfo = {
} }
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
...@@ -507,7 +506,7 @@ Obtains the want in a **WantAgent** object. This API uses a promise to return th ...@@ -507,7 +506,7 @@ Obtains the want in a **WantAgent** object. This API uses a promise to return th
```js ```js
import WantAgent from '@ohos.wantAgent'; import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object // WantAgent object
var wantAgent; var wantAgent;
...@@ -535,9 +534,9 @@ var wantAgentInfo = { ...@@ -535,9 +534,9 @@ var wantAgentInfo = {
} }
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
WantAgent.getWantAgent(wantAgentInfo).then((data) => { WantAgent.getWantAgent(wantAgentInfo).then((data) => {
...@@ -571,7 +570,7 @@ Cancels a **WantAgent** object. This API uses an asynchronous callback to return ...@@ -571,7 +570,7 @@ Cancels a **WantAgent** object. This API uses an asynchronous callback to return
```js ```js
import WantAgent from '@ohos.wantAgent'; import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object // WantAgent object
var wantAgent; var wantAgent;
...@@ -608,9 +607,9 @@ var wantAgentInfo = { ...@@ -608,9 +607,9 @@ var wantAgentInfo = {
} }
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
...@@ -648,7 +647,7 @@ Cancels a **WantAgent** object. This API uses a promise to return the result. ...@@ -648,7 +647,7 @@ Cancels a **WantAgent** object. This API uses a promise to return the result.
```js ```js
import WantAgent from '@ohos.wantAgent'; import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object // WantAgent object
var wantAgent; var wantAgent;
...@@ -676,9 +675,9 @@ var wantAgentInfo = { ...@@ -676,9 +675,9 @@ var wantAgentInfo = {
} }
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
WantAgent.getWantAgent(wantAgentInfo).then((data) => { WantAgent.getWantAgent(wantAgentInfo).then((data) => {
...@@ -713,7 +712,7 @@ Triggers a **WantAgent** object. This API uses an asynchronous callback to retur ...@@ -713,7 +712,7 @@ Triggers a **WantAgent** object. This API uses an asynchronous callback to retur
```js ```js
import WantAgent from '@ohos.wantAgent'; import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object // WantAgent object
var wantAgent; var wantAgent;
...@@ -750,15 +749,15 @@ var wantAgentInfo = { ...@@ -750,15 +749,15 @@ var wantAgentInfo = {
} }
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
// trigger callback //trigger callback
function triggerCallback(err, data) { function triggerCallback(data) {
console.info("==========================>triggerCallback=======================>"); console.info("==========================>triggerCallback=======================>");
} }
...@@ -790,7 +789,7 @@ Checks whether two **WantAgent** objects are equal. This API uses an asynchronou ...@@ -790,7 +789,7 @@ Checks whether two **WantAgent** objects are equal. This API uses an asynchronou
```js ```js
import WantAgent from '@ohos.wantAgent'; import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object // WantAgent object
var wantAgent1; var wantAgent1;
...@@ -829,9 +828,9 @@ var wantAgentInfo = { ...@@ -829,9 +828,9 @@ var wantAgentInfo = {
} }
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
...@@ -870,7 +869,7 @@ Checks whether two **WantAgent** objects are equal. This API uses a promise to r ...@@ -870,7 +869,7 @@ Checks whether two **WantAgent** objects are equal. This API uses a promise to r
```js ```js
import WantAgent from '@ohos.wantAgent'; import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object // WantAgent object
var wantAgent1; var wantAgent1;
...@@ -899,9 +898,9 @@ var wantAgentInfo = { ...@@ -899,9 +898,9 @@ var wantAgentInfo = {
} }
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} }
WantAgent.getWantAgent(wantAgentInfo).then((data) => { WantAgent.getWantAgent(wantAgentInfo).then((data) => {
...@@ -915,6 +914,135 @@ WantAgent.equal(wantAgent1, wantAgent2).then((data) => { ...@@ -915,6 +914,135 @@ WantAgent.equal(wantAgent1, wantAgent2).then((data) => {
}); });
``` ```
## WantAgent.getOperationType<sup>9+</sup>
getOperationType(agent: WantAgent, callback: AsyncCallback\<number>): void;
Obtains the operation type of a **WantAgent** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Readable | Writable | Type | Mandatory | Description |
| ---------- | --- | ---- | ------------------------ | ---- | --------------------------------------- |
| agent | Yes | No | WantAgent | Yes | Target **WantAgent** object. |
| callback | Yes | No | AsyncCallback\<number> | Yes | Callback used to return the operation type. |
**Example**
```js
import WantAgent from '@ohos.wantAgent';
//wantAgent����
var wantAgent;
//WantAgentInfo����
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
wantAgent = data;
});
WantAgent.getOperationType(wantAgent, (OperationType) => {
console.log('----------- getOperationType ----------, OperationType: ' + OperationType);
})
```
## WantAgent.getOperationType<sup>9+</sup>
getOperationType(agent: WantAgent): Promise\<number>;
Obtains the operation type of a **WantAgent** object. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Readable | Writable | Type | Mandatory | Description |
| ---------- | --- | ---- | --------- | ---- | ------------- |
| agent | Yes | No | WantAgent | Yes | Target **WantAgent** object. |
**Return value**
| Type | Description |
| ---------------- | ------------------------------------------ |
| Promise\<number> | Promise used to return the operation type. |
**Example**
```js
import WantAgent from '@ohos.wantAgent';
//wantAgent����
var wantAgent;
//WantAgentInfo����
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
wantAgent = data;
});
WantAgent.getOperationType(wantAgent).then((OperationType) => {
console.log('getOperationType success, OperationType: ' + OperationType);
}).catch((err) => {
console.log('getOperationType fail, err: ' + err);
})
```
## WantAgentInfo ## WantAgentInfo
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册