提交 9dbb03af 编写于 作者: G Gloria

Update docs against 17813

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 c4647178
...@@ -7,14 +7,12 @@ The **AbilityLifecycleCallback** module defines the callbacks to receive lifecyc ...@@ -7,14 +7,12 @@ The **AbilityLifecycleCallback** module defines the callbacks to receive lifecyc
> 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. > The APIs of this module can be used only in the stage model.
## Modules to Import ## Modules to Import
```ts ```ts
import AbilityLifecycleCallback from '@ohos.app.ability.AbilityLifecycleCallback'; import AbilityLifecycleCallback from '@ohos.app.ability.AbilityLifecycleCallback';
``` ```
## AbilityLifecycleCallback.onAbilityCreate ## AbilityLifecycleCallback.onAbilityCreate
onAbilityCreate(ability: UIAbility): void; onAbilityCreate(ability: UIAbility): void;
......
...@@ -11,7 +11,6 @@ The **appRecovery** module provides APIs for recovering faulty applications. ...@@ -11,7 +11,6 @@ The **appRecovery** module provides APIs for recovering faulty applications.
import appRecovery from '@ohos.app.ability.appRecovery'; import appRecovery from '@ohos.app.ability.appRecovery';
``` ```
## appRecovery.RestartFlag ## appRecovery.RestartFlag
Enumerates the application restart flags. This enum is used as an input parameter of [enableAppRecovery](#apprecoveryenableapprecovery). Enumerates the application restart flags. This enum is used as an input parameter of [enableAppRecovery](#apprecoveryenableapprecovery).
...@@ -51,7 +50,7 @@ Enumerates the application state saving modes. This enum is used as an input par ...@@ -51,7 +50,7 @@ Enumerates the application state saving modes. This enum is used as an input par
enableAppRecovery(restart?: [RestartFlag](#apprecoveryrestartflag), saveOccasion?: [SaveOccasionFlag](#apprecoverysaveoccasionflag), saveMode?: [SaveModeFlag](#apprecoverysavemodeflag)) : void; enableAppRecovery(restart?: [RestartFlag](#apprecoveryrestartflag), saveOccasion?: [SaveOccasionFlag](#apprecoverysaveoccasionflag), saveMode?: [SaveModeFlag](#apprecoverysavemodeflag)) : void;
Enables application recovery. Enables application recovery. After this API is called, the first ability that is displayed when the application is started from the initiator can be restored.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
......
# @ohos.app.ability.contextConstant (ContextConstant) # @ohos.app.ability.contextConstant (ContextConstant)
The **ContextConstant** module defines context-related enums. Currently, it defines only the enum of data encryption levels. The **ContextConstant** module defines context-related enums. Currently, it defines only the enum of encryption levels.
> **NOTE** > **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. > The APIs of this module can be used only in the stage model.
## Modules to Import ## Modules to Import
...@@ -21,5 +22,5 @@ You can obtain the value of this constant by calling the **ContextConstant.AreaM ...@@ -21,5 +22,5 @@ You can obtain the value of this constant by calling the **ContextConstant.AreaM
| Name| Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| EL1 | 0 | Device-level encryption area, which is accessible after the device is powered on.| | EL1 | 0 | Device-level encryption. Directories with this encryption level are accessible after the device is powered on. |
| EL2 | 1 | User-level encryption area, which is accessible only after the device is powered on and the password is entered (for the first time).| | EL2 | 1 | User-level encryption. Directories with this encryption level are accessible only after the device is powered on and the password is entered (for the first time). |
...@@ -6,9 +6,15 @@ The **AbilityResult** module defines the result code and data returned when an a ...@@ -6,9 +6,15 @@ The **AbilityResult** module defines the result code and data returned when an a
> >
> 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
```ts
import ability from '@ohos.ability.ability';
```
**System capability**: SystemCapability.Ability.AbilityBase **System capability**: SystemCapability.Ability.AbilityBase
| Name | Readable | Writable | Type | Mandatory| Description | | Name | Readable | Writable | Type | Mandatory| Description |
| ----------- | -------- |-------- | -------------------- | ---- | ------------------------------------------------------------ | | ----------- | -------- |-------- | -------------------- | ---- | ------------------------------------------------------------ |
| resultCode | Yes | Yes | number | Yes | Result code returned after the started ability is terminated. | | resultCode | Yes | No | number | No | Result code returned when the ability is started or terminated. |
| want | Yes | Yes | [Want](./js-apis-app-ability-want.md) | No | Data returned after the started ability is terminated. | | want | Yes | No | [Want](./js-apis-app-ability-want.md) | No | Data returned when the ability is terminated.|
...@@ -2,6 +2,16 @@ ...@@ -2,6 +2,16 @@
**ConnectOptions** can be used as an input parameter to receive status changes during the connection to a background service. For example, it is used as an input parameter of [connectServiceExtensionAbility](js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextconnectserviceextensionability) to connect to a ServiceExtensionAbility. **ConnectOptions** can be used as an input parameter to receive status changes during the connection to a background service. For example, it is used as an input parameter of [connectServiceExtensionAbility](js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextconnectserviceextensionability) to connect to a ServiceExtensionAbility.
> **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.
## Modules to Import
```ts
import common from '@ohos.app.ability.common';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -18,7 +28,7 @@ ...@@ -18,7 +28,7 @@
abilityName: 'MyAbility' abilityName: 'MyAbility'
}; };
let connectOptions = { let connectOptions: common.ConnectOptions = {
onConnect(elementName, remote) { onConnect(elementName, remote) {
console.log('onConnect elementName: ' + elementName); console.log('onConnect elementName: ' + elementName);
}, },
......
...@@ -7,6 +7,12 @@ The **DataAbilityHelper** object is obtained through [acquireDataAbilityHelper]( ...@@ -7,6 +7,12 @@ The **DataAbilityHelper** object is obtained through [acquireDataAbilityHelper](
> 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 model. > The APIs of this module can be used only in the FA model.
## Modules to Import
```ts
import ability from '@ohos.ability.ability';
```
## Usage ## Usage
Import the following modules based on the actual situation before using the current module: Import the following modules based on the actual situation before using the current module:
...@@ -19,7 +25,7 @@ import ohos_data_rdb from '@ohos.data.rdb'; ...@@ -19,7 +25,7 @@ import ohos_data_rdb from '@ohos.data.rdb';
openFile(uri: string, mode: string, callback: AsyncCallback\<number>): void openFile(uri: string, mode: string, callback: AsyncCallback\<number>): void
Opens a file with a specified URI. This API uses an asynchronous callback to return a file descriptor. Opens a file with a specified URI. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -28,14 +34,14 @@ Opens a file with a specified URI. This API uses an asynchronous callback to ret ...@@ -28,14 +34,14 @@ Opens a file with a specified URI. This API uses an asynchronous callback to ret
| 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 **r** indicates read-only access, **w** indicates **write-only** access, and **rw** indicates read-write access. | | 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**
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
let mode = 'rwt'; let mode = 'rwt';
...@@ -48,7 +54,7 @@ DAHelper.openFile('dataability:///com.example.DataAbility', mode, (err) => { ...@@ -48,7 +54,7 @@ DAHelper.openFile('dataability:///com.example.DataAbility', mode, (err) => {
openFile(uri: string, mode: string): Promise\<number> openFile(uri: string, mode: string): Promise\<number>
Opens a file with a specified URI. This API uses a promise to return a file descriptor. Opens a file with a specified URI. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -57,7 +63,7 @@ Opens a file with a specified URI. This API uses a promise to return a file desc ...@@ -57,7 +63,7 @@ Opens a file with a specified URI. This API uses a promise to return a file desc
| 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 **r** indicates read-only access, **w** indicates **write-only** access, and **rw** indicates read-write access. | | mode | string | Yes | Mode for opening the file. The value can be **rwt**. |
**Return value** **Return value**
...@@ -69,7 +75,7 @@ Opens a file with a specified URI. This API uses a promise to return a file desc ...@@ -69,7 +75,7 @@ Opens a file with a specified URI. This API uses a promise to return a file desc
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
let mode = 'rwt'; let mode = 'rwt';
...@@ -90,7 +96,7 @@ Registers an observer to listen for changes in the data specified by a given URI ...@@ -90,7 +96,7 @@ Registers an observer to listen for changes in the data specified by a given URI
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | ------------------------ |
| type | string | Yes | The value **dataChange** means data changes. | | type | string | Yes | Event type. The value is **dataChange**. |
| uri | string | Yes | URI of the data.| | uri | string | Yes | URI of the data.|
| callback | AsyncCallback\<void> | Yes | Callback invoked when the data is changed. | | callback | AsyncCallback\<void> | Yes | Callback invoked when the data is changed. |
...@@ -98,13 +104,13 @@ Registers an observer to listen for changes in the data specified by a given URI ...@@ -98,13 +104,13 @@ Registers an observer to listen for changes in the data specified by a given URI
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let helper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
function onChangeNotify() { function onChangeNotify() {
console.info('==========================>onChangeNotify=======================>'); console.info('==========================>onChangeNotify=======================>');
}; };
helper.on( DAHelper.on(
'dataChange', 'dataChange',
'dataability:///com.example.DataAbility', 'dataability:///com.example.DataAbility',
onChangeNotify onChangeNotify
...@@ -123,25 +129,25 @@ Deregisters the observer that listens for changes in the data specified by a giv ...@@ -123,25 +129,25 @@ Deregisters the observer that listens for changes in the data specified by a giv
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | ------------------------ |
| type | string | Yes | The value **dataChange** means data changes. | | type | string | Yes | Event type. The value is **dataChange**. |
| uri | string | Yes | URI of the data.| | uri | string | Yes | URI of the data.|
| callback | AsyncCallback\<void> | No | Callback of the listener to deregister. If the callback is set to **null**, all data change listeners are canceled. | | callback | AsyncCallback\<void> | No | Callback used to return the result. |
**Example** **Example**
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let helper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
function onChangeNotify() { function onChangeNotify() {
console.info('==========================>onChangeNotify=======================>'); console.info('==========================>onChangeNotify=======================>');
}; };
helper.off( DAHelper.off(
'dataChange', 'dataChange',
'dataability:///com.example.DataAbility', 'dataability:///com.example.DataAbility',
); );
helper.off( DAHelper.off(
'dataChange', 'dataChange',
'dataability:///com.example.DataAbility', 'dataability:///com.example.DataAbility',
onChangeNotify onChangeNotify
...@@ -152,7 +158,7 @@ helper.off( ...@@ -152,7 +158,7 @@ helper.off(
getType(uri: string, callback: AsyncCallback\<string>): void getType(uri: string, callback: AsyncCallback\<string>): void
Obtains the media resource type of the data specified by a given URI. This API uses an asynchronous callback to return the result. Obtains the MIME type of the data specified by a given URI. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -161,13 +167,13 @@ Obtains the media resource type of the data specified by a given URI. This API u ...@@ -161,13 +167,13 @@ Obtains the media resource type of the data specified by a given URI. This API u
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | --------------------------------------------- | | -------- | ---------------------- | ---- | --------------------------------------------- |
| uri | string | Yes | URI of the data. | | uri | string | Yes | URI of the data. |
| callback | AsyncCallback\<string> | Yes | Callback used to return the media resource type.| | callback | AsyncCallback\<string> | Yes | Callback used to return the MIME type.|
**Example** **Example**
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
DAHelper.getType('dataability:///com.example.DataAbility', (err, data) => { DAHelper.getType('dataability:///com.example.DataAbility', (err, data) => {
...@@ -179,7 +185,7 @@ DAHelper.getType('dataability:///com.example.DataAbility', (err, data) => { ...@@ -179,7 +185,7 @@ DAHelper.getType('dataability:///com.example.DataAbility', (err, data) => {
getType(uri: string): Promise\<string> getType(uri: string): Promise\<string>
Obtains the media resource type of the data specified by a given URI. This API uses a promise to return the result. Obtains the MIME type of the data specified by a given URI. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -193,13 +199,13 @@ Obtains the media resource type of the data specified by a given URI. This API u ...@@ -193,13 +199,13 @@ Obtains the media resource type of the data specified by a given URI. This API u
| Type | Description | | Type | Description |
| ---------------- | ----------------------------------- | | ---------------- | ----------------------------------- |
| Promise\<string> | Promise used to return the media resource type.| | Promise\<string> | Promise used to return the MIME type.|
**Example** **Example**
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
DAHelper.getType('dataability:///com.example.DataAbility').then((data) => { DAHelper.getType('dataability:///com.example.DataAbility').then((data) => {
...@@ -211,7 +217,7 @@ DAHelper.getType('dataability:///com.example.DataAbility').then((data) => { ...@@ -211,7 +217,7 @@ DAHelper.getType('dataability:///com.example.DataAbility').then((data) => {
getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array\<string>>): void getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array\<string>>): void
Obtains the supported media resource types of a specified file. This API uses an asynchronous callback to return the result. Obtains the supported MIME types of a specified file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -220,14 +226,14 @@ Obtains the supported media resource types of a specified file. This API uses an ...@@ -220,14 +226,14 @@ Obtains the supported media resource types of a specified file. This API uses an
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------------- | ------------------------------ | ---- | ---------------------------------- | | -------------- | ------------------------------ | ---- | ---------------------------------- |
| uri | string | Yes | URI of the file. | | uri | string | Yes | URI of the file. |
| mimeTypeFilter | string | Yes | Media resource type of the file to obtain. | | mimeTypeFilter | string | Yes | MIME types to match. |
| callback | AsyncCallback\<Array\<string>> | Yes | Callback used to return an array holding the media resource type.| | callback | AsyncCallback\<Array\<string>> | Yes | Callback used to return the supported MIME types.|
**Example** **Example**
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
DAHelper.getFileTypes( 'dataability:///com.example.DataAbility', DAHelper.getFileTypes( 'dataability:///com.example.DataAbility',
...@@ -242,7 +248,7 @@ DAHelper.getFileTypes( 'dataability:///com.example.DataAbility', ...@@ -242,7 +248,7 @@ DAHelper.getFileTypes( 'dataability:///com.example.DataAbility',
getFileTypes(uri: string, mimeTypeFilter: string): Promise\<Array\<string>> getFileTypes(uri: string, mimeTypeFilter: string): Promise\<Array\<string>>
Obtains the supported media resource types of a specified file. This API uses a promise to return the result. Obtains the supported MIME types of a specified file. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -251,19 +257,19 @@ Obtains the supported media resource types of a specified file. This API uses a ...@@ -251,19 +257,19 @@ Obtains the supported media resource types of a specified file. This API uses a
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------------- | ------ | ---- | ---------------------------- | | -------------- | ------ | ---- | ---------------------------- |
| uri | string | Yes | URI of the file. | | uri | string | Yes | URI of the file. |
| mimeTypeFilter | string | Yes | Media resource type of the file to obtain.| | mimeTypeFilter | string | Yes | MIME types to match.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------ | ------------------------ | | ------------------------ | ------------------------ |
| Promise\<Array\<string>> | Promise used to return an array holding the media resource type.| | Promise\<Array\<string>> | Promise used to return the supported MIME types.|
**Example** **Example**
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
DAHelper.getFileTypes('dataability:///com.example.DataAbility', DAHelper.getFileTypes('dataability:///com.example.DataAbility',
...@@ -276,7 +282,7 @@ DAHelper.getFileTypes('dataability:///com.example.DataAbility', ...@@ -276,7 +282,7 @@ DAHelper.getFileTypes('dataability:///com.example.DataAbility',
normalizeUri(uri: string, callback: AsyncCallback\<string>): void normalizeUri(uri: string, callback: AsyncCallback\<string>): void
Converts the URI that refers to a Data ability into a normalized URI. This API uses an asynchronous callback to return the result. Converts the URI that refers to a DataAbility into a normalized URI. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -285,13 +291,13 @@ Converts the URI that refers to a Data ability into a normalized URI. This API u ...@@ -285,13 +291,13 @@ Converts the URI that refers to a Data ability into a normalized URI. This API u
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| uri | string | Yes | URI object to normalize. | | uri | string | Yes | URI object to normalize. |
| callback | AsyncCallback\<string> | Yes | Callback used to return the normalized URI object if the Data ability supports URI normalization. If the Data ability does not support URI normalization, **null** is returned.| | callback | AsyncCallback\<string> | Yes | Callback used to return the normalized URI object if the DataAbility supports URI normalization. If the DataAbility does not support URI normalization, **null** is returned.|
**Example** **Example**
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
DAHelper.normalizeUri('dataability:///com.example.DataAbility', (err, data) => { DAHelper.normalizeUri('dataability:///com.example.DataAbility', (err, data) => {
...@@ -303,7 +309,7 @@ DAHelper.normalizeUri('dataability:///com.example.DataAbility', (err, data) => { ...@@ -303,7 +309,7 @@ DAHelper.normalizeUri('dataability:///com.example.DataAbility', (err, data) => {
normalizeUri(uri: string): Promise\<string> normalizeUri(uri: string): Promise\<string>
Converts the URI that refers to a Data ability into a normalized URI. This API uses a promise to return the result. Converts the URI that refers to a DataAbility into a normalized URI. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
...@@ -317,13 +323,13 @@ Converts the URI that refers to a Data ability into a normalized URI. This API u ...@@ -317,13 +323,13 @@ Converts the URI that refers to a Data ability into a normalized URI. This API u
| Type | Description | | Type | Description |
| ---------------- | ------------------------------------------------------ | | ---------------- | ------------------------------------------------------ |
| Promise\<string> | Promise used to return the normalized URI object if the Data ability supports URI normalization. If the Data ability does not support URI normalization, **null** is returned.| | Promise\<string> | Promise used to return the normalized URI object if the DataAbility supports URI normalization. If the DataAbility does not support URI normalization, **null** is returned.|
**Example** **Example**
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
DAHelper.normalizeUri('dataability:///com.example.DataAbility',).then((data) => { DAHelper.normalizeUri('dataability:///com.example.DataAbility',).then((data) => {
...@@ -343,14 +349,14 @@ Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: str ...@@ -343,14 +349,14 @@ Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: str
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | --------------------------------------------------- | | -------- | ---------------------- | ---- | --------------------------------------------------- |
| uri | string | Yes | URI object to denormalize. | | uri | string | Yes | URI object to normalize. |
| callback | AsyncCallback\<string> | Yes | Callback used to return the denormalized URI object.| | callback | AsyncCallback\<string> | Yes | Callback used to return the denormalized URI object.|
**Example** **Example**
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
DAHelper.denormalizeUri('dataability:///com.example.DataAbility', (err, data) => { DAHelper.denormalizeUri('dataability:///com.example.DataAbility', (err, data) => {
...@@ -384,7 +390,7 @@ Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: str ...@@ -384,7 +390,7 @@ Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: str
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
DAHelper.denormalizeUri('dataability:///com.example.DataAbility',).then((data) => { DAHelper.denormalizeUri('dataability:///com.example.DataAbility',).then((data) => {
...@@ -404,17 +410,17 @@ Notifies the registered observer of a change to the data specified by the URI. T ...@@ -404,17 +410,17 @@ Notifies the registered observer of a change to the data specified by the URI. T
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | ------------------------ |
| uri | string | Yes | URI of the data that changes.| | uri | string | Yes | URI of the data.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example** **Example**
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let helper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
helper.notifyChange('dataability:///com.example.DataAbility', (err) => { DAHelper.notifyChange('dataability:///com.example.DataAbility', (err) => {
console.info('==========================>Called=======================>'); console.info('==========================>Called=======================>');
}); });
``` ```
...@@ -431,7 +437,7 @@ Notifies the registered observer of a change to the data specified by the URI. T ...@@ -431,7 +437,7 @@ Notifies the registered observer of a change to the data specified by the URI. T
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ------------------------ | | ---- | ------ | ---- | ------------------------ |
| uri | string | Yes | URI of the data that changes.| | uri | string | Yes | URI of the data.|
**Return value** **Return value**
...@@ -443,7 +449,7 @@ Notifies the registered observer of a change to the data specified by the URI. T ...@@ -443,7 +449,7 @@ Notifies the registered observer of a change to the data specified by the URI. T
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
DAHelper.notifyChange('dataability:///com.example.DataAbility').then(() => { DAHelper.notifyChange('dataability:///com.example.DataAbility').then(() => {
...@@ -471,7 +477,7 @@ Inserts a single data record into the database. This API uses an asynchronous ca ...@@ -471,7 +477,7 @@ Inserts a single data record into the database. This API uses an asynchronous ca
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
const valueBucket = { const valueBucket = {
...@@ -511,7 +517,7 @@ Inserts a single data record into the database. This API uses a promise to retur ...@@ -511,7 +517,7 @@ Inserts a single data record into the database. This API uses a promise to retur
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
const valueBucket = { const valueBucket = {
...@@ -538,14 +544,14 @@ Inserts multiple data records into the database. This API uses an asynchronous c ...@@ -538,14 +544,14 @@ Inserts multiple data records into the database. This API uses an asynchronous c
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------------ | ----------------------- | ---- | -------------------------------- | | ------------ | ----------------------- | ---- | -------------------------------- |
| uri | string | Yes | URI of the data to insert. | | uri | string | Yes | URI of the data to insert. |
| valuesBucket | Array\<rdb.ValuesBucket> | Yes | Data records to insert. | | valuesBucket | Array\<rdb.ValuesBucket> | Yes | Data record to insert. |
| callback | AsyncCallback\<number> | Yes | Callback used to return the number of inserted data records.| | callback | AsyncCallback\<number> | Yes | Callback used to return the number of inserted data records.|
**Example** **Example**
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
let cars = new Array({'name': 'roe11', 'age': 21, 'salary': 20.5, 'blobType': 'u8',}, let cars = new Array({'name': 'roe11', 'age': 21, 'salary': 20.5, 'blobType': 'u8',},
...@@ -570,7 +576,7 @@ Inserts multiple data records into the database. This API uses a promise to retu ...@@ -570,7 +576,7 @@ Inserts multiple data records into the database. This API uses a promise to retu
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------------ | ----------------------- | ---- | ------------------------ | | ------------ | ----------------------- | ---- | ------------------------ |
| uri | string | Yes | URI of the data to insert.| | uri | string | Yes | URI of the data to insert.|
| valuesBucket | Array<rdb.ValuesBucket> | Yes | Data records to insert. | | valuesBucket | Array<rdb.ValuesBucket> | Yes | Data record to insert. |
**Return value** **Return value**
...@@ -582,7 +588,7 @@ Inserts multiple data records into the database. This API uses a promise to retu ...@@ -582,7 +588,7 @@ Inserts multiple data records into the database. This API uses a promise to retu
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
let cars = new Array({'name': 'roe11', 'age': 21, 'salary': 20.5, 'blobType': 'u8',}, let cars = new Array({'name': 'roe11', 'age': 21, 'salary': 20.5, 'blobType': 'u8',},
...@@ -614,7 +620,7 @@ Deletes one or more data records from the database. This API uses an asynchronou ...@@ -614,7 +620,7 @@ Deletes one or more data records from the database. This API uses an asynchronou
```ts ```ts
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';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
let da = new ohos_data_ability.DataAbilityPredicates(); let da = new ohos_data_ability.DataAbilityPredicates();
...@@ -650,7 +656,7 @@ Deletes one or more data records from the database. This API uses a promise to r ...@@ -650,7 +656,7 @@ Deletes one or more data records from the database. This API uses a promise to r
```ts ```ts
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';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
let da = new ohos_data_ability.DataAbilityPredicates(); let da = new ohos_data_ability.DataAbilityPredicates();
...@@ -681,7 +687,7 @@ Updates data records in the database. This API uses an asynchronous callback to ...@@ -681,7 +687,7 @@ Updates data records in the database. This API uses an asynchronous callback to
```ts ```ts
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';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
const va = { const va = {
...@@ -723,7 +729,7 @@ Updates data records in the database. This API uses a promise to return the resu ...@@ -723,7 +729,7 @@ Updates data records in the database. This API uses a promise to return the resu
```ts ```ts
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';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
const va = { const va = {
...@@ -760,7 +766,7 @@ Queries data in the database. This API uses an asynchronous callback to return t ...@@ -760,7 +766,7 @@ Queries data in the database. This API uses an asynchronous callback to return t
```ts ```ts
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';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
let cars=new Array('value1', 'value2', 'value3', 'value4'); let cars=new Array('value1', 'value2', 'value3', 'value4');
...@@ -799,13 +805,49 @@ Queries data in the database. This API uses a promise to return the result. ...@@ -799,13 +805,49 @@ Queries data in the database. This API uses a promise to return the result.
```ts ```ts
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';
let DAHelper = featureAbility.acquireDataAbilityHelper( let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.DataAbility' 'dataability:///com.example.DataAbility'
); );
let cars = new Array('value1', 'value2', 'value3', 'value4'); let cars = new Array('value1', 'value2', 'value3', 'value4');
let da = new ohos_data_ability.DataAbilityPredicates(); let da = new ohos_data_ability.DataAbilityPredicates();
DAHelper.query('dataability:///com.example.DataAbility', cars, da).then((data) => { DAHelper.query('dataability:///com.example.DataAbility', cars, da).then((data) => {
console.info('==========================>queryCallback=======================>'); console.info('query data: ${JSON.stringify(data)}');
});
```
## DataAbilityHelper.call
call(uri: string, method: string, arg: string, extras: PacMap, callback: AsyncCallback\<PacMap>): void
Calls an extended API of the DataAbility. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------- | ---- | ------------------------------------------------ |
| uri | string | Yes | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'. |
| method | string | Yes | Name of the API to call. |
| arg | string | Yes | Parameter to pass in. |
| extras | [PacMap](#pacmap) | Yes | Key-value pair parameter. |
| callback | AsyncCallback\<[PacMap](#pacmap)> | Yes| Callback used to return the result. |
**Example**
```ts
import featureAbility from '@ohos.ability.featureAbility';
let dataAbilityHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.jsapidemo.UserDataAbility'
);
dataAbilityHelper.call('dataability:///com.example.jsapidemo.UserDataAbility',
'method', 'arg', {'key1':'value1'}, (error, data) => {
if (error && error.code !== 0) {
console.error('call fail, error: ${JSON.stringify(error)}');
} else {
console.log('call success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -823,7 +865,7 @@ Calls an extended API of the DataAbility. This API uses a promise to return the ...@@ -823,7 +865,7 @@ Calls an extended API of the DataAbility. This API uses a promise to return the
| ---------- | --------------------------------- | ---- | ------------------------------------------------ | | ---------- | --------------------------------- | ---- | ------------------------------------------------ |
| uri | string | Yes | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'. | | uri | string | Yes | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'. |
| method | string | Yes | Name of the API to call. | | method | string | Yes | Name of the API to call. |
| arg | string | Yes | Parameter to pass in. | | arg | string | Yes |Parameter to pass in. |
| extras | [PacMap](#pacmap) | Yes | Key-value pair parameter. | | extras | [PacMap](#pacmap) | Yes | Key-value pair parameter. |
**Return value** **Return value**
...@@ -837,8 +879,9 @@ Calls an extended API of the DataAbility. This API uses a promise to return the ...@@ -837,8 +879,9 @@ Calls an extended API of the DataAbility. This API uses a promise to return the
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper( let dataAbilityHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.jsapidemo.UserDataAbility'); 'dataability:///com.example.jsapidemo.UserDataAbility'
);
dataAbilityHelper.call('dataability:///com.example.jsapidemo.UserDataAbility', dataAbilityHelper.call('dataability:///com.example.jsapidemo.UserDataAbility',
'method', 'arg', {'key1':'value1'}).then((data) => { 'method', 'arg', {'key1':'value1'}).then((data) => {
console.info('Operation succeeded: ' + data); console.info('Operation succeeded: ' + data);
...@@ -861,9 +904,9 @@ Calls an extended API of the DataAbility. This API uses an asynchronous callback ...@@ -861,9 +904,9 @@ Calls an extended API of the DataAbility. This API uses an asynchronous callback
| ---------- | --------------------------------- | ---- | ------------------------------------------------ | | ---------- | --------------------------------- | ---- | ------------------------------------------------ |
| uri | string | Yes | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'. | | uri | string | Yes | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'. |
| method | string | Yes | Name of the API to call. | | method | string | Yes | Name of the API to call. |
| arg | string | Yes | Parameter to pass in. | | arg | string | Yes |Parameter to pass in. |
| extras | [PacMap](#pacmap) | Yes | Key-value pair parameter. | | extras | [PacMap](#pacmap) | Yes | Key-value pair parameter. |
| callback | AsyncCallback\<[PacMap](#pacmap)> | Yes | Callback used to return the result. | | callback | AsyncCallback\<[PacMap](#pacmap)> | Yes| Callback used to return the result. |
**Example** **Example**
...@@ -892,10 +935,10 @@ Operates data in the database in batches. This API uses an asynchronous callback ...@@ -892,10 +935,10 @@ Operates data in the database in batches. This API uses an asynchronous callback
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------| ---------------------------------| ---- | ------------------------------------------------ | | ---------- | --------------------------------- | ---- | ------------------------------------------------ |
| uri | string | Yes | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'.| | uri | string | Yes | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'.|
| operations | Array\<[DataAbilityOperation](js-apis-inner-ability-dataAbilityOperation.md)> | Yes | An array holding the data operations on the database. | | operations | Array\<[DataAbilityOperation](js-apis-inner-ability-dataAbilityOperation.md)> | Yes | An array holding the data operations on the database. |
| callback | AsyncCallback\<Array\<[DataAbilityResult](js-apis-inner-ability-dataAbilityResult.md)>> | Yes | Callback used to return the result of each operation in the **DataAbilityResult** array. | | callback | AsyncCallback\<Array\<[DataAbilityResult](js-apis-inner-ability-dataAbilityResult.md)>> | Yes | Callback used to return the result of each operation in the **DataAbilityResult** array. |
**Example** **Example**
...@@ -905,13 +948,14 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -905,13 +948,14 @@ import featureAbility from '@ohos.ability.featureAbility';
// Select the operations to be performed on the database according to the DataAbilityOperation array. // Select the operations to be performed on the database according to the DataAbilityOperation array.
let op=new Array(); let op=new Array();
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper( let dataAbilityHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.jsapidemo.UserDataAbility'); 'dataability:///com.example.jsapidemo.UserDataAbility'
dataAbilityHelper.executeBatch('dataability:///com.example.jsapidemo.UserDataAbility', );
op, (err, data) => { dataAbilityHelper.executeBatch('dataability:///com.example.jsapidemo.UserDataAbility', op, (error, data) => {
if (err) { if (error && error.code !== 0) {
console.error('Operation failed. Cause: ' + err); console.error('executeBatch fail, error: ${JSON.stringify(error)}');
return; } else {
console.log('executeBatch success, data: ${JSON.stringify(data)}');
} }
console.info('Operation succeeded: ' + data); console.info('Operation succeeded: ' + data);
}); });
...@@ -945,11 +989,11 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -945,11 +989,11 @@ import featureAbility from '@ohos.ability.featureAbility';
// Select the operations to be performed on the database according to the DataAbilityOperation array. // Select the operations to be performed on the database according to the DataAbilityOperation array.
let op=new Array(); let op=new Array();
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper( let dataAbilityHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
'dataability:///com.example.jsapidemo.UserDataAbility'); 'dataability:///com.example.jsapidemo.UserDataAbility'
dataAbilityHelper.executeBatch('dataability:///com.example.jsapidemo.UserDataAbility', );
op).then((data) => { dataAbilityHelper.executeBatch('dataability:///com.example.jsapidemo.UserDataAbility', op).then((data) => {
console.info('Operation succeeded: ' + data); console.info('executeBatch success, data: ${data}');
}).catch((error) => { }).catch((error) => {
console.error('Operation failed. Cause: ' + error); console.error('Operation failed. Cause: ' + error);
}); });
......
...@@ -7,11 +7,17 @@ The **DataAbilityOperation** module defines the operation on DataAbilities. It c ...@@ -7,11 +7,17 @@ The **DataAbilityOperation** module defines the operation on DataAbilities. It c
> 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 model. > The APIs of this module can be used only in the FA model.
## Modules to Import
```ts
import ability from '@ohos.ability.ability';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
| Name | Template | Mandatory| Description | | Name | Template | Mandatory| Description |
| -------- | -------- | --------| -------- | | -------- | -------- | --------| -------- |
| uri | string | Yes | URI of the DataAbility. Example: "dataability:///com.example.xxx.xxxx". | | uri | string | Yes | URI of the DataAbility. Example: dataability:///com.example.xxx.xxxx. |
| type | featureAbility.DataAbilityOperationType | Yes | Operation type. | | type | featureAbility.DataAbilityOperationType | Yes | Operation type. |
| valuesBucket? | rdb.ValuesBucket | No | Data value to set. | | valuesBucket? | rdb.ValuesBucket | No | Data value to set. |
| valueBackReferences? | rdb.ValuesBucket | No | **ValuesBucket** object that contains a set of key-value pairs. | | valueBackReferences? | rdb.ValuesBucket | No | **ValuesBucket** object that contains a set of key-value pairs. |
......
...@@ -7,6 +7,12 @@ The **DataAbilityResult** module defines the operation result on DataAbilities. ...@@ -7,6 +7,12 @@ The **DataAbilityResult** module defines the operation result on DataAbilities.
> 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 model. > The APIs of this module can be used only in the FA model.
## Modules to Import
```ts
import ability from '@ohos.ability.ability';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -19,54 +25,57 @@ The **DataAbilityResult** module defines the operation result on DataAbilities. ...@@ -19,54 +25,57 @@ The **DataAbilityResult** module defines the operation result on DataAbilities.
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let dataAbilityUri = ('dataability:///com.example.myapplication.TestDataAbility'); // Perform database operations in batches.
let DAHelper; function executeBatchOperation() {
try { let dataAbilityUri = ('dataability:///com.example.myapplication.TestDataAbility');
DAHelper = featureAbility.acquireDataAbilityHelper(dataAbilityUri); let DAHelper: ability.DataAbilityHelper;
if (DAHelper == null) { try {
console.error('DAHelper is null'); DAHelper = featureAbility.acquireDataAbilityHelper(dataAbilityUri);
if (DAHelper === null) {
console.error('DAHelper is null');
}
} catch (err) {
console.error('acquireDataAbilityHelper fail, error: ${JSON.stringify(err)}');
} }
} catch (err) {
console.error('acquireDataAbilityHelper fail, error:' + JSON.stringify(err));
}
let valueBucket = { let valueBucket = {
'name': 'DataAbilityHelperTest', 'name': 'DataAbilityHelperTest',
'age': 24, 'age': 24,
'salary': 2024.20, 'salary': 2024.20,
}; };
let operations = [ let operations = [
{ {
uri: dataAbilityUri, uri: dataAbilityUri,
type: featureAbility.DataAbilityOperationType.TYPE_INSERT, type: featureAbility.DataAbilityOperationType.TYPE_INSERT,
valuesBucket: valueBucket, valuesBucket: valueBucket,
predicates: null, predicates: null,
expectedCount: 1, expectedCount: 1,
PredicatesBackReferences: {}, PredicatesBackReferences: {},
interrupted: true, interrupted: true,
}, },
{ {
uri: dataAbilityUri, uri: dataAbilityUri,
type: featureAbility.DataAbilityOperationType.TYPE_INSERT, type: featureAbility.DataAbilityOperationType.TYPE_INSERT,
valuesBucket: valueBucket, valuesBucket: valueBucket,
predicates: null, predicates: null,
expectedCount: 1, expectedCount: 1,
PredicatesBackReferences: {}, PredicatesBackReferences: {},
interrupted: true, interrupted: true,
} }
]; ];
try { try {
let promise = DAHelper.executeBatch(dataAbilityUri, operations).then((data) => { DAHelper.executeBatch(dataAbilityUri, operations).then((data) => {
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
let dataAbilityResult = data[i]; let dataAbilityResult: ability.DataAbilityResult = data[i];
console.log('dataAbilityResult.uri: ' + dataAbilityResult.uri); console.log('dataAbilityResult.uri: ${dataAbilityResult.uri}');
console.log('dataAbilityResult.count: ' + dataAbilityResult.count); console.log('dataAbilityResult.count: ${dataAbilityResult.count}');
} }
}).catch(err => { }).catch(err => {
console.error('executeBatch error: ' + JSON.stringify(err)); console.error('executeBatch error: ${JSON.stringify(err)}');
}); });
} catch (err) { } catch (err) {
console.error('executeBatch error: ' + JSON.stringify(err)); console.error('executeBatch error: ${JSON.stringify(err)}');
}
} }
``` ```
...@@ -7,6 +7,12 @@ The **StartAbilityParameter** module defines the parameters for starting an abil ...@@ -7,6 +7,12 @@ The **StartAbilityParameter** module defines the parameters for starting an abil
> 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. > The APIs of this module can be used only in the FA model.
## Modules to Import
```ts
import ability from '@ohos.ability.ability';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -30,7 +36,7 @@ let abilityStartSetting ={ ...@@ -30,7 +36,7 @@ let abilityStartSetting ={
[featureAbility.AbilityStartSetting.DISPLAY_ID_KEY] : 1, [featureAbility.AbilityStartSetting.DISPLAY_ID_KEY] : 1,
}; };
let startAbilityParameter = { let startAbilityParameter: ability.StartAbilityParameter = {
want : Want, want : Want,
abilityStartSetting : abilityStartSetting abilityStartSetting : abilityStartSetting
}; };
......
...@@ -6,19 +6,25 @@ Want is a carrier for information transfer between objects (application componen ...@@ -6,19 +6,25 @@ Want is a carrier for information transfer between objects (application componen
> >
> The APIs of this module are supported since API version 6 and deprecated since API version 9. You are advised to use [@ohos.app.ability.Want](js-apis-app-ability-want.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The APIs of this module are supported since API version 6 and deprecated since API version 9. You are advised to use [@ohos.app.ability.Want](js-apis-app-ability-want.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
import Want from '@ohos.app.ability.Want';
```
**System capability**: SystemCapability.Ability.AbilityBase **System capability**: SystemCapability.Ability.AbilityBase
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------- | -------------------- | ---- | ------------------------------------------------------------ | | ----------- | -------------------- | ---- | ------------------------------------------------------------ |
| deviceId | string | No | ID of the device running the ability. | | deviceId | string | No | ID of the device running the ability. |
| bundleName | string | No | Bundle name. If both **bundleName** and **abilityName** are specified in a **Want**, the **Want** can directly match the specified ability.| | bundleName | string | No | Bundle name.|
| abilityName | string | No | Name of the ability. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can match a specific ability. The value of **abilityName** must be unique in an application.| | abilityName | string | No | Name of the ability. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can match a specific ability. The value of **abilityName** must be unique in an application.|
| uri | string | No | URI. If **uri** is specified in a **Want** object, the **Want** object will match the specified URI information, including **scheme**, **schemeSpecificPart**, **authority**, and **path**.| | uri | string | No | URI. If **uri** is specified in a **Want** object, the **Want** object will match the specified URI information, including **scheme**, **schemeSpecificPart**, **authority**, and **path**.|
| type | string | No | MIME type, that is, the type of the file to open, for example, **'text/xml'** and **'image/*'**. For details about the MIME type definition, see https://www.iana.org/assignments/media-types/media-types.xhtml?utm_source=ld246.com. | | type | string | No | MIME type, that is, the type of the file to open, for example, **'text/xml'** and **'image/*'**. For details about the MIME type definition, see https://www.iana.org/assignments/media-types/media-types.xhtml?utm_source=ld246.com. |
| flags | number | No | How the **Want** object will be handled. By default, numbers are passed in. For details, see [flags](js-apis-ability-wantConstant.md#wantconstantflags).| | flags | number | No | How the **Want** object will be handled. By default, numbers are passed in. For details, see [flags](js-apis-app-ability-wantConstant.md#wantconstantflags).|
| action | string | No | Action to take, such as viewing and sharing application details. In implicit Want, you can define this field and use it together with **uri** or **parameters** to specify the operation to be performed on the data. | | action | string | No | Action to take, such as viewing and sharing application details. In implicit Want, you can define this field and use it together with **uri** or **parameters** to specify the operation to be performed on the data. |
| parameters | {[key: string]: Object} | No | Want parameters in the form of custom key-value (KV) pairs. By default, the following keys are carried:<br>- **ohos.aafwk.callerPid**: PID of the caller.<br>- **ohos.aafwk.param.callerToken**: token of the caller.<br>- **ohos.aafwk.param.callerUid**: UID in [bundleInfo](js-apis-bundle-BundleInfo.md#bundleinfo-1), that is, the application UID in the bundle information.<br>- **component.startup.newRules**: whether to enable the new control rule.<br>- **moduleName**: module name of the caller. No matter what this field is set to, the correct module name will be sent to the peer.<br>- **ohos.dlp.params.sandbox**: available only for DLP files. | | parameters | {[key: string]: Object} | No | Want parameters in the form of custom key-value (KV) pairs. By default, the following keys are carried:<br>- **ohos.aafwk.callerPid**: PID of the caller.<br>- **ohos.aafwk.param.callerToken**: token of the caller.<br>- **ohos.aafwk.param.callerUid**: UID in [bundleInfo](js-apis-bundle-BundleInfo.md#bundleinfo-1), that is, the application UID in the bundle information.<br>- **component.startup.newRules**: whether to enable the new control rule.<br>- **moduleName**: module name of the caller. No matter what this field is set to, the correct module name will be sent to the peer.<br>- **ohos.dlp.params.sandbox**: available only for DLP files. |
| entities | Array\<string> | No | Additional category information (such as browser and video player) of the target ability. It is a supplement to **action** in implicit Want and is used to filter ability types. | | entities | Array\<string> | No | Additional category information (such as browser and video player) of the target ability. It is a supplement to **action** in implicit Want and is used to filter ability types. |
| moduleName<sup>9+</sup> | string | No | Module to which the ability belongs.| | moduleName<sup>9+</sup> | string | No | Module to which the ability belongs.|
**Example** **Example**
......
...@@ -6,6 +6,12 @@ The **AppVersionInfo** module defines the application version information. You c ...@@ -6,6 +6,12 @@ The **AppVersionInfo** module defines the application version information. You c
> >
> 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
```ts
import featureAbility from '@ohos.ability.featureAbility';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
......
...@@ -5,16 +5,21 @@ The **Context** module provides context for abilities or applications. It allows ...@@ -5,16 +5,21 @@ The **Context** module provides context for abilities or applications. It allows
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs of this module can be used only in the FA model. > The APIs of this module can be used only in the FA model.
## Modules to Import
```ts
import featureAbility from '@ohos.ability.featureAbility';
```
## Usage ## Usage
The **Context** object is created in a **featureAbility** and returned through its [getContext](js-apis-ability-featureAbility.md#featureabilitygetcontext) API. Therefore, you must import the **@ohos.ability.featureAbility** package before using the **Context** module. An example is as follows: The **Context** object is created in a **featureAbility** and returned through its [getContext](js-apis-ability-featureAbility.md#featureabilitygetcontext) API. Therefore, you must import the **@ohos.ability.featureAbility** package before using the **Context** module. An example is as follows:
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getOrCreateLocalDir().then((data) => { context.getOrCreateLocalDir().then((data) => {
console.info('getOrCreateLocalDir data: ' + JSON.stringify(data)); console.info('getOrCreateLocalDir data: ' + JSON.stringify(data));
}); });
...@@ -40,9 +45,13 @@ If this API is called for the first time, a root directory will be created. ...@@ -40,9 +45,13 @@ If this API is called for the first time, a root directory will be created.
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getOrCreateLocalDir((err, data)=>{ context.getOrCreateLocalDir((error, data)=>{
console.info('getOrCreateLocalDir err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('getOrCreateLocalDir fail, error: ${JSON.stringify(error)}');
} else {
console.log('getOrCreateLocalDir success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -68,7 +77,7 @@ If this API is called for the first time, a root directory will be created. ...@@ -68,7 +77,7 @@ If this API is called for the first time, a root directory will be created.
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getOrCreateLocalDir().then((data) => { context.getOrCreateLocalDir().then((data) => {
console.info('getOrCreateLocalDir data: ' + JSON.stringify(data)); console.info('getOrCreateLocalDir data: ' + JSON.stringify(data));
}); });
...@@ -94,10 +103,10 @@ Verifies whether a specific PID and UID have the given permission. This API uses ...@@ -94,10 +103,10 @@ Verifies whether a specific PID and UID have the given permission. This API uses
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
import bundle from '@ohos.bundle'; import bundle from '@ohos.bundle.bundleManager';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
bundle.getBundleInfo('com.context.test', 1, (err, datainfo) =>{ bundle.getBundleInfo('com.context.test', 1, (err, datainfo) =>{
context.verifyPermission('com.example.permission', {uid:datainfo.uid}, (err, data) =>{ context.verifyPermission('com.example.permission', {uid:datainfo.appInfo.uid}, (err, data) =>{
console.info('verifyPermission err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); console.info('verifyPermission err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data));
}); });
}); });
...@@ -124,9 +133,13 @@ Verifies whether the current PID and UID have the given permission. This API use ...@@ -124,9 +133,13 @@ Verifies whether the current PID and UID have the given permission. This API use
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.verifyPermission('com.example.permission', (err, data) =>{ context.verifyPermission('com.example.permission', (error, data) =>{
console.info('verifyPermission err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('verifyPermission fail, error: ${JSON.stringify(error)}');
} else {
console.log('verifyPermission success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -155,7 +168,7 @@ Verifies whether a specific PID and UID have the given permission. This API uses ...@@ -155,7 +168,7 @@ Verifies whether a specific PID and UID have the given permission. This API uses
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
let Permission = {pid:1}; let Permission = {pid:1};
context.verifyPermission('com.context.permission',Permission).then((data) => { context.verifyPermission('com.context.permission',Permission).then((data) => {
console.info('verifyPermission data: ' + JSON.stringify(data)); console.info('verifyPermission data: ' + JSON.stringify(data));
...@@ -184,7 +197,7 @@ Requests certain permissions from the system. This API uses an asynchronous call ...@@ -184,7 +197,7 @@ Requests certain permissions from the system. This API uses an asynchronous call
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.requestPermissionsFromUser( context.requestPermissionsFromUser(
['com.example.permission1', ['com.example.permission1',
'com.example.permission2', 'com.example.permission2',
...@@ -224,7 +237,7 @@ Requests certain permissions from the system. This API uses a promise to return ...@@ -224,7 +237,7 @@ Requests certain permissions from the system. This API uses a promise to return
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.requestPermissionsFromUser( context.requestPermissionsFromUser(
['com.example.permission1', ['com.example.permission1',
'com.example.permission2', 'com.example.permission2',
...@@ -257,9 +270,13 @@ Obtains information about the current application. This API uses an asynchronous ...@@ -257,9 +270,13 @@ Obtains information about the current application. This API uses an asynchronous
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getApplicationInfo((err, data) => { context.getApplicationInfo((error, data) => {
console.info('getApplicationInfo err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('getApplicationInfo fail, error: ${JSON.stringify(error)}');
} else {
console.log('getApplicationInfo success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -283,7 +300,7 @@ Obtains information about the current application. This API uses a promise to re ...@@ -283,7 +300,7 @@ Obtains information about the current application. This API uses a promise to re
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getApplicationInfo().then((data) => { context.getApplicationInfo().then((data) => {
console.info('getApplicationInfo data: ' + JSON.stringify(data)); console.info('getApplicationInfo data: ' + JSON.stringify(data));
}); });
...@@ -309,9 +326,13 @@ Obtains the bundle name of this ability. This API uses an asynchronous callback ...@@ -309,9 +326,13 @@ Obtains the bundle name of this ability. This API uses an asynchronous callback
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getBundleName((err, data) => { context.getBundleName((error, data) => {
console.info('getBundleName err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('getBundleName fail, error: ${JSON.stringify(error)}');
} else {
console.log('getBundleName success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -335,7 +356,7 @@ Obtains the bundle name of this ability. This API uses a promise to return the r ...@@ -335,7 +356,7 @@ Obtains the bundle name of this ability. This API uses a promise to return the r
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getBundleName().then((data) => { context.getBundleName().then((data) => {
console.info('getBundleName data: ' + JSON.stringify(data)); console.info('getBundleName data: ' + JSON.stringify(data));
}); });
...@@ -359,9 +380,13 @@ Obtains the display orientation of this ability. This API uses an asynchronous c ...@@ -359,9 +380,13 @@ Obtains the display orientation of this ability. This API uses an asynchronous c
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getDisplayOrientation((err, data) => { context.getDisplayOrientation((error, data) => {
console.info('getDisplayOrientation err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('getDisplayOrientation fail, error: ${JSON.stringify(error)}');
} else {
console.log('getDisplayOrientation success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -383,7 +408,7 @@ Obtains the display orientation of this ability. This API uses a promise to retu ...@@ -383,7 +408,7 @@ Obtains the display orientation of this ability. This API uses a promise to retu
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getDisplayOrientation().then((data) => { context.getDisplayOrientation().then((data) => {
console.info('getDisplayOrientation data: ' + JSON.stringify(data)); console.info('getDisplayOrientation data: ' + JSON.stringify(data));
}); });
...@@ -407,9 +432,13 @@ Obtains the external cache directory of the application. This API uses an asynch ...@@ -407,9 +432,13 @@ Obtains the external cache directory of the application. This API uses an asynch
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getExternalCacheDir((err, data) => { context.getExternalCacheDir((error, data) => {
console.info('getExternalCacheDir err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('getExternalCacheDir fail, error: ${JSON.stringify(error)}');
} else {
console.log('getExternalCacheDir success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -431,7 +460,7 @@ Obtains the external cache directory of the application. This API uses a promise ...@@ -431,7 +460,7 @@ Obtains the external cache directory of the application. This API uses a promise
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getExternalCacheDir().then((data) => { context.getExternalCacheDir().then((data) => {
console.info('getExternalCacheDir data: ' + JSON.stringify(data)); console.info('getExternalCacheDir data: ' + JSON.stringify(data));
}); });
...@@ -457,10 +486,10 @@ Sets the display orientation for this ability. This API uses an asynchronous cal ...@@ -457,10 +486,10 @@ Sets the display orientation for this ability. This API uses an asynchronous cal
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
import bundle from '@ohos.bundle'; import bundle from '@ohos.bundle';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
let orientation=bundle.DisplayOrientation.UNSPECIFIED let orientation = bundle.DisplayOrientation.UNSPECIFIED;
context.setDisplayOrientation(orientation, (err) => { context.setDisplayOrientation(orientation, (error) => {
console.info('setDisplayOrientation err: ' + JSON.stringify(err)); console.error('setDisplayOrientation fail, error: ${JSON.stringify(error)}');
}); });
``` ```
...@@ -484,18 +513,19 @@ Sets the display orientation for this ability. This API uses a promise to return ...@@ -484,18 +513,19 @@ Sets the display orientation for this ability. This API uses a promise to return
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
import bundle from '@ohos.bundle'; import bundle from '@ohos.bundle';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
let orientation=bundle.DisplayOrientation.UNSPECIFIED let orientation = bundle.DisplayOrientation.UNSPECIFIED;
context.setDisplayOrientation(orientation).then((data) => { context.setDisplayOrientation(orientation).then((data) => {
console.info('setDisplayOrientation data: ' + JSON.stringify(data)); console.info('setDisplayOrientation data: ' + JSON.stringify(data));
}); });
``` ```
## Context.setShowOnLockScreen<sup>7+</sup> ## Context.setShowOnLockScreen<sup>(deprecated)</sup>
setShowOnLockScreen(show: boolean, callback: AsyncCallback\<void>): void setShowOnLockScreen(show: boolean, callback: AsyncCallback\<void>): void
Sets whether to show this feature at the top of the lock screen so that the feature remains activated. This API uses an asynchronous callback to return the result. Sets whether to show this feature at the top of the lock screen so that the feature remains activated. This API uses an asynchronous callback to return the result.
> This API is deprecated since API version 9. You are advised to use [window.setShowOnLockScreen](js-apis-window.md#setShowOnLockScreen9).
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -510,18 +540,19 @@ Sets whether to show this feature at the top of the lock screen so that the feat ...@@ -510,18 +540,19 @@ Sets whether to show this feature at the top of the lock screen so that the feat
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
let show=true let show = true;
context.setShowOnLockScreen(show, (err) => { context.setShowOnLockScreen(show, (error) => {
console.info('setShowOnLockScreen err: ' + JSON.stringify(err)); console.error('setShowOnLockScreen fail, error: ${JSON.stringify(error)}');
}); });
``` ```
## Context.setShowOnLockScreen<sup>7+</sup> ## Context.setShowOnLockScreen<sup>(deprecated)</sup>
setShowOnLockScreen(show: boolean): Promise\<void>; setShowOnLockScreen(show: boolean): Promise\<void>;
Sets whether to show this feature at the top of the lock screen so that the feature remains activated. This API uses a promise to return the result. Sets whether to show this feature at the top of the lock screen so that the feature remains activated. This API uses a promise to return the result.
> This API is deprecated since API version 9. You are advised to use [window.setShowOnLockScreen](js-apis-window.md#setShowOnLockScreen9).
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -541,8 +572,8 @@ Sets whether to show this feature at the top of the lock screen so that the feat ...@@ -541,8 +572,8 @@ Sets whether to show this feature at the top of the lock screen so that the feat
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
let show=true let show = true;
context.setShowOnLockScreen(show).then((data) => { context.setShowOnLockScreen(show).then((data) => {
console.info('setShowOnLockScreen data: ' + JSON.stringify(data)); console.info('setShowOnLockScreen data: ' + JSON.stringify(data));
}); });
...@@ -567,16 +598,16 @@ Sets whether to wake up the screen when this feature is restored. This API uses ...@@ -567,16 +598,16 @@ Sets whether to wake up the screen when this feature is restored. This API uses
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
let wakeUp=true let wakeUp = true;
context.setWakeUpScreen(wakeUp, (err) => { context.setWakeUpScreen(wakeUp, (error) => {
console.info('setWakeUpScreen err: ' + JSON.stringify(err)); console.error('setWakeUpScreen fail, error: ${JSON.stringify(error)}');
}); });
``` ```
## Context.setWakeUpScreen<sup>7+</sup> ## Context.setWakeUpScreen<sup>7+</sup>
setWakeUpScreen(wakeUp: boolean): Promise\<void>; setWakeUpScreen(wakeUp: boolean): Promise\<void>;
Sets whether to wake up the screen when this feature is restored. This API uses a promise to return the result. Sets whether to wake up the screen when this feature is restored. This API uses a promise to return the result.
...@@ -598,8 +629,8 @@ Sets whether to wake up the screen when this feature is restored. This API uses ...@@ -598,8 +629,8 @@ Sets whether to wake up the screen when this feature is restored. This API uses
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
let wakeUp=true let wakeUp = true;
context.setWakeUpScreen(wakeUp).then((data) => { context.setWakeUpScreen(wakeUp).then((data) => {
console.info('setWakeUpScreen data: ' + JSON.stringify(data)); console.info('setWakeUpScreen data: ' + JSON.stringify(data));
}); });
...@@ -626,9 +657,13 @@ Obtains information about the current process, including the PID and process nam ...@@ -626,9 +657,13 @@ Obtains information about the current process, including the PID and process nam
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getProcessInfo((err, data) => { context.getProcessInfo((error, data) => {
console.info('getProcessInfo err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('getProcessInfo fail, error: ${JSON.stringify(error)}');
} else {
console.log('getProcessInfo success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -652,7 +687,7 @@ Obtains information about the current process, including the PID and process nam ...@@ -652,7 +687,7 @@ Obtains information about the current process, including the PID and process nam
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getProcessInfo().then((data) => { context.getProcessInfo().then((data) => {
console.info('getProcessInfo data: ' + JSON.stringify(data)); console.info('getProcessInfo data: ' + JSON.stringify(data));
}); });
...@@ -680,9 +715,13 @@ This API is available only to Page abilities. ...@@ -680,9 +715,13 @@ This API is available only to Page abilities.
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getElementName((err, data) => { context.getElementName((error, data) => {
console.info('getElementName err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('getElementName fail, error: ${JSON.stringify(error)}');
} else {
console.log('getElementName success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -708,7 +747,7 @@ This API is available only to Page abilities. ...@@ -708,7 +747,7 @@ This API is available only to Page abilities.
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getElementName().then((data) => { context.getElementName().then((data) => {
console.info('getElementName data: ' + JSON.stringify(data)); console.info('getElementName data: ' + JSON.stringify(data));
}); });
...@@ -732,9 +771,13 @@ Obtains the name of the current process. This API uses an asynchronous callback ...@@ -732,9 +771,13 @@ Obtains the name of the current process. This API uses an asynchronous callback
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getProcessName((err, data) => { context.getProcessName((error, data) => {
console.info('getProcessName err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('getProcessName fail, error: ${JSON.stringify(error)}');
} else {
console.log('getProcessName success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -758,7 +801,7 @@ Obtains the name of the current process. This API uses a promise to return the r ...@@ -758,7 +801,7 @@ Obtains the name of the current process. This API uses a promise to return the r
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getProcessName().then((data) => { context.getProcessName().then((data) => {
console.info('getProcessName data: ' + JSON.stringify(data)); console.info('getProcessName data: ' + JSON.stringify(data));
}); });
...@@ -770,7 +813,7 @@ context.getProcessName().then((data) => { ...@@ -770,7 +813,7 @@ context.getProcessName().then((data) => {
getCallingBundle(callback: AsyncCallback\<string>): void getCallingBundle(callback: AsyncCallback\<string>): void
Obtains the bundle name of the caller ability. This API uses an asynchronous callback to return the result. Obtains the bundle name of the calling ability. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -784,9 +827,13 @@ Obtains the bundle name of the caller ability. This API uses an asynchronous cal ...@@ -784,9 +827,13 @@ Obtains the bundle name of the caller ability. This API uses an asynchronous cal
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getCallingBundle((err, data) => { context.getCallingBundle((error, data) => {
console.info('getCallingBundle err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('getCallingBundle fail, error: ${JSON.stringify(error)}');
} else {
console.log('getCallingBundle success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -796,7 +843,7 @@ context.getCallingBundle((err, data) => { ...@@ -796,7 +843,7 @@ context.getCallingBundle((err, data) => {
getCallingBundle(): Promise\<string> getCallingBundle(): Promise\<string>
Obtains the bundle name of the caller ability. This API uses a promise to return the result. Obtains the bundle name of the calling ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -810,7 +857,7 @@ Obtains the bundle name of the caller ability. This API uses a promise to return ...@@ -810,7 +857,7 @@ Obtains the bundle name of the caller ability. This API uses a promise to return
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getCallingBundle().then((data) => { context.getCallingBundle().then((data) => {
console.info('getCallingBundle data: ' + JSON.stringify(data)); console.info('getCallingBundle data: ' + JSON.stringify(data));
}); });
...@@ -834,9 +881,13 @@ Obtains the cache directory of the application in the internal storage. This API ...@@ -834,9 +881,13 @@ Obtains the cache directory of the application in the internal storage. This API
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getCacheDir((err, data) => { context.getCacheDir((error, data) => {
console.info('getCacheDir err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('getCacheDir fail, error: ${JSON.stringify(error)}');
} else {
console.log('getCacheDir success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -858,7 +909,7 @@ Obtains the cache directory of the application in the internal storage. This API ...@@ -858,7 +909,7 @@ Obtains the cache directory of the application in the internal storage. This API
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getCacheDir().then((data) => { context.getCacheDir().then((data) => {
console.info('getCacheDir data: ' + JSON.stringify(data)); console.info('getCacheDir data: ' + JSON.stringify(data));
}); });
...@@ -882,9 +933,13 @@ Obtains the file directory of the application in the internal storage. This API ...@@ -882,9 +933,13 @@ Obtains the file directory of the application in the internal storage. This API
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getFilesDir((err, data) => { context.getFilesDir((error, data) => {
console.info('getFilesDir err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('getFilesDir fail, error: ${JSON.stringify(error)}');
} else {
console.log('getFilesDir success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -906,7 +961,7 @@ Obtains the file directory of the application in the internal storage. This API ...@@ -906,7 +961,7 @@ Obtains the file directory of the application in the internal storage. This API
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getFilesDir().then((data) => { context.getFilesDir().then((data) => {
console.info('getFilesDir data: ' + JSON.stringify(data)); console.info('getFilesDir data: ' + JSON.stringify(data));
}); });
...@@ -918,7 +973,7 @@ getOrCreateDistributedDir(callback: AsyncCallback\<string>): void ...@@ -918,7 +973,7 @@ getOrCreateDistributedDir(callback: AsyncCallback\<string>): void
Obtains the distributed file path for storing ability or application data files. This API uses an asynchronous callback to return the result. Obtains the distributed file path for storing ability or application data files. This API uses an asynchronous callback to return the result.
If the distributed file path does not exist, the system will create one and return the created path. If the file path does not exist, the system will create one and return the created path.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -926,15 +981,19 @@ If the distributed file path does not exist, the system will create one and retu ...@@ -926,15 +981,19 @@ If the distributed file path does not exist, the system will create one and retu
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | ---------------------------------------- | | -------- | ---------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the distributed file path.<br>If the path does not exist, the system will create one and return the created path.| | callback | AsyncCallback\<string> | Yes | Callback used to return the distributed file path. If the file path does not exist, the system will create one and return the created path.|
**Example** **Example**
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getOrCreateDistributedDir((err, data) => { context.getOrCreateDistributedDir((error, data) => {
console.info('getOrCreateDistributedDir err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('getOrCreateDistributedDir fail, error: ${JSON.stringify(error)}');
} else {
console.log('getOrCreateDistributedDir success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -958,7 +1017,7 @@ If the distributed file path does not exist, the system will create one and retu ...@@ -958,7 +1017,7 @@ If the distributed file path does not exist, the system will create one and retu
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getOrCreateDistributedDir().then((data) => { context.getOrCreateDistributedDir().then((data) => {
console.info('getOrCreateDistributedDir data: ' + JSON.stringify(data)); console.info('getOrCreateDistributedDir data: ' + JSON.stringify(data));
}); });
...@@ -982,9 +1041,13 @@ Obtains the application type. This API uses an asynchronous callback to return t ...@@ -982,9 +1041,13 @@ Obtains the application type. This API uses an asynchronous callback to return t
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getAppType((err, data) => { context.getAppType((error, data) => {
console.info('getAppType err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('getAppType fail, error: ${JSON.stringify(error)}');
} else {
console.log('getAppType success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -1006,7 +1069,7 @@ Obtains the application type. This API uses a promise to return the result. ...@@ -1006,7 +1069,7 @@ Obtains the application type. This API uses a promise to return the result.
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getAppType().then((data) => { context.getAppType().then((data) => {
console.info('getAppType data: ' + JSON.stringify(data)); console.info('getAppType data: ' + JSON.stringify(data));
}); });
...@@ -1030,9 +1093,13 @@ Obtains the **ModuleInfo** object of the application. This API uses an asynchron ...@@ -1030,9 +1093,13 @@ Obtains the **ModuleInfo** object of the application. This API uses an asynchron
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getHapModuleInfo((err, data) => { context.getHapModuleInfo((error, data) => {
console.info('getHapModuleInfo err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('getHapModuleInfo fail, error: ${JSON.stringify(error)}');
} else {
console.log('getHapModuleInfo success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -1054,7 +1121,7 @@ Obtains the **ModuleInfo** object of the application. This API uses a promise to ...@@ -1054,7 +1121,7 @@ Obtains the **ModuleInfo** object of the application. This API uses a promise to
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getHapModuleInfo().then((data) => { context.getHapModuleInfo().then((data) => {
console.info('getHapModuleInfo data: ' + JSON.stringify(data)); console.info('getHapModuleInfo data: ' + JSON.stringify(data));
}); });
...@@ -1078,9 +1145,13 @@ Obtains the version information of the application. This API uses an asynchronou ...@@ -1078,9 +1145,13 @@ Obtains the version information of the application. This API uses an asynchronou
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getAppVersionInfo((err, data) => { context.getAppVersionInfo((error, data) => {
console.info('getAppVersionInfo err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('getAppVersionInfo fail, error: ${JSON.stringify(error)}');
} else {
console.log('getAppVersionInfo success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -1102,7 +1173,7 @@ Obtains the version information of the application. This API uses a promise to r ...@@ -1102,7 +1173,7 @@ Obtains the version information of the application. This API uses a promise to r
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getAppVersionInfo().then((data) => { context.getAppVersionInfo().then((data) => {
console.info('getAppVersionInfo data: ' + JSON.stringify(data)); console.info('getAppVersionInfo data: ' + JSON.stringify(data));
}); });
...@@ -1126,9 +1197,13 @@ Obtains information about this ability. This API uses an asynchronous callback t ...@@ -1126,9 +1197,13 @@ Obtains information about this ability. This API uses an asynchronous callback t
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getAbilityInfo((err, data) => { context.getAbilityInfo((error, data) => {
console.info('getAbilityInfo err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('getAbilityInfo fail, error: ${JSON.stringify(error)}');
} else {
console.log('getAbilityInfo success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -1150,7 +1225,7 @@ Obtains information about this ability. This API uses a promise to return the re ...@@ -1150,7 +1225,7 @@ Obtains information about this ability. This API uses a promise to return the re
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.getAbilityInfo().then((data) => { context.getAbilityInfo().then((data) => {
console.info('getAbilityInfo data: ' + JSON.stringify(data)); console.info('getAbilityInfo data: ' + JSON.stringify(data));
}); });
...@@ -1174,7 +1249,7 @@ Obtains the context of the application. ...@@ -1174,7 +1249,7 @@ Obtains the context of the application.
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext().getApplicationContext(); let context: featureAbility.Context = featureAbility.getContext().getApplicationContext();
``` ```
## Context.isUpdatingConfigurations<sup>7+</sup> ## Context.isUpdatingConfigurations<sup>7+</sup>
...@@ -1195,9 +1270,13 @@ Checks whether the configuration of this ability is being updated. This API uses ...@@ -1195,9 +1270,13 @@ Checks whether the configuration of this ability is being updated. This API uses
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.isUpdatingConfigurations((err, data) => { context.isUpdatingConfigurations((error, data) => {
console.info('isUpdatingConfigurations err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data)); if (error && error.code !== 0) {
console.error('isUpdatingConfigurations fail, error: ${JSON.stringify(error)}');
} else {
console.log('isUpdatingConfigurations success, data: ${JSON.stringify(data)}');
}
}); });
``` ```
...@@ -1219,7 +1298,7 @@ Checks whether the configuration of this ability is being updated. This API uses ...@@ -1219,7 +1298,7 @@ Checks whether the configuration of this ability is being updated. This API uses
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.isUpdatingConfigurations().then((data) => { context.isUpdatingConfigurations().then((data) => {
console.info('isUpdatingConfigurations data: ' + JSON.stringify(data)); console.info('isUpdatingConfigurations data: ' + JSON.stringify(data));
}); });
...@@ -1243,7 +1322,7 @@ Notifies the system of the time required to draw this page function. This API us ...@@ -1243,7 +1322,7 @@ Notifies the system of the time required to draw this page function. This API us
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.printDrawnCompleted((err) => { context.printDrawnCompleted((err) => {
console.error('printDrawnCompleted err: ' + JSON.stringify(err)); console.error('printDrawnCompleted err: ' + JSON.stringify(err));
}); });
...@@ -1267,7 +1346,7 @@ Notifies the system of the time required to draw this page function. This API us ...@@ -1267,7 +1346,7 @@ Notifies the system of the time required to draw this page function. This API us
```ts ```ts
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context: featureAbility.Context = featureAbility.getContext();
context.printDrawnCompleted().then((data) => { context.printDrawnCompleted().then((data) => {
console.info('printDrawnCompleted data: ' + JSON.stringify(data)); console.info('printDrawnCompleted data: ' + JSON.stringify(data));
}); });
......
...@@ -6,6 +6,12 @@ The **ProcessInfo** module defines process information. You can use [getProcessI ...@@ -6,6 +6,12 @@ The **ProcessInfo** module defines process information. You can use [getProcessI
> >
> 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
```ts
import featureAbility from '@ohos.ability.featureAbility';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
......
...@@ -16,7 +16,7 @@ import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry ...@@ -16,7 +16,7 @@ import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry
An **AbilityDelegator** object is obtained by calling [getAbilityDelegator](js-apis-app-ability-abilityDelegatorRegistry.md#abilitydelegatorregistrygetabilitydelegator) in **AbilityDelegatorRegistry**. An **AbilityDelegator** object is obtained by calling [getAbilityDelegator](js-apis-app-ability-abilityDelegatorRegistry.md#abilitydelegatorregistrygetabilitydelegator) in **AbilityDelegatorRegistry**.
```ts ```ts
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
``` ```
## AbilityDelegator ## AbilityDelegator
...@@ -163,7 +163,7 @@ abilityDelegator.removeAbilityMonitor(monitor, (err : any) => { ...@@ -163,7 +163,7 @@ abilityDelegator.removeAbilityMonitor(monitor, (err : any) => {
removeAbilityMonitor(monitor: AbilityMonitor): Promise\<void>; removeAbilityMonitor(monitor: AbilityMonitor): Promise\<void>;
删除已经添加的AbilityMonitor实例(promise形式) Removes an **AbilityMonitor** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
......
...@@ -6,6 +6,12 @@ The **AbilityDelegatorArgs** module provides a global register to store the regi ...@@ -6,6 +6,12 @@ The **AbilityDelegatorArgs** module provides a global register to store the regi
> >
> 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
```ts
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
```
## Usage ## Usage
An **AbilityDelegatorArgs** object is obtained by calling [getArguments](js-apis-app-ability-abilityDelegatorRegistry.md#abilitydelegatorregistrygetarguments) in **AbilityDelegatorRegistry**. An **AbilityDelegatorArgs** object is obtained by calling [getArguments](js-apis-app-ability-abilityDelegatorRegistry.md#abilitydelegatorregistrygetarguments) in **AbilityDelegatorRegistry**.
...@@ -26,7 +32,5 @@ Describes the ability delegator arguments. ...@@ -26,7 +32,5 @@ Describes the ability delegator arguments.
**Example** **Example**
```ts ```ts
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; let args: AbilityDelegatorRegistry.AbilityDelegatorArgs = AbilityDelegatorRegistry.getArguments();
let args = AbilityDelegatorRegistry.getArguments();
``` ```
...@@ -6,6 +6,12 @@ The **AbilityMonitor** module provides monitors for abilities that meet specifie ...@@ -6,6 +6,12 @@ The **AbilityMonitor** module provides monitors for abilities that meet specifie
> >
> 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.
## Modules to Import
```ts
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
```
## Usage ## Usage
**AbilityMonitor** can be used as an input parameter of [addAbilityMonitor](js-apis-inner-application-abilityDelegator.md#addabilitymonitor9) in **abilityDelegator** to listen for lifecycle changes of an ability. **AbilityMonitor** can be used as an input parameter of [addAbilityMonitor](js-apis-inner-application-abilityDelegator.md#addabilitymonitor9) in **abilityDelegator** to listen for lifecycle changes of an ability.
...@@ -31,8 +37,6 @@ Describes an ability monitor. ...@@ -31,8 +37,6 @@ Describes an ability monitor.
**Example** **Example**
```ts ```ts
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
function onAbilityCreateCallback(data) { function onAbilityCreateCallback(data) {
console.info('onAbilityCreateCallback'); console.info('onAbilityCreateCallback');
} }
...@@ -43,9 +47,11 @@ let monitor = { ...@@ -43,9 +47,11 @@ let monitor = {
onAbilityCreate: onAbilityCreateCallback onAbilityCreate: onAbilityCreateCallback
}; };
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); let abilityDelegator: AbilityDelegatorRegistry.AbilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.addAbilityMonitor(monitor, (err : any) => { abilityDelegator.addAbilityMonitor(monitor, (error : any) => {
console.info('addAbilityMonitor callback'); if (error && error.code !== 0) {
console.error('addAbilityMonitor fail, error: ${JSON.stringify(error)}');
}
}); });
``` ```
......
...@@ -6,6 +6,12 @@ The **AbilityRunningInfo** module defines the running information and state of a ...@@ -6,6 +6,12 @@ The **AbilityRunningInfo** module defines the running information and state of a
> >
> 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
```ts
import abilitymanager from '@ohos.app.ability.abilityManager';
```
## Usage ## Usage
The ability running information is obtained by calling [getAbilityRunningInfos](js-apis-app-ability-abilityManager.md#getabilityrunninginfos) in **abilityManager**. The ability running information is obtained by calling [getAbilityRunningInfos](js-apis-app-ability-abilityManager.md#getabilityrunninginfos) in **abilityManager**.
......
...@@ -9,6 +9,12 @@ This module provides APIs for accessing a specific ability stage. You can use th ...@@ -9,6 +9,12 @@ This module provides APIs for accessing a specific ability stage. You can use th
> 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. > The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import common from '@ohos.app.ability.common';
```
## Usage ## Usage
The ability stage context is obtained through an **AbilityStage** instance. The ability stage context is obtained through an **AbilityStage** instance.
......
# AbilityStageMonitor # AbilityStageMonitor
The **AbilityStageMonitor** module provides conditions for matching **AbilityStage** instances. The most recently matched **AbilityStage** instance is saved in an **AbilityStageMonitor** instance. The **AbilityStageMonitor** module provides conditions for matching **AbilityStage** instances. The most recently matched **AbilityStage** instance is saved in an **AbilityStageMonitor** instance.
> **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.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------------------------------------------------------------ | -------- | ---- | ---- | ------------------------------------------------------------ | | ------------------------------------------------------------ | -------- | ---- | ---- | ------------------------------------------------------------ |
| moduleName<sup>9+</sup> | string | Yes | Yes | Module name of the **AbilityStage** instance.| | moduleName | string | Yes | Yes | Module name of the **AbilityStage** instance.|
| srcEntrance<sup>9+</sup> | string | Yes | Yes | Source path of the **AbilityStage** instance.| | srcEntrance | string | Yes | Yes | Source path of the **AbilityStage** instance.|
**Example** **Example**
```ts ```ts
......
...@@ -2,17 +2,27 @@ ...@@ -2,17 +2,27 @@
The **AbilityStateData** module defines the ability state information, which can be obtained through the **onAbilityStateChanged** lifecycle callback of [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md). The callback can be invoked after a lifecycle change listener is registered through [registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver8). The **AbilityStateData** module defines the ability state information, which can be obtained through the **onAbilityStateChanged** lifecycle callback of [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md). The callback can be invoked after a lifecycle change listener is registered through [registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver8).
> **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.
## Modules to Import
```ts
import appManager from '@ohos.application.appManager';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ----------------------- | ---------| ---- | ---- | ------------------------- | | ----------------------- | ---------| ---- | ---- | ------------------------- |
| pid<sup>8+</sup> | number | Yes | No | Process ID. | | pid | number | Yes | No | Process ID. |
| bundleName<sup>8+</sup> | string | Yes | No | Bundle name. | | bundleName | string | Yes | No | Bundle name. |
| abilityName<sup>8+</sup> | string | Yes | No | Ability name. | | abilityName | string | Yes | No | Ability name. |
| uid<sup>8+</sup> | number | Yes | No | User ID. | | uid | number | Yes | No | User ID. |
| state<sup>8+</sup> | number | Yes | No | [Ability state](#ability-states). | | state | number | Yes | No | [Ability state](#ability-states). |
| moduleName<sup>9+</sup> | string | Yes | No | Name of the HAP file to which the ability belongs. | | moduleName<sup>9+</sup> | string | Yes | No | Name of the HAP file to which the ability belongs. |
| abilityType<sup>8+</sup> | number | Yes | No | [Ability type](#ability-types), which can be **page** or **service**.| | abilityType | number | Yes | No | [Ability type](#ability-types), which can be **page** or **service**.|
#### Ability States #### Ability States
...@@ -29,7 +39,7 @@ The **AbilityStateData** module defines the ability state information, which can ...@@ -29,7 +39,7 @@ The **AbilityStateData** module defines the ability state information, which can
#### Ability Types #### Ability Types
| Value | Status | Description | | Value | State | Description |
| ---- | ------- | --------------------- | | ---- | ------- | --------------------- |
| 0 | UNKNOWN | Unknown type. | | 0 | UNKNOWN | Unknown type. |
| 1 | PAGE | Ability that has the UI. | | 1 | PAGE | Ability that has the UI. |
......
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
The **AppStateData** module defines the application state data, which can be obtained through [getForegroundApplications](js-apis-app-ability-appManager.md#appmanagergetforegroundapplications). The **AppStateData** module defines the application state data, which can be obtained through [getForegroundApplications](js-apis-app-ability-appManager.md#appmanagergetforegroundapplications).
## Modules to Import
```ts
import appManager from '@ohos.app.ability.appManager';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
...@@ -9,7 +15,7 @@ The **AppStateData** module defines the application state data, which can be obt ...@@ -9,7 +15,7 @@ The **AppStateData** module defines the application state data, which can be obt
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------------------------- | ------ | ---- | --------- | | ------------------------- | ------ | ---- | --------- |
| bundleName<sup>8+</sup> | string | No | Bundle name.| | bundleName<sup>8+</sup> | string | No | Bundle name.|
| uid<sup>8+</sup> | number | No | UID of the application. | | uid<sup>8+</sup> | number | No | User ID. |
| state<sup>8+</sup> | number | No | Application state.| | state<sup>8+</sup> | number | No | Application state.|
**Example** **Example**
...@@ -25,3 +31,4 @@ appManager.getForegroundApplications((error, data) => { ...@@ -25,3 +31,4 @@ appManager.getForegroundApplications((error, data) => {
} }
}); });
``` ```
...@@ -7,12 +7,18 @@ The **ApplicationContext** module provides application-level context. You can us ...@@ -7,12 +7,18 @@ The **ApplicationContext** module provides application-level context. You can us
> 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. > The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import common from '@ohos.app.ability.common';
```
## Usage ## Usage
Before calling any APIs in **ApplicationContext**, obtain an **ApplicationContext** instance through the **context** instance. Before calling any APIs in **ApplicationContext**, obtain an **ApplicationContext** instance through the **context** instance.
```ts ```ts
let applicationContext = this.context.getApplicationContext(); let applicationContext: common.ApplicationContext = this.context.getApplicationContext();
``` ```
## ApplicationContext.on(type: 'abilityLifecycle', callback: AbilityLifecycleCallback) ## ApplicationContext.on(type: 'abilityLifecycle', callback: AbilityLifecycleCallback)
...@@ -295,7 +301,6 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error ...@@ -295,7 +301,6 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
**Example** **Example**
```ts ```ts
let applicationContext = this.context.getApplicationContext();
applicationContext.getRunningProcessInformation().then((data) => { applicationContext.getRunningProcessInformation().then((data) => {
console.log('The process running information is:' + JSON.stringify(data)); console.log('The process running information is:' + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
...@@ -333,7 +338,6 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error ...@@ -333,7 +338,6 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
**Example** **Example**
```ts ```ts
let applicationContext = this.context.getApplicationContext();
applicationContext.getRunningProcessInformation((err, data) => { applicationContext.getRunningProcessInformation((err, data) => {
if (err.code !== 0) { if (err.code !== 0) {
console.error('getRunningProcessInformation faile, err: ' + JSON.stringify(err)); console.error('getRunningProcessInformation faile, err: ' + JSON.stringify(err));
...@@ -388,7 +392,7 @@ Kills all the processes where the application is located. This API uses an async ...@@ -388,7 +392,7 @@ Kills all the processes where the application is located. This API uses an async
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
|AsyncCallback\<void\> | Callback used to return the result.| |AsyncCallback\<void> | Callback used to return the result.|
**Error codes** **Error codes**
...@@ -401,10 +405,9 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error ...@@ -401,10 +405,9 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
**Example** **Example**
```ts ```ts
let applicationContext = this.context.getApplicationContext(); applicationContext.killAllProcesses(error => {
applicationContext.killProcessesBySelf(err => { if (error) {
if (err.code !== 0) { console.error('killAllProcesses fail, error: ${JSON.stringify(error)}');
console.error('killProcessesBySelf faile, err: ' + JSON.stringify(err));
} }
}) })
``` ```
...@@ -2,22 +2,30 @@ ...@@ -2,22 +2,30 @@
The **ApplicationStateObserver** module defines an observer to listen for application state changes. It can be used as an input parameter in [registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver8) to listen for lifecycle changes of the current application. The **ApplicationStateObserver** module defines an observer to listen for application state changes. It can be used as an input parameter in [registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver8) to listen for lifecycle changes of the current application.
> **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.
## Modules to Import
```ts
import appManager from '@ohos.app.ability.appManager';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
| Name | | Type | Readable| Writable| Description | | Name | | Type | Readable| Writable| Description |
| ----------------------- | ---------| ---- | ---- | ------------------------- | ------------------------- | | ----------------------- | ---------| ---- | ---- | ------------------------- | ------------------------- |
| onForegroundApplicationChanged<sup>8+</sup> | [AppStateData](js-apis-inner-application-appStateData.md) | AsyncCallback\<void> | Yes | No | Callback invoked when the foreground or background state of an application changes. | | onForegroundApplicationChanged | [AppStateData](js-apis-inner-application-appStateData.md) | AsyncCallback\<void> | Yes | No | Callback invoked when the foreground or background state of an application changes. |
| onAbilityStateChanged<sup>8+</sup> | [AbilityStateData](js-apis-inner-application-abilityStateData.md) | AsyncCallback\<void> | Yes | No | Callback invoked when the ability state changes. | | onAbilityStateChanged | [AbilityStateData](js-apis-inner-application-abilityStateData.md) | AsyncCallback\<void> | Yes | No | Callback invoked when the ability state changes. |
| onProcessCreated<sup>8+</sup> | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\<void> | Yes | No | Callback invoked when a process is created. | | onProcessCreated | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\<void> | Yes | No | Callback invoked when a process is created. |
| onProcessDied<sup>8+</sup> | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\<void> | Yes | No | Callback invoked when a process is destroyed. | | onProcessDied | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\<void> | Yes | No | Callback invoked when a process is destroyed. |
| onProcessStateChanged<sup>8+</sup> | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\<void> | Yes | No | Callback invoked when the process state is changed. | | onProcessStateChanged<sup>9+</sup> | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\<void> | Yes | No | Callback invoked when the process state is changed. |
**Example** **Example**
```ts ```ts
import appManager from "@ohos.application.appManager";
let applicationStateObserver = { let applicationStateObserver = {
onForegroundApplicationChanged(appStateData) { onForegroundApplicationChanged(appStateData) {
console.log('onForegroundApplicationChanged appStateData: ' + JSON.stringify(appStateData)); console.log('onForegroundApplicationChanged appStateData: ' + JSON.stringify(appStateData));
......
...@@ -6,11 +6,17 @@ ...@@ -6,11 +6,17 @@
> >
> 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
```ts
import common from '@ohos.app.ability.common';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| -------- | ------ | ---- | ---- | ------- | | -------- | ------ | ---- | ---- | ------- |
| stageMode | boolean | Yes | Yes | Whether the child class **Context** is used for the stage model.<br>**true**: used for the stage model.<br>**false**: used for the FA model.| | stageMode | boolean | Yes | Yes | Whether the child class **Context** is used for the stage model.|
**Example** **Example**
......
...@@ -4,8 +4,14 @@ The **Context** module provides context for abilities or applications. It allows ...@@ -4,8 +4,14 @@ The **Context** module provides context for abilities or applications. It allows
> **NOTE** > **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. > The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import common from '@ohos.app.ability.common';
```
## Attributes ## Attributes
...@@ -20,7 +26,7 @@ The **Context** module provides context for abilities or applications. It allows ...@@ -20,7 +26,7 @@ The **Context** module provides context for abilities or applications. It allows
| filesDir | string | Yes | No | File directory.| | filesDir | string | Yes | No | File directory.|
| databaseDir | string | Yes | No | Database directory.| | databaseDir | string | Yes | No | Database directory.|
| preferencesDir | string | Yes | No | Preferences directory.| | preferencesDir | string | Yes | No | Preferences directory.|
| bundleCodeDir | string | Yes | No | Bundle code directory. A resource file cannot be accessed by combining paths. Use [Resource Manager](js-apis-resource-manager.md) to access it. | | bundleCodeDir | string | Yes | No | Bundle code directory. Do not access resource files by concatenating paths. Use the [resourceManager API](js-apis-resource-manager.md) instead.|
| distributedFilesDir | string | Yes | No | Distributed file directory.| | distributedFilesDir | string | Yes | No | Distributed file directory.|
| eventHub | [EventHub](js-apis-inner-application-eventHub.md) | Yes | No | Event hub that implements event subscription, unsubscription, and triggering.| | eventHub | [EventHub](js-apis-inner-application-eventHub.md) | Yes | No | Event hub that implements event subscription, unsubscription, and triggering.|
| area | [AreaMode](#areamode) | Yes | No | Area in which the file to be access is located.| | area | [AreaMode](#areamode) | Yes | No | Area in which the file to be access is located.|
...@@ -49,7 +55,12 @@ Creates the context based on the bundle name. ...@@ -49,7 +55,12 @@ Creates the context based on the bundle name.
**Example** **Example**
```ts ```ts
let bundleContext = this.context.createBundleContext('com.example.test'); let bundleContext: common.Context;
try {
bundleContext = this.context.createBundleContext('com.example.test');
} catch (error) {
console.error('createBundleContext failed, error.code: ${error.code}, error.message: ${error.message}');
}
``` ```
## Context.createModuleContext ## Context.createModuleContext
...@@ -75,7 +86,12 @@ Creates the context based on the module name. ...@@ -75,7 +86,12 @@ Creates the context based on the module name.
**Example** **Example**
```ts ```ts
let moduleContext = this.context.createModuleContext('entry'); let moduleContext: common.Context;
try {
moduleContext = this.context.createModuleContext('entry');
} catch (error) {
console.error('createModuleContext failed, error.code: ${error.code}, error.message: ${error.message}');
}
``` ```
## Context.createModuleContext ## Context.createModuleContext
...@@ -102,14 +118,19 @@ Creates the context based on the bundle name and module name. ...@@ -102,14 +118,19 @@ Creates the context based on the bundle name and module name.
**Example** **Example**
```ts ```ts
let moduleContext = this.context.createModuleContext('com.example.test', 'entry'); let moduleContext: common.Context;
try {
moduleContext = this.context.createModuleContext('com.example.test', 'entry');
} catch (error) {
console.error('createModuleContext failed, error.code: ${error.code}, error.message: ${error.message}');
}
``` ```
## Context.getApplicationContext ## Context.getApplicationContext
getApplicationContext(): ApplicationContext; getApplicationContext(): ApplicationContext;
Obtains the context of this application. Obtains the application context.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -122,16 +143,21 @@ Obtains the context of this application. ...@@ -122,16 +143,21 @@ Obtains the context of this application.
**Example** **Example**
```ts ```ts
let applicationContext = this.context.getApplicationContext(); let applicationContext: common.Context;
try {
applicationContext = this.context.getApplicationContext();
} catch (error) {
console.error('getApplicationContext failed, error.code: ${error.code}, error.message: ${error.message}');
}
``` ```
## AreaMode ## AreaMode
Enumerates the areas in which the file to be access can be located. Enumerates the encryption levels of directories.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| EL1 | 0 | Device-level encryption area, which is accessible after the device is powered on.| | EL1 | 0 | Device-level encryption. Directories with this encryption level are accessible after the device is powered on.|
| EL2 | 1 | User-level encryption area, which is accessible only after the device is powered on and the password is entered (for the first time).| | EL2 | 1 | User-level encryption. Directories with this encryption level are accessible only after the device is powered on and the password is entered (for the first time).|
...@@ -2,7 +2,17 @@ ...@@ -2,7 +2,17 @@
The **ErrorObserver** module defines an observer to listen for application errors. It can be used as an input parameter in [errorManager.on](js-apis-app-ability-errorManager.md#errormanageron) to listen for errors that occur in the current application. The **ErrorObserver** module defines an observer to listen for application errors. It can be used as an input parameter in [errorManager.on](js-apis-app-ability-errorManager.md#errormanageron) to listen for errors that occur in the current application.
## onUnhandledException > **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.
## Modules to Import
```ts
import errorManager from '@ohos.app.ability.errorManager';
```
## ErrorObserver.onUnhandledException
onUnhandledException(errMsg: string): void; onUnhandledException(errMsg: string): void;
...@@ -22,9 +32,15 @@ Called when an unhandled exception occurs in the JS runtime. ...@@ -22,9 +32,15 @@ Called when an unhandled exception occurs in the JS runtime.
import errorManager from '@ohos.app.ability.errorManager'; import errorManager from '@ohos.app.ability.errorManager';
let observer = { let observer = {
onUnhandledException(errorMsg) { onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ' + JSON.stringify(errorMsg)); console.error('onUnhandledException, errorMsg: ', errorMsg);
} }
}; };
errorManager.on('error',observer);
try {
errorManager.on('error', observer);
} catch (error) {
console.error('registerErrorObserver failed, error.code: ${error.code}, error.message: ${error.message}');
}
```
``` ```
...@@ -3,9 +3,15 @@ ...@@ -3,9 +3,15 @@
The **EventHub** module provides APIs to subscribe to, unsubscribe from, and trigger events. The **EventHub** module provides APIs to subscribe to, unsubscribe from, and trigger events.
> **NOTE** > **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. > The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import common from '@ohos.app.ability.common';
```
## Usage ## Usage
...@@ -65,7 +71,7 @@ Subscribes to an event. ...@@ -65,7 +71,7 @@ Subscribes to an event.
off(event: string, callback?: Function): void; off(event: string, callback?: Function): void;
Unsubscribes from an event. Unsubscribes from an event. If **callback** is specified, this API unsubscribes from the specified callback. If **callback** is not specified, this API unsubscribes from all callbacks in the event.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -84,10 +90,10 @@ Unsubscribes from an event. ...@@ -84,10 +90,10 @@ Unsubscribes from an event.
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
onForeground() { onForeground() {
this.context.eventHub.on('123', this.func1); this.context.eventHub.on('123', this.func1);
this.context.eventHub.off('123', this.func1); // Unsubscribe from the myEvent event with the callback eventFunc1. this.context.eventHub.off('123', this.func1); // Unsubscribe from func1.
this.context.eventHub.on('123', this.func1); this.context.eventHub.on('123', this.func1);
this.context.eventHub.on('123', this.func2); this.context.eventHub.on('123', this.func2);
this.context.eventHub.off('123'); // Unsubscribe from the myEvent event with all the callbacks (eventFunc1 and eventFunc2). this.context.eventHub.off('123'); // Unsubscribe from func1 and func2.
} }
func1() { func1() {
console.log('func1 is called'); console.log('func1 is called');
......
...@@ -9,6 +9,12 @@ This module provides APIs for accessing resources of a specific Extension abilit ...@@ -9,6 +9,12 @@ This module provides APIs for accessing resources of a specific Extension abilit
> - 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. > - The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import common from '@ohos.app.ability.common';
```
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
......
# ExtensionRunningInfo # ExtensionRunningInfo
The **ExtensionRunningInfo** module encapsulates ExtensionAbility running information, which can be obtained through [getExtensionRunningInfos](js-apis-app-ability-abilityManager.md#getextensionrunninginfos). The **ExtensionRunningInfo** module provides APIs for setting and querying ExtensionAbility running information, which can be obtained through [getExtensionRunningInfos](js-apis-app-ability-abilityManager.md#getextensionrunninginfos).
> **NOTE** > **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 are system APIs and cannot be called by third-party applications. > The APIs of this module are system APIs and cannot be called by third-party applications.
## Modules to Import
```ts
import abilityManager from '@ohos.app.ability.abilityManager';
```
## Usage ## Usage
Import the **abilityManager** module and obtain the ExtensionAbility running information by calling the method in the **abilityManager** module. The ExtensionAbility running information is obtained through an **abilityManager** instance.
## Attributes ## Attributes
...@@ -17,11 +23,11 @@ Import the **abilityManager** module and obtain the ExtensionAbility running inf ...@@ -17,11 +23,11 @@ Import the **abilityManager** module and obtain the ExtensionAbility running inf
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| extension | ElementName | Yes| No| ExtensionAbility information.| | extension | ElementName | Yes| No| ExtensionAbility information..|
| pid | number | Yes| No| Process ID.| | pid | number | Yes| No| Process ID.|
| uid | number | Yes| No| UID of the application.| | uid | number | Yes| No| User ID.|
| processName | string | Yes| No| Process name.| | processName | string | Yes| No| Process name.|
| startTime | number | Yes| No| Timestamp when the ExtensionAbility is started.| | startTime | number | Yes| No| Start time of the ExtensionAbility.|
| clientPackage | Array&lt;String&gt; | Yes| No| Names of all packages in the process.| | clientPackage | Array&lt;String&gt; | Yes| No| Names of all packages in the process.|
| type | [bundle.ExtensionAbilityType](js-apis-Bundle.md) | Yes| No| ExtensionAbility type.| | type | [bundle.ExtensionAbilityType](js-apis-Bundle.md) | Yes| No| ExtensionAbility type.|
......
...@@ -24,7 +24,7 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; ...@@ -24,7 +24,7 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData'; import formBindingData from '@ohos.app.form.formBindingData';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onAddForm() { onAddForm() {
let formContext = this.context; // »ñÈ¡FormExtensionContext let formContext = this.context; // Obtain a FormExtensionContext instance.
// ... // ...
let dataObj1 = { let dataObj1 = {
temperature:'11c', temperature:'11c',
......
...@@ -2,6 +2,16 @@ ...@@ -2,6 +2,16 @@
The **MissionInfo** module defines detailed information about a mission. The information can be obtained through [getMissionInfo](js-apis-app-ability-missionManager.md#missionmanagergetmissioninfo). The **MissionInfo** module defines detailed information about a mission. The information can be obtained through [getMissionInfo](js-apis-app-ability-missionManager.md#missionmanagergetmissioninfo).
> **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.
## Modules to Import
```ts
import missionManager from '@ohos.app.ability.missionManager';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission **System capability**: SystemCapability.Ability.AbilityRuntime.Mission
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
......
...@@ -2,6 +2,16 @@ ...@@ -2,6 +2,16 @@
The **MissionListener** module defines the listeners used to observe the mission status. The listeners can be registered by using [registerMissionListener](js-apis-application-missionManager.md#missionmanagerregistermissionlistener). The **MissionListener** module defines the listeners used to observe the mission status. The listeners can be registered by using [registerMissionListener](js-apis-application-missionManager.md#missionmanagerregistermissionlistener).
> **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.
## Modules to Import
```ts
import missionManager from '@ohos.app.ability.missionManager';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission **System capability**: SystemCapability.Ability.AbilityRuntime.Mission
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
...@@ -10,9 +20,9 @@ The **MissionListener** module defines the listeners used to observe the mission ...@@ -10,9 +20,9 @@ The **MissionListener** module defines the listeners used to observe the mission
| onMissionDestroyed | function | No | Called when the system destroys the mission.| | onMissionDestroyed | function | No | Called when the system destroys the mission.|
| onMissionSnapshotChanged | function | No | Called when the system updates the mission snapshot.| | onMissionSnapshotChanged | function | No | Called when the system updates the mission snapshot.|
| onMissionMovedToFront | function | No | Called when the system moves the mission to the foreground.| | onMissionMovedToFront | function | No | Called when the system moves the mission to the foreground.|
| onMissionLabelUpdated | function | No | Called when the system updates the mission label.| | onMissionLabelUpdated<sup>9+</sup> | function | No | Called when the system updates the mission label.|
| onMissionIconUpdated | function | No | Called when the system updates the mission icon.| | onMissionIconUpdated<sup>9+</sup> | function | No | Called when the system updates the mission icon.|
| onMissionClosed | function | No | Called when the system closes the mission.| | onMissionClosed<sup>9+</sup> | function | No | Called when the system closes the mission.|
**Example** **Example**
```ts ```ts
......
...@@ -7,6 +7,12 @@ The **MissionSnapshot** module defines the snapshot of a mission. The snapshot c ...@@ -7,6 +7,12 @@ The **MissionSnapshot** module defines the snapshot of a mission. The snapshot c
> 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.
> The APIs of this module are system APIs and cannot be called by third-party applications. > The APIs of this module are system APIs and cannot be called by third-party applications.
## Modules to Import
```ts
import missionManager from '@ohos.app.ability.missionManager';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission **System capability**: SystemCapability.Ability.AbilityRuntime.Mission
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
......
...@@ -2,17 +2,28 @@ ...@@ -2,17 +2,28 @@
The **ProcessData** module defines process data. If a lifecycle change listener is registered by calling [registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver8), the **onProcessCreated** callback in [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md) is invoked when the lifecycle of an application or ability changes. The **ProcessData** module defines process data. If a lifecycle change listener is registered by calling [registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver8), the **onProcessCreated** callback in [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md) is invoked when the lifecycle of an application or ability changes.
> **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.
## Modules to Import
```ts
import appManager from '@ohos.application.appManager';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ----------------------- | ---------| ---- | ---- | ------------------------- | | ----------------------- | ---------| ---- | ---- | ------------------------- |
| pid<sup>8+</sup> | number | Yes | No | Process ID. | | pid | number | Yes | No | Process ID. |
| bundleName<sup>8+</sup> | string | Yes | No | Bundle name of the application. | | bundleName | string | Yes | No | Bundle name of the application. |
| uid<sup>8+</sup> | number | Yes | No | UID of the application. | | uid | number | Yes | No | UID of the application. |
| isContinuousTask<sup>9+</sup> | boolean | Yes | No | Whether the task is a continuous task. The value **true** means that the task is a continuous task, and **false** means the opposite. | | isContinuousTask<sup>9+</sup> | boolean | Yes | No | Whether the task is a continuous task. The value **true** means that the task is a continuous task, and **false** means the opposite. |
| isKeepAlive<sup>9+</sup> | boolean | Yes | No | Whether the process is a resident task. The value **true** means that the process is a resident, and **false** means the opposite. | | isKeepAlive<sup>9+</sup> | boolean | Yes | No | Whether the process is a resident task. The value **true** means that the process is a resident, and **false** means the opposite. |
| state<sup>9+</sup> | number | Yes | No | Application state. The value can be **0** (newly created), **2** (foreground), **4** (background), or **5** (terminated). |
**Example** **Example**
```ts ```ts
......
...@@ -6,6 +6,12 @@ The **ProcessInformation** module defines the running information of a process. ...@@ -6,6 +6,12 @@ The **ProcessInformation** module defines the running information of a process.
> >
> 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.
## Modules to Import
```ts
import appManager from '@ohos.app.ability.appManager';
```
## How to Use ## How to Use
The process information is obtained by calling [getRunningProcessInformation](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinformation9) of the **appManager** module. The process information is obtained by calling [getRunningProcessInformation](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinformation9) of the **appManager** module.
......
...@@ -6,6 +6,12 @@ The **ProcessRunningInfo** module defines the running information of a process. ...@@ -6,6 +6,12 @@ The **ProcessRunningInfo** module defines the running information of a process.
> - The APIs provided by this module are deprecated since API version 9. You are advised to use [ProcessInformation<sup>9+</sup>](js-apis-inner-application-processInformation.md) instead. > - The APIs provided by this module are deprecated since API version 9. You are advised to use [ProcessInformation<sup>9+</sup>](js-apis-inner-application-processInformation.md) instead.
> - The initial APIs of this module are supported since API version 8. > - The initial APIs of this module are supported since API version 8.
## Modules to Import
```ts
import appManager from '@ohos.app.ability.appManager';
```
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission **System capability**: SystemCapability.Ability.AbilityRuntime.Mission
......
...@@ -9,6 +9,12 @@ You can use the APIs of this module to start, terminate, connect, and disconnect ...@@ -9,6 +9,12 @@ You can use the APIs of this module to start, terminate, connect, and disconnect
> - 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. > - The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import common from '@ohos.app.ability.common';
```
## Usage ## Usage
Before using the **ServiceExtensionContext** module, you must define a child class that inherits from **ServiceExtensionAbility**. Before using the **ServiceExtensionContext** module, you must define a child class that inherits from **ServiceExtensionAbility**.
......
...@@ -6,6 +6,12 @@ The **ShellCmdResult** module provides the shell command execution result. ...@@ -6,6 +6,12 @@ The **ShellCmdResult** module provides the shell command execution result.
> >
> 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
```ts
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
...@@ -19,8 +25,7 @@ The result is obtained by calling [executeShellCommand](js-apis-inner-applicatio ...@@ -19,8 +25,7 @@ The result is obtained by calling [executeShellCommand](js-apis-inner-applicatio
**Example** **Example**
```ts ```ts
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; let abilityDelegator: AbilityDelegatorRegistry.AbilityDelegator;
let abilityDelegator;
let cmd = 'cmd'; let cmd = 'cmd';
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
......
...@@ -9,6 +9,12 @@ This module provides APIs for accessing UIAbility-specific resources. You can us ...@@ -9,6 +9,12 @@ This module provides APIs for accessing UIAbility-specific resources. You can us
> - 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. > - The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import common from '@ohos.app.ability.common';
```
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -360,23 +366,20 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error ...@@ -360,23 +366,20 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
windowMode: 0, windowMode: 0,
}; };
try { try {
this.context.startAbilityForResult(want, options, (error, result) => { this.context.startAbilityForResult(want, options, (err, result) => {
if (error.code) { if (err.code) {
// Process service logic errors. // Process service logic errors.
console.log('startAbilityForResult failed, error.code: ' + JSON.stringify(error.code) + console.error(`startAbilityForResult failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); return;
return; }
} // Carry out normal service processing.
// Carry out normal service processing. console.info('startAbilityForResult succeed');
console.log('startAbilityForResult succeed, result.resultCode = ' + });
result.resultCode) } catch (err) {
}); // Process input parameter errors.
} catch (paramError) { console.error(`startAbilityForResult failed, code is ${err.code}, message is ${err.message}`);
// Process input parameter errors. }
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
...@@ -779,22 +782,20 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error ...@@ -779,22 +782,20 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
abilityName: 'MainAbility' abilityName: 'MainAbility'
}; };
try { try {
this.context.startServiceExtensionAbility(want) this.context.startServiceExtensionAbility(want)
.then((data) => { .then(() => {
// Carry out normal service processing. // Carry out normal service processing.
console.log('startServiceExtensionAbility succeed'); console.info('startServiceExtensionAbility succeed');
}) })
.catch((error) => { .catch((err) => {
// Process service logic errors. // Process service logic errors.
console.log('startServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) + console.error(`startServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
' error.message: ' + JSON.stringify(error.message)); });
}); } catch (err) {
} catch (paramError) { // Process input parameter errors.
// Process input parameter errors. console.error(`startServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
console.log('error.code: ' + JSON.stringify(paramError.code) + }
' error.message: ' + JSON.stringify(paramError.message));
}
``` ```
## UIAbilityContext.startServiceExtensionAbilityWithAccount ## UIAbilityContext.startServiceExtensionAbilityWithAccount
...@@ -1404,15 +1405,22 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error ...@@ -1404,15 +1405,22 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
**Example** **Example**
```ts ```ts
let want = { let want = {
deviceId: '', deviceId: '',
bundleName: 'com.extreme.test', bundleName: 'com.example.myapplication',
abilityName: 'MainAbility' abilityName: 'ServiceExtensionAbility'
}; };
let options = { let commRemote;
onConnect(elementName, remote) { console.log('----------- onConnect -----------') }, let options = {
onDisconnect(elementName) { console.log('----------- onDisconnect -----------') }, onConnect(elementName, remote) {
onFailed(code) { console.log('----------- onFailed -----------') } commRemote = remote;
console.info('onConnect...')
},
onDisconnect(elementName) {
console.info('onDisconnect...')
},
onFailed(code) {
console.info('onFailed...')
} }
let connection = null; let connection = null;
...@@ -1466,16 +1474,23 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error ...@@ -1466,16 +1474,23 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
**Example** **Example**
```ts ```ts
let want = { let want = {
deviceId: '', deviceId: '',
bundleName: 'com.extreme.test', bundleName: 'com.example.myapplication',
abilityName: 'MainAbility' abilityName: 'ServiceExtensionAbility'
}; };
let accountId = 100; let accountId = 100;
let options = { let commRemote;
onConnect(elementName, remote) { console.log('----------- onConnect -----------') }, let options = {
onDisconnect(elementName) { console.log('----------- onDisconnect -----------') }, onConnect(elementName, remote) {
onFailed(code) { console.log('----------- onFailed -----------') } commRemote = remote;
console.info('onConnect...')
},
onDisconnect(elementName) {
console.info('onDisconnect...')
},
onFailed(code) {
console.info('onFailed...')
} }
let connection = null; let connection = null;
...@@ -1520,8 +1535,8 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error ...@@ -1520,8 +1535,8 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
**Example** **Example**
```ts ```ts
// connection is the return value of connectServiceExtensionAbility. // connection is the return value of connectServiceExtensionAbility.
let connection = 1; let connection = 1;
try { try {
this.context.disconnectServiceExtensionAbility(connection) this.context.disconnectServiceExtensionAbility(connection)
...@@ -1568,8 +1583,26 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error ...@@ -1568,8 +1583,26 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
**Example** **Example**
```ts ```ts
// connection is the return value of connectServiceExtensionAbility. // connection is the return value of connectServiceExtensionAbility.
let connection = 1; let connection = 1;
let commRemote;
try {
this.context.disconnectServiceExtensionAbility(connection, (err) => {
commRemote = null;
if (err.code) {
// Process service logic errors.
console.error(`disconnectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
return;
}
// Carry out normal service processing.
console.info('disconnectServiceExtensionAbility succeed');
});
} catch (err) {
commRemote = null;
// Process input parameter errors.
console.error(`disconnectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
}
try { try {
this.context.disconnectServiceExtensionAbility(connection, (error) => { this.context.disconnectServiceExtensionAbility(connection, (error) => {
...@@ -1925,7 +1958,7 @@ Requests permissions from the user by displaying a dialog box. This API uses an ...@@ -1925,7 +1958,7 @@ Requests permissions from the user by displaying a dialog box. This API uses an
| 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.| | callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -1956,7 +1989,7 @@ Requests permissions from the user by displaying a dialog box. This API uses a p ...@@ -1956,7 +1989,7 @@ Requests permissions from the user by displaying a dialog box. This API uses a p
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[PermissionRequestResult](js-apis-permissionRequestResult.md)&gt; | Promise used to return the result.| | Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result.|
**Example** **Example**
......
...@@ -2,6 +2,16 @@ ...@@ -2,6 +2,16 @@
The **TriggerInfo** module defines the information required for triggering the WantAgent. The information is used as an input parameter of [trigger](js-apis-app-ability-wantAgent.md#wantagenttrigger). The **TriggerInfo** module defines the information required for triggering the WantAgent. The information is used as an input parameter of [trigger](js-apis-app-ability-wantAgent.md#wantagenttrigger).
> **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.
## Modules to Import
```ts
import wantAgent from '@ohos.app.ability.wantAgent';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
......
...@@ -2,6 +2,16 @@ ...@@ -2,6 +2,16 @@
The **WantAgentInfo** module defines the information required for triggering a **WantAgent** object. The information can be used as an input parameter in [getWantAgent](js-apis-app-ability-wantAgent.md#wantagentgetwantagent) to obtain a specified **WantAgent** object. The **WantAgentInfo** module defines the information required for triggering a **WantAgent** object. The information can be used as an input parameter in [getWantAgent](js-apis-app-ability-wantAgent.md#wantagentgetwantagent) to obtain a specified **WantAgent** object.
> **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.
## Modules to Import
```ts
import wantAgent from '@ohos.app.ability.wantAgent';
```
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册