提交 da80bb82 编写于 作者: W wusongqing

update docs against TR7765

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 8e60e6b8
# Context
The **Context** module provides context for abilities or applications. It allows access to application-specific resources, as well as permission requests and verification.
> **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 APIs of this module can be used only in the FA model.
## Modules to Import
```js
import featureAbility from '@ohos.ability.featureAbility'
```
## Usage
The **Context** object is created in a **featureAbility** and returned through its **getContext()** 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()** API. Therefore, you must import the **@ohos.ability.featureAbility** package before using the **Context** module. An example is as follows:
```js
import featureAbility from '@ohos.ability.featureAbility'
......@@ -33,9 +29,9 @@ If this API is called for the first time, a root directory will be created.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | -------------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the local root directory.|
| Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | ------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the local root directory.|
**Example**
......@@ -61,8 +57,8 @@ If this API is called for the first time, a root directory will be created.
**Return value**
| Type | Description |
| ---------------- | ---------------------- |
| Type | Description |
| ---------------- | ----------- |
| Promise\<string> | Promise used to return the local root directory.|
**Example**
......@@ -87,11 +83,11 @@ Verifies whether a specific PID and UID have the given permission. This API uses
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | ------------------------------------- |
| permission | string | Yes | Name of the permission to verify. |
| options | [PermissionOptions](#permissionoptions) | Yes | Permission options. |
| callback | AsyncCallback\<number> | Yes | Callback used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.|
| Name | Type | Mandatory | Description |
| ---------- | --------------------------------------- | ---- | -------------------- |
| permission | string | Yes | Name of the permission to verify. |
| options | [PermissionOptions](#permissionoptions) | Yes | Permission options. |
| callback | AsyncCallback\<number> | Yes | Callback used to return the permission verification result. The value **0** means that the PID and UID have the given permission, and the value **-1** means the opposite.|
**Example**
......@@ -116,10 +112,10 @@ Verifies whether the current PID and UID have the given permission. This API use
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ---------------------- | ---- | ------------------------------------- |
| permission | string | Yes | Name of the permission to verify. |
| callback | AsyncCallback\<number> | Yes | Callback used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.|
| Name | Type | Mandatory | Description |
| ---------- | ---------------------- | ---- | -------------------- |
| permission | string | Yes | Name of the permission to verify. |
| callback | AsyncCallback\<number> | Yes | Callback used to return the permission verification result. The value **0** means that the PID and UID have the given permission, and the value **-1** means the opposite.|
**Example**
......@@ -139,16 +135,16 @@ Verifies whether a specific PID and UID have the given permission. This API uses
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | ---------------- |
| permission | string | Yes | Name of the permission to verify.|
| options | [PermissionOptions](#permissionoptions) | No | Permission options. |
| Name | Type | Mandatory | Description |
| ---------- | --------------------------------------- | ---- | -------- |
| permission | string | Yes | Name of the permission to verify.|
| options | [PermissionOptions](#permissionoptions) | No | Permission options. |
**Return value**
| Type | Description |
| ---------------- | ----------------------------------------------------------- |
| Promise\<number> | Promise used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.|
| Type | Description |
| ---------------- | ---------------------------------- |
| Promise\<number> | Promise used to return the permission verification result. The value **0** means that the PID and UID have the given permission, and the value **-1** means the opposite.|
**Example**
......@@ -174,11 +170,11 @@ Requests certain permissions from the system. This API uses an asynchronous call
**Parameters**
| Name | Type | Mandatory| Description |
| -------------- | ------------------------------------------------------------ | ---- | ----------------------------------------------- |
| permissions | Array\<string> | Yes | Permissions to request. This parameter cannot be **null**. |
| requestCode | number | Yes | Request code to be passed to **PermissionRequestResult**.|
| resultCallback | AsyncCallback<[PermissionRequestResult](#permissionrequestresult)> | Yes | Permission request result. |
| Name | Type | Mandatory | Description |
| -------------- | ---------------------------------------- | ---- | ----------------------------------- |
| permissions | Array\<string> | Yes | Permissions to request. This parameter cannot be **null**. |
| requestCode | number | Yes | Request code to be passed to **PermissionRequestResult**.|
| resultCallback | AsyncCallback<[PermissionRequestResult](#permissionrequestresult)> | Yes | Permission request result. |
**Example**
......@@ -210,9 +206,9 @@ Obtains information about the current application. This API uses an asynchronous
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback\<ApplicationInfo> | Yes | Callback used to return the application information.|
| Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ------------ |
| callback | AsyncCallback\<ApplicationInfo> | Yes | Callback used to return the application information.|
**Example**
......@@ -234,8 +230,8 @@ Obtains information about the current application. This API uses a promise to re
**Return value**
| Type | Description |
| ------------------------- | ------------------ |
| Type | Description |
| ------------------------- | --------- |
| Promise\<ApplicationInfo> | Promise used to return the application information.|
**Example**
......@@ -255,15 +251,15 @@ context.getApplicationInfo().then((data) => {
getBundleName(callback: AsyncCallback\<string>): void
Obtains the bundle name of the current ability. This API uses an asynchronous callback to return the result.
Obtains the bundle name of this ability. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ----------------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the bundle name.|
| Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | ------------------ |
| callback | AsyncCallback\<string> | Yes | Callback used to return the bundle name.|
**Example**
......@@ -279,14 +275,14 @@ context.getBundleName()
getBundleName(): Promise\<string>
Obtains the bundle name of the current ability. This API uses a promise to return the result.
Obtains the bundle name of this ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| ---------------- | ------------------------- |
| Type | Description |
| ---------------- | ---------------- |
| Promise\<string> | Promise used to return the bundle name.|
**Example**
......@@ -300,6 +296,225 @@ context.getBundleName().then((data) => {
});
```
## Context.getDisplayOrientation<sup>7+</sup>
getDisplayOrientation(callback: AsyncCallback\<bundle.DisplayOrientation>): void
Obtains the display orientation of this ability. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ------------------ |
| callback | AsyncCallback\<[bundle.DisplayOrientation](js-apis-Bundle.md#displayorientation)> | Yes | Callback used to return the display orientation.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getDisplayOrientation()
```
## Context.getDisplayOrientation<sup>7+</sup>
getDisplayOrientation(): Promise\<bundle.DisplayOrientation>;
Obtains the display orientation of this ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| ---------------------------------------- | --------- |
| Promise\<[bundle.DisplayOrientation](js-apis-Bundle.md#displayorientation)> | Promise used to return the display orientation.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getDisplayOrientation().then((data) => {
console.info("=======================>getDisplayOrientationCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
});
```
## Context.setDisplayOrientation<sup>7+</sup>
setDisplayOrientation(orientation: bundle.DisplayOrientation, callback: AsyncCallback\<void>): void
Sets the display orientation for this ability. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ---------------------------------------- | ---- | ------------ |
| orientation | [bundle.DisplayOrientation](js-apis-Bundle.md#displayorientation) | Yes | Display orientation to set.|
| callback | AsyncCallback\<[bundle.DisplayOrientation](js-apis-Bundle.md#displayorientation)> | Yes | Callback used to return the display orientation. |
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
import bundle from '@ohos.bundle'
var context = featureAbility.getContext();
var orientation=bundle.DisplayOrientation.UNSPECIFIED
context.setDisplayOrientation(orientation, (err) => {
console.log('---------- setDisplayOrientation fail, err: -----------', err);
});
```
## Context.setDisplayOrientation<sup>7+</sup>
setDisplayOrientation(orientation: bundle.DisplayOrientation): Promise\<void>;
Sets the display orientation for this ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| ---------------------------------------- | ---------------------------------------- |
| orientation | [bundle.DisplayOrientation](js-apis-Bundle.md#displayorientation) |
| Promise\<[bundle.DisplayOrientation](js-apis-Bundle.md#displayorientation)> | Promise used to return the display orientation. |
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
import bundle from '@ohos.bundle'
var context = featureAbility.getContext();
var orientation=bundle.DisplayOrientation.UNSPECIFIED
context.setDisplayOrientation(orientation).then((data) => {
console.info("=======================>setDisplayOrientationCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
});
```
## Context.setShowOnLockScreen<sup>7+</sup>
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.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ---------------------------------------- |
| show | boolean | Yes | Whether to show this feature at the top of the lock screen. The value **true** means to show this feature at the top of the lock screen, and **false** means the opposite.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
var show=true
context.setShowOnLockScreen(show, (err) => {
console.log('---------- setShowOnLockScreen fail, err: -----------', err);
});
```
## Context.setShowOnLockScreen<sup>7+</sup>
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.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------- | ---- | ---------------------------------------- |
| show | boolean | Yes | Whether to show this feature at the top of the lock screen. The value **true** means to show this feature at the top of the lock screen, and **false** means the opposite.|
**Return value**
| Type | Description |
| -------------- | --------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
var show=true
context.setShowOnLockScreen(show).then((data) => {
console.info("=======================>setShowOnLockScreenCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
});
```
## Context.setWakeUpScreen<sup>7+</sup>
setWakeUpScreen(wakeUp: boolean, callback: AsyncCallback\<void>): void
Sets whether to wake up the screen when this feature is restored. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | --------------------------------- |
| wakeUp | boolean | Yes | Whether to wake up the screen. The value **true** means to wake up the screen, and **false** means the opposite.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
var wakeUp=true
context.setWakeUpScreen(wakeUp, (err) => {
console.log('---------- setWakeUpScreen fail, err: -----------', err);
});
```
## Context.setWakeUpScreen<sup>7+</sup>
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.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------- | ---- | --------------------------------- |
| wakeUp | boolean | Yes | Whether to wake up the screen. The value **true** means to wake up the screen, and **false** means the opposite.|
**Return value**
| Type | Description |
| -------------- | --------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
var wakeUp=true
context.setWakeUpScreen(wakeUp).then((data) => {
console.info("=======================>setWakeUpScreenCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
});
```
## Context.getProcessInfo<sup>7+</sup>
......@@ -312,9 +527,9 @@ Obtains information about the current process, including the PID and process nam
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | -------------------- |
| callback | AsyncCallback\<ProcessInfo> | Yes | Callback used to return the process information.|
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | ---------- |
| callback | AsyncCallback\<ProcessInfo> | Yes | Callback used to return the process information.|
**Example**
......@@ -336,8 +551,8 @@ Obtains information about the current process, including the PID and process nam
**Return value**
| Type | Description |
| --------------------- | -------------- |
| Type | Description |
| --------------------- | ------- |
| Promise\<ProcessInfo> | Promise used to return the process information.|
**Example**
......@@ -357,7 +572,7 @@ context.getProcessInfo().then((data) => {
getElementName(callback: AsyncCallback\<ElementName>): void
Obtains the **ohos.bundle.ElementName** object of the current ability. This API uses an asynchronous callback to return the result.
Obtains the **ohos.bundle.ElementName** object of this ability. This API uses an asynchronous callback to return the result.
This API is available only to Page abilities.
......@@ -365,9 +580,9 @@ This API is available only to Page abilities.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ---------------------------------------------- |
| callback | AsyncCallback\<ElementName> | Yes | Callback used to return the **ohos.bundle.ElementName** object.|
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback\<ElementName> | Yes | Callback used to return the **ohos.bundle.ElementName** object.|
**Example**
......@@ -383,7 +598,7 @@ context.getElementName()
getElementName(): Promise\<ElementName>
Obtains the **ohos.bundle.ElementName** object of the current ability. This API uses a promise to return the result.
Obtains the **ohos.bundle.ElementName** object of this ability. This API uses a promise to return the result.
This API is available only to Page abilities.
......@@ -391,8 +606,8 @@ This API is available only to Page abilities.
**Return value**
| Type | Description |
| --------------------- | ------------------------------------------ |
| Type | Description |
| --------------------- | ------------------------------------ |
| Promise\<ElementName> | Promise used to return the **ohos.bundle.ElementName** object.|
**Example**
......@@ -416,9 +631,9 @@ Obtains the name of the current process. This API uses an asynchronous callback
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the process name.|
| Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | ---------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the process name.|
**Example**
......@@ -440,8 +655,8 @@ Obtains the name of the current process. This API uses a promise to return the r
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Type | Description |
| ---------------- | ---------- |
| Promise\<string> | Promise used to return the process name.|
**Example**
......@@ -467,9 +682,9 @@ Obtains the bundle name of the calling ability. This API uses an asynchronous ca
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the bundle name.|
| Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | ---------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the bundle name.|
**Example**
......@@ -491,8 +706,8 @@ Obtains the bundle name of the calling ability. This API uses a promise to retur
**Return value**
| Type | Description |
| --------------- | ------------------------- |
| Type | Description |
| ---------------- | -------------- |
| Promise\<string> | Promise used to return the bundle name.|
**Example**
......@@ -510,15 +725,15 @@ context.getCallingBundle().then((data) => {
getCacheDir(callback: AsyncCallback\<string>): void
Obtains the cache directory of the application on the internal storage. This API uses an asynchronous callback to return the result.
Obtains the cache directory of the application in the internal storage. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the cache directory.|
| Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | --------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the cache directory.|
**Example**
......@@ -538,14 +753,14 @@ context.getCacheDir((err, data) => {
getCacheDir(): Promise\<string>
Obtains the cache directory of the application on the internal storage. This API uses a promise to return the result.
Obtains the cache directory of the application in the internal storage. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| --------------- | ------------------------- |
| Type | Description |
| ---------------- | --------------- |
| Promise\<string> | Promise used to return the cache directory.|
**Example**
......@@ -563,15 +778,15 @@ context.getCacheDir().then((data) => {
getFilesDir(callback: AsyncCallback\<string>): void
Obtains the file directory of the application on the internal storage. This API uses an asynchronous callback to return the result.
Obtains the file directory of the application in the internal storage. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the file directory.|
| Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | ------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the file directory.|
**Example**
......@@ -591,14 +806,14 @@ context.getFilesDir((err, data) => {
getFilesDir(): Promise\<string>
Obtains the file directory of the application on the internal storage. This API uses a promise to return the result.
Obtains the file directory of the application in the internal storage. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| --------------- | ------------------------- |
| Type | Description |
| ---------------- | ------------------- |
| Promise\<string> | Promise used to return the file directory.|
**Example**
......@@ -624,9 +839,9 @@ If the distributed file path does not exist, the system will create one and retu
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the distributed file path. If the distributed file path does not exist, the system will create one and return the created path.|
| Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the distributed file path. If the distributed file path does not exist, the system will create one and return the created path.|
**Example**
......@@ -654,8 +869,8 @@ If the distributed file path does not exist, the system will create one and retu
**Return value**
| Type | Description |
| --------------- | ------------------------- |
| Type | Description |
| ---------------- | ----------------------------------- |
| Promise\<string> | Promise used to return the distributed file path. If this API is called for the first time, a new path will be created.|
**Example**
......@@ -678,9 +893,9 @@ Obtains the application type. This API uses an asynchronous callback to return t
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the application type.|
| Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | -------------------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the application type.|
**Example**
......@@ -706,8 +921,8 @@ Obtains the application type. This API uses a promise to return the result.
**Return value**
| Type | Description |
| --------------- | ------------------------- |
| Type | Description |
| ---------------- | ------------------ |
| Promise\<string> | Promise used to return the application type.|
**Example**
......@@ -730,9 +945,9 @@ Obtains the **ModuleInfo** object of the application. This API uses an asynchron
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------- |
| callback | AsyncCallback\<[HapModuleInfo](#hapmoduleinfo)> | Yes | Callback used to return the **ModuleInfo** object.|
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
| callback | AsyncCallback\<[HapModuleInfo](js-apis-bundle-HapModuleInfo.md)> | Yes | Callback used to return the **ModuleInfo** object.|
**Example**
......@@ -758,9 +973,9 @@ Obtains the **ModuleInfo** object of the application. This API uses a promise to
**Return value**
| Type | Description |
| --------------- | ------------------------- |
| Promise\<[HapModuleInfo](#hapmoduleinfo)> | Promise used to return the **ModuleInfo** object.|
| Type | Description |
| ---------------------------------------- | ------------------ |
| Promise\<[HapModuleInfo](js-apis-bundle-HapModuleInfo.md)> | Promise used to return the **ModuleInfo** object.|
**Example**
......@@ -774,17 +989,17 @@ context.getHapModuleInfo().then((data) => {
## Context.getAppVersionInfo<sup>7+</sup>
getAppVersionInfo(callback: AsyncCallback\<HapModuleInfo>): void
getAppVersionInfo(callback: AsyncCallback\<AppVersionInfo>): void
Obtains the version information of the application. This API uses an asynchronous callback to return the result.
Obtains the version information of this application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------- |
| callback | AsyncCallback\<[AppVersionInfo](#appversioninfo)> | Yes | Callback used to return the version information.|
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------ |
| callback | AsyncCallback\<[AppVersionInfo](#appversioninfo)> | Yes | Callback used to return the version information.|
**Example**
......@@ -804,14 +1019,14 @@ context.getAppVersionInfo((err, data) => {
getAppVersionInfo(): Promise\<AppVersionInfo>
Obtains the version information of the application. This API uses a promise to return the result.
Obtains the version information of this application. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| --------------- | ------------------------- |
| Type | Description |
| ---------------------------------------- | --------- |
| Promise\<[AppVersionInfo](#appversioninfo)> | Promise used to return the version information.|
**Example**
......@@ -828,15 +1043,15 @@ context.getAppVersionInfo().then((data) => {
getAbilityInfo(callback: AsyncCallback\<AbilityInfo>): void
Obtains information of the current ability. This API uses an asynchronous callback to return the result.
Obtains information about this ability. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------- |
| callback | AsyncCallback\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)> | Yes | Callback used to return the ability information.|
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
| callback | AsyncCallback\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)> | Yes | Callback used to return the ability information.|
**Example**
......@@ -856,14 +1071,14 @@ context.getAbilityInfo((err, data) => {
getAbilityInfo(): Promise\<AbilityInfo>
Obtains information of the current ability. This API uses a promise to return the result.
Obtains information about this ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| --------------- | ------------------------- |
| Type | Description |
| ---------------------------------------- | ------------------ |
| Promise\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)> | Promise used to return the ability information.|
**Example**
......@@ -886,9 +1101,9 @@ Obtains the context of the application.
**Return value**
| Type | Description |
| --------- |------ |
| Context | Application context.|
| Type | Description |
| ------- | ---------- |
| Context | Application context.|
**Example**
......@@ -897,52 +1112,136 @@ import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext().getApplicationContext();
```
## Context.isUpdatingConfigurations<sup>7+</sup>
isUpdatingConfigurations(callback: AsyncCallback\<boolean>): void;
Checks whether the configuration of this ability is being updated. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------- | ---- | ----------------------------- |
| callback | AsyncCallback\<boolean> | Yes | Returns **true** if the configuration of the capability is being updated; returns **false** otherwise.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.isUpdatingConfigurations((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
});
```
## Context.isUpdatingConfigurations<sup>7+</sup>
isUpdatingConfigurations(): Promise\<boolean>;
Checks whether the configuration of this ability is being updated. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| ----------------- | ----------------------------- |
| Promise\<boolean> | Returns **true** if the configuration of the capability is being updated; returns **false** otherwise.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.isUpdatingConfigurations().then((data) => {
console.info("====>data====>" + JSON.stringify(data));
});
```
## Context.printDrawnCompleted<sup>7+</sup>
printDrawnCompleted(callback: AsyncCallback\<void>): void;
Notifies the system of the time required to draw this page function. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ----------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.printDrawnCompleted((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
});
```
## Context.printDrawnCompleted<sup>7+</sup>
printDrawnCompleted(): Promise\<void>;
Notifies the system of the time required to draw this page function. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| -------------- | --------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.printDrawnCompleted().then((data) => {
console.info("====>data====>" + JSON.stringify(data));
});
```
## PermissionOptions<sup>7+</sup>
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Readable/Writable| Type | Mandatory| Description |
| ---- | -------- | ------ | ---- | ------ |
| pid | Read-only | number | No | Process ID.|
| uid | Read-only | number | No | User ID.|
| Name | Readable/Writable| Type | Mandatory | Description |
| ---- | ---- | ------ | ---- | ----- |
| pid | Read-only | number | No | Process ID.|
| uid | Read-only | number | No | User ID.|
## PermissionRequestResult<sup>7+</sup>
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Readable/Writable| Type | Mandatory| Description |
| ----------- | -------- | -------------- | ---- | ------------------ |
| requestCode | Read-only | number | Yes | Request code passed.|
| permissions | Read-only | Array\<string> | Yes | Permissions requested. |
| authResults | Read-only | Array\<number> | Yes | Permission request result. |
## HapModuleInfo<sup>7+</sup>
Describes the HAP module information.
| Name | Type| Readable| Writable| Description|
| ------ | ------ | ------ | ------ | ------ |
| name | string | Yes | No | Module name. |
| description | string | Yes | No | Module description. |
| descriptionId | number | Yes | No | Module description ID. |
| icon | string | Yes | No | Module icon. |
| label | string | Yes | No | Module label. |
| labelId | number | Yes | No | Module label ID. |
| iconId | number | Yes | No | Module icon ID. |
| backgroundImg | string | Yes | No | Module background image. |
| supportedModes | number | Yes | No | Running modes supported by the module. |
| reqCapabilities | Array\<string> | Yes | No | Capabilities required for module running.|
| deviceTypes | Array\<string> | Yes | No | Device types supported by the module.|
| abilityInfo | Array\<AbilityInfo> | Yes | No | Ability information. |
| moduleName | string | Yes | No | Module name. |
| mainAbilityName | string | Yes | No | Name of the main ability. |
| installationFree | boolean | Yes | No | Whether installation-free is supported. |
| mainElementName | string | Yes| No| Information about the main ability.|
| Name | Readable/Writable| Type | Mandatory | Description |
| ----------- | ---- | -------------- | ---- | ---------- |
| requestCode | Read-only | number | Yes | Request code passed.|
| permissions | Read-only | Array\<string> | Yes | Permissions requested. |
| authResults | Read-only | Array\<number> | Yes | Permission request result. |
## AppVersionInfo<sup>7+</sup>
| Name | Type| Readable | Writable | Description|
| ------ | ------ | ------| ------ | ------ |
| appName | string | Yes | No | Module name. |
| versionCode | number | Yes | No | Module description. |
| versionName | string | Yes | No | Module description ID. |
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Readable | Writable | Description |
| ----------- | ------ | ---- | ---- | ------- |
| appName | string | Yes | No | Module name. |
| versionCode | number | Yes | No | Module description.|
| versionName | string | Yes | No | Module description ID.|
# AbilityContext
The **AbilityContext** module, inherited from **Context**, implements the context for abilities.
This module provides APIs for accessing ability-specific resources. You can use the APIs to start and terminate an ability, obtain the caller interface, and request permissions from users by displaying a dialog box.
> **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 APIs of this module can be used only in the stage model.
Implements the ability context. This module is inherited from **Context**.
## Modules to Import
```js
import Ability from '@ohos.application.Ability'
```
## Usage
Before using the **AbilityContext** module, you must define a child class that inherits from **Ability**.
......@@ -25,7 +22,6 @@ class MainAbility extends Ability {
}
```
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -34,13 +30,13 @@ class MainAbility extends Ability {
| -------- | -------- | -------- | -------- | -------- |
| abilityInfo | AbilityInfo | Yes| No| Ability information.|
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.|
| config | [Configuration](js-apis-configuration.md) | Yes| No| Configuration information.|
## AbilityContext.startAbility
startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void
Starts an ability. This API uses a callback to return the result.
Starts an ability. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -48,7 +44,7 @@ Starts an ability. This API uses a callback to return the result.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example**
......@@ -69,7 +65,7 @@ Starts an ability. This API uses a callback to return the result.
startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&gt;): void
Starts an ability. This API uses a callback to return the result.
Starts an ability with start options specified. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -77,7 +73,7 @@ Starts an ability. This API uses a callback to return the result.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| options | [StartOptions](js-apis-application-StartOptions.md) | Yes| Parameters used for starting the ability.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
......@@ -110,7 +106,7 @@ Starts an ability. This API uses a promise to return the result.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| options | [StartOptions](js-apis-application-StartOptions.md) | No| Parameters used for starting the ability.|
**Return value**
......@@ -143,7 +139,7 @@ Starts an ability. This API uses a promise to return the result.
startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;): void;
Starts an ability. This API uses a callback to return the result when the ability is terminated.
Starts an ability. This API uses an asynchronous callback to return the result when the ability is terminated.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -151,7 +147,7 @@ Starts an ability. This API uses a callback to return the result when the abilit
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
| want |[Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
......@@ -171,7 +167,7 @@ Starts an ability. This API uses a callback to return the result when the abilit
startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback&lt;AbilityResult&gt;): void;
Starts an ability. This API uses a callback to return the result when the ability is terminated.
Starts an ability with start options specified. This API uses an asynchronous callback to return the result when the ability is terminated.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -179,7 +175,7 @@ Starts an ability. This API uses a callback to return the result when the abilit
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
| want |[Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| options | [StartOptions](js-apis-application-StartOptions.md) | Yes| Parameters used for starting the ability.|
| callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
......@@ -212,7 +208,7 @@ Starts an ability. This API uses a promise to return the result when the ability
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| options | [StartOptions](js-apis-application-StartOptions.md) | No| Parameters used for starting the ability.|
......@@ -235,12 +231,398 @@ Starts an ability. This API uses a promise to return the result when the ability
})
```
## AbilityContext.startAbilityForResultWithAccount
startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncCallback\<AbilityResult>): void;
Starts an ability. This API uses an asynchronous callback to return the result when the account of the ability is destroyed.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<AbilityResult\> | Yes| Callback used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
this.context.startAbilityWithAccount(want, accountId, (err, data) => {
console.log('---------- startAbilityWithAccount fail, err: -----------', err);
console.log('---------- startAbilityWithAccount success, data: -----------', data);
});
```
## AbilityContext.startAbilityForResultWithAccount
startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback\<void\>): void;
Starts an ability with start options specified. This API uses an asynchronous callback to return the result when the account of the ability is destroyed.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| options | [StartOptions](js-apis-application-StartOptions.md) | Yes| Parameters used for starting the ability.|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
var options = {
windowMode: 0,
};
this.context.startAbilityForResultWithAccount(want, accountId, options, (err) => {
console.log('---------- startAbilityForResultWithAccount fail, err: -----------', err);
});
```
## AbilityContext.startAbilityForResultWithAccount
startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartOptions): Promise\<AbilityResult\>;
Starts an ability with start options specified. This API uses a promise to return the result when the account of the ability is destroyed.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| options | [StartOptions](js-apis-application-StartOptions.md) | No| Parameters used for starting the ability.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;AbilityResult&gt; | Promise used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
var options = {
windowMode: 0,
};
this.context.startAbilityForResultWithAccount(want, accountId, options)
.then((data) => {
console.log('---------- startAbilityForResultWithAccount success, data: -----------', data);
})
.catch((err) => {
console.log('---------- startAbilityForResultWithAccount fail, err: -----------', err);
})
```
## AbilityContext.startServiceExtensionAbility
startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
Starts a new Service Extension ability. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
this.context.startServiceExtensionAbility(want, (err) => {
console.log('---------- startServiceExtensionAbility fail, err: -----------', err);
});
```
## AbilityContext.startServiceExtensionAbility
startServiceExtensionAbility(want: Want): Promise\<void>;
Starts a new Service Extension ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
this.context.startServiceExtensionAbility(want)
.then((data) => {
console.log('---------- startServiceExtensionAbility success, data: -----------', data);
})
.catch((err) => {
console.log('---------- startServiceExtensionAbility fail, err: -----------', err);
})
```
## AbilityContext.startServiceExtensionAbilityWithAccount
startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void>): void;
Starts a new Service Extension ability with the account ID specified. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
this.context.startServiceExtensionAbilityWithAccount(want,accountId, (err) => {
console.log('---------- startServiceExtensionAbilityWithAccount fail, err: -----------', err);
});
```
## AbilityContext.startServiceExtensionAbilityWithAccount
startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<void>;
Starts a new Service Extension ability with the account ID specified. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
this.context.startServiceExtensionAbilityWithAccount(want,accountId)
.then((data) => {
console.log('---------- startServiceExtensionAbilityWithAccount success, data: -----------', data);
})
.catch((err) => {
console.log('---------- startServiceExtensionAbilityWithAccount fail, err: -----------', err);
})
```
## AbilityContext.stopServiceExtensionAbility
stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
Stops a Service Extension ability in the same application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
this.context.stopServiceExtensionAbility(want, (err) => {
console.log('---------- stopServiceExtensionAbility fail, err: -----------', err);
});
```
## AbilityContext.stopServiceExtensionAbility
stopServiceExtensionAbility(want: Want): Promise\<void>;
Stops a Service Extension ability in the same application. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
this.context.stopServiceExtensionAbility(want)
.then((data) => {
console.log('---------- stopServiceExtensionAbility success, data: -----------', data);
})
.catch((err) => {
console.log('---------- stopServiceExtensionAbility fail, err: -----------', err);
})
```
## AbilityContext.stopServiceExtensionAbilityWithAccount
stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void>): void;
Stops a Service Extension ability in the same application with the account ID specified. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
this.context.stopServiceExtensionAbilityWithAccount(want,accountId, (err) => {
console.log('---------- stopServiceExtensionAbilityWithAccount fail, err: -----------', err);
});
```
## AbilityContext.stopServiceExtensionAbilityWithAccount
stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<void>;
Stops a Service Extension ability in the same application with the account ID specified. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
this.context.stopServiceExtensionAbilityWithAccount(want,accountId)
.then((data) => {
console.log('---------- stopServiceExtensionAbilityWithAccount success, data: -----------', data);
})
.catch((err) => {
console.log('---------- stopServiceExtensionAbilityWithAccount fail, err: -----------', err);
})
```
## AbilityContext.terminateSelf
terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
Terminates this ability. This API uses a callback to return the result.
Terminates this ability. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -248,7 +630,7 @@ Terminates this ability. This API uses a callback to return the result.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example**
......@@ -271,12 +653,12 @@ Terminates this ability. This API uses a promise to return the result.
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
this.context.terminateSelf(want).then((data) => {
this.context.terminateSelf().then((data) => {
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
......@@ -288,7 +670,7 @@ Terminates this ability. This API uses a promise to return the result.
terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;void&gt;): void;
Terminates this ability. This API uses a callback to return the information to the caller of **startAbilityForResult**.
Terminates this ability. This API uses an asynchronous callback to return the information to the caller of **startAbilityForResult**.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -317,7 +699,7 @@ Terminates this ability. This API uses a callback to return the information to t
terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;;
Terminates this ability. This API uses a promise to return information to the caller of **startAbilityForResult**.
Terminates this ability. This API uses a promise to return the information to the caller of **startAbilityForResult**.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -346,6 +728,149 @@ Terminates this ability. This API uses a promise to return information to the ca
)
```
## AbilityContext.connectAbility
connectAbility(want: Want, options: ConnectOptions): number;
Uses the **AbilityInfo.AbilityType.SERVICE** template to connect this ability to another ability.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| options | [ConnectOptions](js-apis-featureAbility.md#connectoptions) | No| Parameters for the connection.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Result code of the ability connection.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var options = {
onConnect(elementName, remote) { console.log('----------- onConnect -----------') },
onDisconnect(elementName) { console.log('----------- onDisconnect -----------') },
onFailed(code) { console.log('----------- onFailed -----------') }
}
const result = this.context.connectAbility(want, options);
console.log('----------- connectAbilityResult: ------------', result);
```
## AbilityContext.connectAbilityWithAccount
connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions): number;
Uses the **AbilityInfo.AbilityType.SERVICE** template and account ID to connect this ability to another ability with the account ID specified.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| options | [ConnectOptions](js-apis-featureAbility.md#connectoptions) | No| Parameters for the connection.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Result code of the ability connection.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
var options = {
onConnect(elementName, remote) { console.log('----------- onConnect -----------') },
onDisconnect(elementName) { console.log('----------- onDisconnect -----------') },
onFailed(code) { console.log('----------- onFailed -----------') }
}
const result = this.context.connectAbilityWithAccount(want, accountId, options);
console.log('----------- connectAbilityResult: ------------', result);
```
## AbilityContext.disconnectAbility
disconnectAbility(connection: number): Promise\<void>;
Disconnects a connection. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| connection | number | Yes| Result code of the ability connection.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
var connectionNumber = 0;
this.context.disconnectAbility(connectionNumber).then((data) => {
console.log('disconnectAbility success, data: ', data);
}).catch((err) => {
console.log('disconnectAbility fail, err: ', err);
});
```
## AbilityContext.disconnectAbility
disconnectAbility(connection: number, callback:AsyncCallback\<void>): void;
Disconnects a connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| connection | number | Yes| Result code of the ability connection.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
**Example**
```js
var connectionNumber = 0;
this.context.disconnectAbility(connectionNumber, (err) => {
console.log('---------- disconnectAbility fail, err: -----------', err);
});
```
## AbilityContext.startAbilityByCall
......@@ -359,7 +884,7 @@ Obtains the caller interface of the specified ability, and if the specified abil
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the ability to start, including the ability name, bundle name, and device ID. If the device ID is left blank or the default value is used, the local ability will be started.|
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability, including the ability name, bundle name, and device ID. If the device ID is left blank or the default value is used, it indicates the local device.|
**Return value**
......@@ -388,12 +913,126 @@ Obtains the caller interface of the specified ability, and if the specified abil
}
```
## AbilityContext.startAbilityWithAccount
startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void\>): void;
Starts an ability with the account ID specified. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
this.context.startAbilityWithAccount(want, accountId, (err) => {
console.log('---------- startAbilityWithAccount fail, err: -----------', err);
});
```
## AbilityContext.startAbilityWithAccount
startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback\<void\>): void;
Starts an ability with the account ID and start options specified. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| options | [StartOptions](js-apis-application-StartOptions.md) | No| Parameters used for starting the ability.|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
var options = {
windowMode: 0,
};
this.context.startAbilityWithAccount(want, accountId, options, (err) => {
console.log('---------- startAbilityWithAccount fail, err: -----------', err);
});
```
## AbilityContext.startAbilityWithAccount
startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions): Promise\<void\>;
Starts an ability with the account ID specified. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| options | [StartOptions](js-apis-application-StartOptions.md) | No| Parameters used for starting the ability.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
var options = {
windowMode: 0,
};
this.context.startAbilityWithAccount(want, accountId, options)
.then((data) => {
console.log('---------- startAbilityWithAccount success, data: -----------', data);
})
.catch((err) => {
console.log('---------- startAbilityWithAccount fail, err: -----------', err);
})
```
## AbilityContext.requestPermissionsFromUser
requestPermissionsFromUser(permissions: Array&lt;string&gt;, requestCallback: AsyncCallback&lt;PermissionRequestResult&gt;) : void;
Requests permissions from the user by displaying a pop-up window. This API uses a callback to return the result.
Requests permissions from the user by displaying a dialog box. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -402,7 +1041,7 @@ Requests permissions from the user by displaying a pop-up window. This API uses
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| Permissions to request.|
| callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.|
| callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result.|
**Example**
......@@ -419,7 +1058,7 @@ Requests permissions from the user by displaying a pop-up window. This API uses
requestPermissionsFromUser(permissions: Array&lt;string&gt;) : Promise&lt;PermissionRequestResult&gt;;
Requests permissions from the user by displaying a pop-up window. This API uses a promise to return the result.
Requests permissions from the user by displaying a dialog box. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -433,7 +1072,7 @@ Requests permissions from the user by displaying a pop-up window. This API uses
| Type| Description|
| -------- | -------- |
| Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result indicating whether the API is successfully called.|
| Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result.|
**Example**
......@@ -452,7 +1091,7 @@ Requests permissions from the user by displaying a pop-up window. This API uses
setMissionLabel(label: string, callback:AsyncCallback&lt;void&gt;): void;
Sets the label of the ability in the mission. This API uses an asynchronous callback to return the result.
Sets a label for this ability in the mission. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -461,7 +1100,7 @@ Sets the label of the ability in the mission. This API uses an asynchronous call
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| label | string | Yes| Label of the ability to set.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example**
......@@ -476,7 +1115,7 @@ Sets the label of the ability in the mission. This API uses an asynchronous call
setMissionLabel(label: string): Promise&lt;void&gt;
Sets the label of the ability in the mission. This API uses a promise to return the result.
Sets a label for this ability in the mission. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -490,7 +1129,7 @@ Sets the label of the ability in the mission. This API uses a promise to return
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
......@@ -501,6 +1140,117 @@ Sets the label of the ability in the mission. This API uses a promise to return
console.log('failed:' + JSON.stringify(error));
});
```
## AbilityContext.setMissionIcon
setMissionIcon(icon: image.PixelMap, callback:AsyncCallback\<void>): void;
Sets an icon for this ability in the mission. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| icon | image.PixelMap | Yes| Icon of the ability to set.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
**Example**
```js
import image from '@ohos.multimedia.image'
var imagePixelMap;
var color = new ArrayBuffer(0);
var initializationOptions = {
size: {
height: 100,
width: 100
}
};
image.createPixelMap(color, initializationOptions)
.then((data) => {
imagePixelMap = data;
})
.catch((err) => {
console.log('--------- createPixelMap fail, err: ---------', err)
});
this.context.setMissionIcon(imagePixelMap, (err) => {
console.log('---------- setMissionIcon fail, err: -----------', err);
})
```
## AbilityContext.setMissionIcon
setMissionIcon(icon: image.PixelMap): Promise\<void>;
Sets an icon for this ability in the mission. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| icon | image.PixelMap | Yes| Icon of the ability to set.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
import image from '@ohos.multimedia.image'
var imagePixelMap;
var color = new ArrayBuffer(0);
var initializationOptions = {
size: {
height: 100,
width: 100
}
};
image.createPixelMap(color, initializationOptions)
.then((data) => {
imagePixelMap = data;
})
.catch((err) => {
console.log('--------- createPixelMap fail, err: ---------', err)
});
this.context.setMissionIcon(imagePixelMap)
.then((data) => {
console.log('-------------- setMissionIcon success, data: -------------', data);
})
.catch((err) => {
console.log('-------------- setMissionIcon fail, err: -------------', err);
});
```
## AbilityContext.restoreWindowStage
restoreWindowStage(localStorage: LocalStorage) : void;
Restores the window stage data for this ability.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| localStorage | image.LocalStorage | Yes| Storage used to store the restored window stage.|
**Example**
```js
var storage = new LocalStorage();
this.context.restoreWindowStage(storage);
```
## AbilityContext.isTerminating
......@@ -514,7 +1264,7 @@ Checks whether this ability is in the terminating state.
| Type| Description|
| -------- | -------- |
| bool | The value **true** means that the ability is in terminating state, and **false** means the opposite.|
| boolean| The value **true** means that the ability is in the terminating state, and **false** means the opposite.|
**Example**
......
# wantConstant
The **wantConstant** module provides the actions, entities, and flags used in **Want** objects.
> **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 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
......@@ -12,73 +14,75 @@ import wantConstant from '@ohos.ability.wantConstant'
## wantConstant.Action
**System capability**: SystemCapability.Ability.AbilityBase
Enumerates the action constants of the **Want** object.
Lists the permissions.
**System capability**: SystemCapability.Ability.AbilityBase
| Common Event Macro | Common Event Name | Subscriber Permission |
| Name | Value | Description |
| ------------ | ------------------ | ---------------------- |
| ACTION_HOME | ohos.want.action.home | None |
| ACTION_DIAL | ohos.want.action.dial | None |
| ACTION_SEARCH | ohos.want.action.search | None |
| ACTION_WIRELESS_SETTINGS | ohos.settings.wireless | None |
| ACTION_MANAGE_APPLICATIONS_SETTINGS | ohos.settings.manage.applications | None |
| ACTION_APPLICATION_DETAILS_SETTINGS | ohos.settings.application.details | None |
| ACTION_SET_ALARM | ohos.want.action.setAlarm | None |
| ACTION_SHOW_ALARMS | ohos.want.action.showAlarms | None |
| ACTION_SNOOZE_ALARM | ohos.want.action.snoozeAlarm | None |
| ACTION_DISMISS_ALARM | ohos.want.action.dismissAlarm | None |
| ACTION_DISMISS_TIMER | ohos.want.action.dismissTimer | None |
| ACTION_SEND_SMS | ohos.want.action.sendSms | None |
| ACTION_CHOOSE | ohos.want.action.choose | None |
| ACTION_IMAGE_CAPTURE<sup>8+</sup> | ohos.want.action.imageCapture | None |
| ACTION_VIDEO_CAPTUR<sup>8+</sup> | ohos.want.action.videoCapture | None |
| ACTION_SELECT | ohos.want.action.select | None |
| ACTION_SEND_DATA | ohos.want.action.sendData | None |
| ACTION_SEND_MULTIPLE_DATA | ohos.want.action.sendMultipleData | None |
| ACTION_SCAN_MEDIA_FILE | ohos.want.action.scanMediaFile | None |
| ACTION_VIEW_DATA | ohos.want.action.viewData | None |
| ACTION_EDIT_DATA | ohos.want.action.editData | None |
| INTENT_PARAMS_INTENT | ability.want.params.INTENT | None |
| INTENT_PARAMS_TITLE | ability.want.params.TITLE | None |
| ACTION_FILE_SELECT<sup>7+</sup> | ohos.action.fileSelect | None |
| PARAMS_STREAM<sup>7+</sup> | ability.params.stream | None |
| ACTION_APP_ACCOUNT_OAUTH <sup>8+</sup> | ohos.account.appAccount.action.oauth | None |
| ACTION_HOME | ohos.want.action.home | Action of returning to the home page. |
| ACTION_DIAL | ohos.want.action.dial | Action of launching the numeric keypad. |
| ACTION_SEARCH | ohos.want.action.search | Action of launching the search function. |
| ACTION_WIRELESS_SETTINGS | ohos.settings.wireless | Action of launching the UI that provides wireless network settings, for example, Wi-Fi options. |
| ACTION_MANAGE_APPLICATIONS_SETTINGS | ohos.settings.manage.applications | Action of launching the UI for managing installed applications. |
| ACTION_APPLICATION_DETAILS_SETTINGS | ohos.settings.application.details | Action of launching the UI that displays the details of an application. |
| ACTION_SET_ALARM | ohos.want.action.setAlarm | Action of launching the UI for setting the alarm clock. |
| ACTION_SHOW_ALARMS | ohos.want.action.showAlarms | Action of launching the UI that displays all alarms. |
| ACTION_SNOOZE_ALARM | ohos.want.action.snoozeAlarm | Action of launching the UI for snoozing an alarm. |
| ACTION_DISMISS_ALARM | ohos.want.action.dismissAlarm | Action of launching the UI for deleting an alarm. |
| ACTION_DISMISS_TIMER | ohos.want.action.dismissTimer | Action of launching the UI for dismissing a timer. |
| ACTION_SEND_SMS | ohos.want.action.sendSms | Action of launching the UI for sending an SMS message. |
| ACTION_CHOOSE | ohos.want.action.choose | Action of launching the UI for openning a contact or picture. |
| ACTION_IMAGE_CAPTURE<sup>8+</sup> | ohos.want.action.imageCapture | Action of launching the UI for photographing. |
| ACTION_VIDEO_CAPTURE<sup>8+</sup> | ohos.want.action.videoCapture | Action of launching the UI for shooting a video. |
| ACTION_SELECT | ohos.want.action.select | Action of launching the UI for application selection. |
| ACTION_SEND_DATA | ohos.want.action.sendData | Action of launching the UI for sending a single data record. |
| ACTION_SEND_MULTIPLE_DATA | ohos.want.action.sendMultipleData | Action of launching the UI for sending multiple data records. |
| ACTION_SCAN_MEDIA_FILE | ohos.want.action.scanMediaFile | Action of requesting a media scanner to scan a file and add the file to the media library. |
| ACTION_VIEW_DATA | ohos.want.action.viewData | Action of viewing data. |
| ACTION_EDIT_DATA | ohos.want.action.editData | Action of editing data. |
| INTENT_PARAMS_INTENT | ability.want.params.INTENT | Action of displaying selection options with an action selector. |
| INTENT_PARAMS_TITLE | ability.want.params.TITLE | Title of the character sequence dialog box used with the action selector. |
| ACTION_FILE_SELECT<sup>7+</sup> | ohos.action.fileSelect | Action of selecting a file. |
| PARAMS_STREAM<sup>7+</sup> | ability.params.stream | URI of the data stream associated with the target when the data is sent. |
| ACTION_APP_ACCOUNT_OAUTH <sup>8+</sup> | ohos.account.appAccount.action.oauth | Action of providing the OAuth service. |
| ACTION_MARKER_DOWNLOAD <sup>9+</sup> | ohos.want.action.marketDownload | Action of downloading an application from the application market.<br>**System API**: This is a system API and cannot be called by third-party applications. |
## wantConstant.Entity
**System capability**: SystemCapability.Ability.AbilityBase
Enumerates the entity constants of the **Want** object.
Lists the permissions.
**System capability**: SystemCapability.Ability.AbilityBase
| Common Event Macro | Common Event Name | Subscriber Permission |
| Name | Value | Description |
| ------------ | ------------------ | ---------------------- |
| ENTITY_DEFAULT | entity.system.default | None |
| ENTITY_HOME | entity.system.homel | None |
| ENTITY_VOICE | ENTITY_VOICE | None |
| ENTITY_BROWSABLE | entity.system.browsable | None |
| ENTITY_VIDEO | entity.system.video | None |
| ACTION_APPLICATION_DETAILS_SETTINGS | ohos.settings.application.details | None |
| ENTITY_DEFAULT | entity.system.default | Default entity. The default entity is used if no entity is specified. |
| ENTITY_HOME | entity.system.home | Home screen entity. |
| ENTITY_VOICE | entity.system.voice | Voice interaction entity. |
| ENTITY_BROWSABLE | entity.system.browsable | Browser type entity. |
| ENTITY_VIDEO | entity.system.video | Video type entity. |
## wantConstant.Flags
## flags
Describes flags.
**System capability**: SystemCapability.Ability.AbilityBase
| Name | Value | Description |
| ------------------------------------ | ---------- | ------------------------------------------------------------ |
| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Indicates the permission to read the URI. |
| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Indicates the permission to write the URI. |
| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Indicates the permission to write data to the URI. |
| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | Returns the result to the ability. |
| FLAG_ABILITY_CONTINUATION | 0x00000008 | Indicates whether the ability on the local device can be continued on a remote device. |
| FLAG_NOT_OHOS_COMPONENT | 0x00000010 | Indicates that a component does not belong to OHOS. |
| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | Indicates that an ability is enabled. |
| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Indicates the permission to make the URI persistent. |
| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | Indicates the permission to verify URIs by prefix matching. |
| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Indicates the permission to make the URI persistent.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | Indicates the permission to verify URIs by prefix matching.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | Supports cross-device startup in a distributed scheduler. |
| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | Indicates that the Service ability is started regardless of whether the host application has been started. |
| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that ability continuation is reversible. |
| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that ability continuation is reversible.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| FLAG_INSTALL_ON_DEMAND | 0x00000800 | Indicates that the specific ability will be installed if it has not been installed. |
| FLAG_INSTALL_WITH_BACKGROUND_MODE | 0x80000000 | Indicates that the specific ability will be installed in the background if it has not been installed. |
| FLAG_ABILITY_CLEAR_MISSION | 0x00008000 | Clears other operation missions. This flag can be set for the **Want** object in the **startAbility** API passed to [ohos.app.Context](js-apis-ability-context.md) and must be used together with **flag_ABILITY_NEW_MISSION**.|
......
# appManager
The **appManager** module implements application management. You can use the APIs of this module to query whether the application is undergoing a stability test, whether the application is running on a RAM constrained device, the memory size of the application, and information about the running process.
> **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.
Implements application management.
## Modules to Import
```js
import app from '@ohos.application.appManager';
```
## appManager.isRunningInStabilityTest<sup>8+</sup>
static isRunningInStabilityTest(callback: AsyncCallback&lt;boolean&gt;): void
......@@ -26,9 +22,9 @@ Checks whether this application is undergoing a stability test. This API uses an
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
**Example**
......@@ -50,9 +46,9 @@ Checks whether this application is undergoing a stability test. This API uses a
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
**Example**
......@@ -76,9 +72,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
**Example**
......@@ -100,9 +96,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
**Example**
......@@ -123,9 +119,9 @@ Obtains the memory size of this application. This API uses a promise to return t
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Size of the application memory.|
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Size of the application memory.|
**Example**
......@@ -147,9 +143,9 @@ Obtains the memory size of this application. This API uses an asynchronous callb
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | No| Size of the application memory.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | No| Size of the application memory.|
**Example**
......@@ -165,6 +161,8 @@ getProcessRunningInfos(): Promise\<Array\<ProcessRunningInfo>>;
Obtains information about the running processes. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
......@@ -189,6 +187,8 @@ getProcessRunningInfos(callback: AsyncCallback\<Array\<ProcessRunningInfo>>): vo
Obtains information about the running processes. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
......@@ -206,13 +206,533 @@ Obtains information about the running processes. This API uses an asynchronous c
})
```
## ProcessRunningInfo
## appManager.registerApplicationStateObserver<sup>8+</sup>
registerApplicationStateObserver(observer: ApplicationStateObserver): number;
Registers the application state observer.
**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| observer | ApplicationStateObserver | No| Numeric code of the observer.|
**Example**
```js
var applicationStateObserver = {
onForegroundApplicationChanged(appStateData) {
console.log('------------ onForegroundApplicationChanged -----------', appStateData);
},
onAbilityStateChanged(abilityStateData) {
console.log('------------ onAbilityStateChanged -----------', abilityStateData);
},
onProcessCreated(processData) {
console.log('------------ onProcessCreated -----------', processData);
},
onProcessDied(processData) {
console.log('------------ onProcessDied -----------', processData);
}
}
const observerCode = app.registerApplicationStateObserver(applicationStateObserver);
console.log('-------- observerCode: ---------', observerCode);
```
## appManager.unregisterApplicationStateObserver<sup>8+</sup>
unregisterApplicationStateObserver(observerId: number, callback: AsyncCallback\<void>): void;
Deregisters the application state observer. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| observerId | number | No| Numeric code of the observer.|
| callback | AsyncCallback\<void> | No| Callback used to return the result.|
**Example**
```js
var observerId = 100;
function unregisterApplicationStateObserverCallback(err) {
if (err) {
console.log('------------ unregisterApplicationStateObserverCallback ------------', err);
}
}
app.unregisterApplicationStateObserver(observerId, unregisterApplicationStateObserverCallback);
```
## appManager.unregisterApplicationStateObserver<sup>8+</sup>
unregisterApplicationStateObserver(observerId: number): Promise\<void>;
Deregisters the application state observer. This API uses a promise to return the result.
**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| observerId | number | No| Numeric code of the observer.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
var observerId = 100;
app.unregisterApplicationStateObserver(observerId)
.then((data) => {
console.log('----------- unregisterApplicationStateObserver success ----------', data);
})
.catch((err) => {
console.log('----------- unregisterApplicationStateObserver fail ----------', err);
})
```
## appManager.getForegroundApplications<sup>8+</sup>
getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void;
Obtains applications that are running in the foreground. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback\<Array\<AppStateData>> | No| Callback used to return the application state data.|
**Example**
```js
function getForegroundApplicationsCallback(err, data) {
if (err) {
console.log('--------- getForegroundApplicationsCallback fail ---------', err);
} else {
console.log('--------- getForegroundApplicationsCallback success ---------', data)
}
}
app.getForegroundApplications(getForegroundApplicationsCallback);
```
## appManager.getForegroundApplications<sup>8+</sup>
getForegroundApplications(): Promise\<Array\<AppStateData>>;
Obtains applications that are running in the foreground. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<Array\<ProcessRunningInfo>> | Promise used to return the application state data.|
**Example**
```js
app.getForegroundApplications()
.then((data) => {
console.log('--------- getForegroundApplications success -------', data);
})
.catch((err) => {
console.log('--------- getForegroundApplications fail -------', err);
})
```
## appManager.killProcessWithAccount<sup>8+</sup>
killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\>
Kills a process by bundle name and account ID. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name of an application.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
**Example**
```js
var bundleName = 'bundleName';
var accountId = 0;
app.killProcessWithAccount(bundleName, accountId)
.then((data) => {
console.log('------------ killProcessWithAccount success ------------', data);
})
.catch((err) => {
console.log('------------ killProcessWithAccount fail ------------', err);
})
```
## appManager.killProcessWithAccount<sup>8+</sup>
killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCallback\<void\>): void
Kills a process by bundle name and account ID. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name of an application.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Example**
```js
var bundleName = 'bundleName';
var accountId = 0;
function killProcessWithAccountCallback(err, data) {
if (err) {
console.log('------------- killProcessWithAccountCallback fail, err: --------------', err);
} else {
console.log('------------- killProcessWithAccountCallback success, data: --------------', data);
}
}
app.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback);
```
## appManager.killProcessesByBundleName<sup>8+</sup>
killProcessesByBundleName(bundleName: string, callback: AsyncCallback\<void>);
Kills a process by bundle name. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | No| Bundle name of an application.|
| callback | AsyncCallback\<void> | No| Callback used to return the result.|
**Example**
```js
var bundleName = 'bundleName';
function killProcessesByBundleNameCallback(err, data) {
if (err) {
console.log('------------- killProcessesByBundleNameCallback fail, err: --------------', err);
} else {
console.log('------------- killProcessesByBundleNameCallback success, data: --------------', data);
}
}
app.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback);
```
## appManager.killProcessesByBundleName<sup>8+</sup>
killProcessesByBundleName(bundleName: string): Promise\<void>;
Kills a process by bundle name. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | No| Bundle name of an application.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
var bundleName = 'bundleName';
app.killProcessesByBundleName(bundleName)
.then((data) => {
console.log('------------ killProcessesByBundleName success ------------', data);
})
.catch((err) => {
console.log('------------ killProcessesByBundleName fail ------------', err);
})
```
## appManager.clearUpApplicationData<sup>8+</sup>
clearUpApplicationData(bundleName: string, callback: AsyncCallback\<void>);
Clears application data by bundle name. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | No| Bundle name of an application.|
| callback | AsyncCallback\<void> | No| Callback used to return the result.|
**Example**
```js
var bundleName = 'bundleName';
function clearUpApplicationDataCallback(err, data) {
if (err) {
console.log('------------- clearUpApplicationDataCallback fail, err: --------------', err);
} else {
console.log('------------- clearUpApplicationDataCallback success, data: --------------', data);
}
}
app.clearUpApplicationData(bundleName, clearUpApplicationDataCallback);
```
## appManager.clearUpApplicationData<sup>8+</sup>
clearUpApplicationData(bundleName: string): Promise\<void>;
Clears application data by bundle name. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | No| Bundle name of an application.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
var bundleName = 'bundleName';
app.clearUpApplicationData(bundleName)
.then((data) => {
console.log('------------ clearUpApplicationData success ------------', data);
})
.catch((err) => {
console.log('------------ clearUpApplicationData fail ------------', err);
})
```
## ApplicationStateObserver.onForegroundApplicationChanged<sup>8+</sup>
onForegroundApplicationChanged(appStateData: AppStateData): void;
Called when the application state changes.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| appStateData | [AppStateData](#appstatedata) | No| Information about the application whose state is changed.|
**Example**
```js
import ApplicationStateObserver from '@ohos.application.ApplicationStateObserver'
const foregroundApplicationInfo = ApplicationStateObserver.onForegroundApplicationChanged();
console.log('-------- foregroundApplicationInfo: ---------', foregroundApplicationInfo);
```
## ApplicationStateObserver.onAbilityStateChanged<sup>8+</sup>
onAbilityStateChanged(abilityStateData: AbilityStateData): void;
Called when the ability state changes.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| abilityStateData | [AbilityStateData](#abilitystatedata) | No| Information about the ability whose state is changed.|
**Example**
```js
import ApplicationStateObserver from '@ohos.application.ApplicationStateObserver'
const abilityStateChangedInfo = ApplicationStateObserver.onAbilityStateChanged();
console.log('-------- abilityStateChangedInfo: ---------', abilityStateChangedInfo);
```
## ApplicationStateObserver.onProcessCreated<sup>8+</sup>
onProcessCreated(processData: ProcessData): void;
Called when a process is created.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| processData | [ProcessData](#processdata) | No| Process information.|
**Example**
```js
import ApplicationStateObserver from '@ohos.application.ApplicationStateObserver'
const processCreatedInfo = ApplicationStateObserver.onProcessCreated();
console.log('-------- processCreatedInfo: ---------', processCreatedInfo);
```
## ApplicationStateObserver.onProcessDied<sup>8+</sup>
onProcessDied(processData: ProcessData): void;
Called when a process is terminated.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| processData | ProcessData | No| Process information.|
**Example**
```js
import ApplicationStateObserver from '@ohos.application.ApplicationStateObserver'
const processDiedInfo = ApplicationStateObserver.onProcessDied();
console.log('-------- processDiedInfo: ---------', processDiedInfo);
```
## AppStateData
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Readable/Writable| Type | Mandatory| Description |
| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
| pid<sup>8+</sup> | Read only | number | No | Process ID. |
| bundleName<sup>8+</sup> | Read only | string | No | Bundle name of an application. |
| uid<sup>8+</sup> | Read only | number | No | User ID.|
| processName<sup>8+</sup> | Read only | string | No | Process name.|
| bundleNames<sup>8+</sup> | Read only | Array\<string> | No | **bundleName** array in the running processes.|
| state<sup>8+</sup> | Read only | number | No | Application state.|
## AbilityStateData
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Readable| Writable| Description |
| ----------------------- | ---------| ---- | ---- | ------------------------- |
| pid<sup>8+</sup> | number | Yes | No | Process ID. |
| bundleName<sup>8+</sup> | string | Yes | No | Bundle name of an application. |
| abilityName<sup>8+</sup> | string | Yes | No | Ability name. |
| uid<sup>8+</sup> | number | Yes | No | User ID. |
| state<sup>8+</sup> | number | Yes | No | Ability state. |
| moduleName<sup>9+</sup> | string | Yes | No | Name of the HAP file to which the ability belongs. |
| abilityType<sup>8+</sup> | string | Yes | No | Ability type. |
## ProcessData
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Readable| Writable| Description |
| ----------------------- | ---------| ---- | ---- | ------------------------- |
| pid<sup>8+</sup> | number | Yes | No | Process ID. |
| bundleName<sup>8+</sup> | string | Yes | No | Bundle name of an application. |
| uid<sup>8+</sup> | number | Yes | No | User ID. |
## ProcessRunningInfo
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Readable/Writable| Type | Mandatory| Description |
| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
| pid<sup>9+</sup> | Read only | number | No | Process ID. |
| uid<sup>9+</sup> | Read only | number | No | User ID.|
| processName<sup>9+</sup> | Read only | string | No | Process name.|
| bundleNames<sup>9+</sup> | Read only | Array\<string> | No | **bundleName** array in the running processes.|
# ErrorManager
The **ErrorManager** module provides APIs for registering and deregistering error observers.
> **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
```
import errorManager from '@ohos.application.errorManager'
```
## ErrorManager.registerErrorObserver
registerErrorObserver(observer: ErrorObserver): number;
Registers an error observer.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| observer | [ErrorObserver](#errorobserver) | No| Numeric code of the observer.|
**Example**
```js
var observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
}
}
errorManager.registerErrorObserver(observer)
.then((data) => {
console.log('----------- registerErrorObserver success ----------', data);
})
.catch((err) => {
console.log('----------- registerErrorObserver fail ----------', err);
})
```
## ErrorManager.unregisterErrorObserver
unregisterErrorObserver(observerId: number, callback: AsyncCallback\<void>): void;
Deregisters an error observer. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| observerId | number | No| Numeric code of the observer.|
| callback | AsyncCallback\<void> | No| Callback used to return the result.|
**Example**
```js
var observerId = 100;
function unregisterErrorObserverCallback(err) {
if (err) {
console.log('------------ unregisterErrorObserverCallback ------------', err);
}
}
errorManager.unregisterErrorObserver(observerId, unregisterErrorObserverCallback);
```
## ErrorManager.unregisterErrorObserver
unregisterErrorObserver(observerId: number): Promise\<void>;
Deregisters an error observer. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| observerId | number | No| Numeric code of the observer.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
var observerId = 100;
errorManager.unregisterErrorObserver(observerId)
.then((data) => {
console.log('----------- unregisterErrorObserver success ----------', data);
})
.catch((err) => {
console.log('----------- unregisterErrorObserver fail ----------', err);
})
```
## ErrorObserver
onUnhandledException(errMsg: string): void;
Called when an unhandled exception occurs in the JS runtime.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| errMsg | string | No| Message and error stack trace about the exception.|
**Example**
```js
var observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
}
}
errorManager.registerErrorObserver(observer)
.then((data) => {
console.log('----------- registerErrorObserver success ----------', data);
})
.catch((err) => {
console.log('----------- registerErrorObserver fail ----------', err);
})
```
# FormExtensionContext
The **FormExtensionContext** module, inherited from **ExtensionContext**, provides context for Form Extension abilities.
You can use the APIs of this module to start Form Extension abilities.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
Implements the context that provides the capabilities and APIs of **FormExtension**. This class is inherited from **ExtensionContext**.
## Modules to Import
## Usage
Before using the **ServiceExtensionContext** module, you must first obtain a **FormExtension** instance.
```js
import FormExtension from '@ohos.application.FormExtension';
import formBindingData from '@ohos.application.formBindingData'
export default class MyFormExtension extends FormExtension {
onCreate() {
let dataObj1 = {
temperature:"11c",
"time":"11:00"
};
let obj1 = formBindingData.createFormBindingData(dataObj1);
return obj1;
}
}
```
## FormExtensionContext.updateForm
## FormExtensionContext.startAbility
updateForm(formId: string, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback\<void>): void
startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void
Updates a widget. This method uses a callback to return the result.
Starts an ability. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.Form
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| --------------- | ------------------------------------------------------------ | ---- | -------------------------------------- |
| formId | string | Yes | ID of the widget that requests to be updated. |
| formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes | New data of the widget. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result indicating whether the method is successfully called.|
| Name| Type | Mandatory| Description |
| ------| --------------------------------- | ---- | -------------------------------------- |
| want| [Want](js-apis-application-Want.md) | Yes | Information about the ability to start, such as the ability name and bundle name.|
| callback| AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example**
```js
import formBindingData from '@ohos.application.formBindingData'
export default class MyFormExtension extends FormExtension {
onUpdate(formId) {
console.log('FormExtension onUpdate, formId:' + formId);
let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
this.context.updateForm(formId, obj2, (data)=>{
console.log('FormExtension context updateForm, data:' + data);
});
}
}
```
```js
var want = {
deviceId: "",
bundleName: "com.example.formstartability",
abilityName: "MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters: {}
}
this.context.startAbility(want, function(err) {
console.info(err.code);
})
```
## FormExtensionContext.updateForm
## FormExtensionContext.startAbility
updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Promise\<void>
startAbility(want: Want): Promise&lt;void&gt;
Updates a widget. This method uses a promise to return the result.
Starts an ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.Form
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| --------------- | ------------------------------------------------------------ | ---- | ------------------ |
| formId | string | Yes | ID of the widget that requests to be updated.|
| formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes | New data of the widget. |
| Name| Type | Mandatory| Description |
| ------| --------------------------------- | ---- | -------------------------------------- |
| want| [Want](js-apis-application-Want.md) | Yes | Information about the ability to start, such as the ability name and bundle name.|
**Return value**
| Type | Description |
| -------------- | --------------------------------- |
| Promise\<void> | Promise returned with the result indicating whether the method is successfully called.|
| Type | Description |
| ------------ | ---------------------------------- |
| Promise&lt;void&lt; | Promise used to return the result.|
**Example**
```js
import formBindingData from '@ohos.application.formBindingData'
export default class MyFormExtension extends FormExtension {
onUpdate(formId) {
console.log('FormExtension onUpdate, formId:' + formId);
let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
this.context.updateForm(formId, obj2)
.then((data)=>{
console.log('FormExtension context updateForm, data:' + data);
}).catch((error) => {
console.error('Operation updateForm failed. Cause: ' + error);});
}
}
```
```js
var want = {
deviceId: "",
bundleName: "com.example.formstartability",
abilityName: "MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters: {}
}
this.context.startAbility(want).then(() => {
console.info("StartAbility Success");
}).catch((error) => {
console.info("StartAbility failed");
});
```
# ServiceExtensionContext
The **ServiceExtensionContext** module, inherited from **ExtensionContext**, provides context for Service Extension abilities.
You can use the APIs of this module to start, terminate, connection, and disconnect abilities.
> **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 APIs of this module can be used only in the stage model.
Implements the context that provides the capabilities and APIs of **ServiceExtension**. This class is inherited from **ExtensionContext**.
## Usage
## Modules to Import
Before using the **ServiceExtensionContext** module, you must define a child class that inherits from **ServiceExtensionAbility**.
```
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
```js
import ServiceExtensionAbility from '@ohos.application.ServiceExtensionAbility';
class MainAbility extends ServiceExtensionAbility {
onCreate() {
let context = this.context;
}
}
```
## startAbility
startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void;
Starts an ability. This API uses a callback to return the result.
Starts an ability. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the ability to start, such as the ability name and bundle name.|
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the API is successfully called.|
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability, such as the ability name and bundle name.|
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result.|
**Example**
```js
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
class MainAbility extends ExtensionContext {
onWindowStageCreate(windowStage) {
let want = {
"bundleName": "com.example.myapp",
"abilityName": "MyAbility"};
this.context.startAbility(want, (err) => {
console.log('startAbility result:' + JSON.stringify(err));
});
}
}
let want = {
"bundleName": "com.example.myapp",
"abilityName": "MyAbility"};
this.context.startAbility(want, (err) => {
console.log('startAbility result:' + JSON.stringify(err));
});
```
## startAbility
## ServiceExtensionContext.startAbility
startAbility(want: Want): Promise&lt;void&gt;;
startAbility(want: Want, options?: StartOptions): Promise\<void>;
Starts an ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the ability to start, such as the ability name and bundle name.|
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability, such as the ability name and bundle name.|
| options | [StartOptions](js-apis-application-StartOptions.md) | Yes| Parameters used for starting the ability.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
let want = {
"bundleName": "com.example.myapp",
"abilityName": "MyAbility"
};
this.context.startAbility(want).then((data) => {
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
```
## startAbility
startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&gt;): void
Starts an ability. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| options | [StartOptions](js-apis-application-StartOptions.md) | Yes| Parameters used for starting the ability.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var options = {
windowMode: 0,
};
this.context.startAbility(want, options, (error) => {
console.log("error.code = " + error.code)
})
```
## ServiceExtensionContext.startAbilityWithAccount
startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void>): void;
Starts an ability with the account ID specified. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
this.context.startAbilityWithAccount(want, accountId, (err) => {
console.log('---------- startAbilityWithAccount fail, err: -----------', err);
});
```
## ServiceExtensionContext.startAbilityWithAccount
startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback\<void\>): void;
Starts an ability with the account ID specified. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| options | [StartOptions](js-apis-application-StartOptions.md) | No| Parameters used for starting the ability.|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
var options = {
windowMode: 0,
};
this.context.startAbilityWithAccount(want, accountId, options, (err) => {
console.log('---------- startAbilityWithAccount fail, err: -----------', err);
});
```
## ServiceExtensionContext.startAbilityWithAccount
startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions): Promise\<void>;
Starts an ability with the account ID specified. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| options | [StartOptions](js-apis-application-StartOptions.md) | No| Parameters used for starting the ability.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
class MainAbility extends ExtensionContext {
onWindowStageCreate(windowStage) {
let want = {
"bundleName": "com.example.myapp",
"abilityName": "MyAbility"
};
this.context.startAbility(want).then((data) => {
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
}
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
var options = {
windowMode: 0,
};
this.context.startAbilityWithAccount(want, accountId, options)
.then((data) => {
console.log('---------- startAbilityWithAccount success, data: -----------', data);
})
.catch((err) => {
console.log('---------- startAbilityWithAccount fail, err: -----------', err);
})
```
## ServiceExtensionContext.startServiceExtensionAbility
startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
Starts a new Service Extension ability. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
this.context.startServiceExtensionAbility(want, (err) => {
console.log('---------- startServiceExtensionAbility fail, err: -----------', err);
});
```
## ServiceExtensionContext.startServiceExtensionAbility
startServiceExtensionAbility(want: Want): Promise\<void>;
Starts a new Service Extension ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
this.context.startServiceExtensionAbility(want)
.then((data) => {
console.log('---------- startServiceExtensionAbility success, data: -----------', data);
})
.catch((err) => {
console.log('---------- startServiceExtensionAbility fail, err: -----------', err);
})
```
## ServiceExtensionContext.startServiceExtensionAbilityWithAccount
startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void>): void;
Starts a new Service Extension ability with the account ID specified. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
this.context.startServiceExtensionAbilityWithAccount(want,accountId, (err) => {
console.log('---------- startServiceExtensionAbilityWithAccount fail, err: -----------', err);
});
```
## ServiceExtensionContext.startServiceExtensionAbilityWithAccount
startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<void>;
Starts a new Service Extension ability with the account ID specified. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
this.context.startServiceExtensionAbilityWithAccount(want,accountId)
.then((data) => {
console.log('---------- startServiceExtensionAbilityWithAccount success, data: -----------', data);
})
.catch((err) => {
console.log('---------- startServiceExtensionAbilityWithAccount fail, err: -----------', err);
})
```
## ServiceExtensionContext.stopServiceExtensionAbility
stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
Stops a Service Extension ability in the same application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
this.context.stopServiceExtensionAbility(want, (err) => {
console.log('---------- stopServiceExtensionAbility fail, err: -----------', err);
});
```
## ServiceExtensionContext.stopServiceExtensionAbility
stopServiceExtensionAbility(want: Want): Promise\<void>;
Stops a Service Extension ability in the same application. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
this.context.stopServiceExtensionAbility(want)
.then((data) => {
console.log('---------- stopServiceExtensionAbility success, data: -----------', data);
})
.catch((err) => {
console.log('---------- stopServiceExtensionAbility fail, err: -----------', err);
})
```
## ServiceExtensionContext.stopServiceExtensionAbilityWithAccount
stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void>): void;
Stops a Service Extension ability in the same application with the account ID specified. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
this.context.stopServiceExtensionAbilityWithAccount(want,accountId, (err) => {
console.log('---------- stopServiceExtensionAbilityWithAccount fail, err: -----------', err);
});
```
## ServiceExtensionContext.stopServiceExtensionAbilityWithAccount
stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<void>;
Stops a Service Extension ability in the same application with the account ID specified. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
this.context.stopServiceExtensionAbilityWithAccount(want,accountId)
.then((data) => {
console.log('---------- stopServiceExtensionAbilityWithAccount success, data: -----------', data);
})
.catch((err) => {
console.log('---------- stopServiceExtensionAbilityWithAccount fail, err: -----------', err);
})
```
## ServiceExtensionContext.terminateSelf
terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
Terminates this ability. This API uses a callback to return the result.
Terminates this ability. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the API is successfully called.|
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result.|
**Example**
```js
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
class MainAbility extends ExtensionContext {
onWindowStageCreate(windowStage) {
this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringify(err));
});
}
}
this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringify(err));
});
```
## ServiceExtensionContext.terminateSelf
terminateSelf(): Promise&lt;void&gt;;
......@@ -126,29 +561,24 @@ Terminates this ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
class MainAbility extends ExtensionContext {
onWindowStageCreate(windowStage) {
this.context.terminateSelf().then((data) => {
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
}
this.context.terminateSelf().then((data) => {
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
```
## ServiceExtensionContext.connectAbility
connectAbility(want: Want, options: ConnectOptions): number;
......@@ -157,12 +587,14 @@ Connects this ability to a Service ability.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the ability to connect to, such as the ability name and bundle name.|
| options | [ConnectOptions](#connectoptions) | Yes| Callback used to return the information indicating that the connection is successful, interrupted, or failed.|
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability, such as the ability name and bundle name.|
| options | [ConnectOptions](js-apis-featureAbility.md#connectoptions) | Yes| Callback used to return the information indicating that the connection is successful, interrupted, or failed.|
**Return value**
......@@ -174,51 +606,86 @@ Connects this ability to a Service ability.
```js
let want = {
"bundleName": "com.example.myapp",
"abilityName": "MyAbility"
"bundleName": "com.example.myapp",
"abilityName": "MyAbility"
};
let options = {
onConnect: function(elementName, proxy) {},
onDisConnect: function(elementName) {},
onFailed: function(code) {}
onConnect(elementName, remote) { console.log('----------- onConnect -----------') },
onDisconnect(elementName) { console.log('----------- onDisconnect -----------') },
onFailed(code) { console.log('----------- onFailed -----------') }
}
let connection = this.context.connectAbility(want,options);
```
## ServiceExtensionContext.connectAbilityWithAccount
connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions): number;
Uses the **AbilityInfo.AbilityType.SERVICE** template and account ID to connect this ability to another ability.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the target ability.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| options | ConnectOptions | No| Remote object instance.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Result code of the ability connection.|
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "MainAbility"
};
var accountId = 100;
var options = {
onConnect(elementName, remote) { console.log('----------- onConnect -----------') },
onDisconnect(elementName) { console.log('----------- onDisconnect -----------') },
onFailed(code) { console.log('----------- onFailed -----------') }
}
const result = this.context.connectAbilityWithAccount(want, accountId, options);
console.log('----------- connectAbilityResult: ------------', result);
```
## ServiceExtensionContext.disconnectAbility
disconnectAbility(connection: number, callback:AsyncCallback&lt;void&gt;): void;
Disconnects this ability from the Service ability. This API uses a callback to return the result.
Disconnects this ability from the Service ability. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| connection | number | Yes| Number returned after **connectAbility** is called.|
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the API is successfully called.|
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result.|
**Example**
```js
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
class MainAbility extends ExtensionContext {
onWindowStageCreate(windowStage) {
let connection=1
this.context.disconnectAbility(connection, (err) => {
let connection=1
this.context.disconnectAbility(connection, (err) => {
// connection is the return value of connectAbility.
console.log('terminateSelf result:' + JSON.stringify(err));
});
}
}
});
```
## ServiceExtensionContext.disconnectAbility
disconnectAbility(connection: number): Promise&lt;void&gt;;
......@@ -227,6 +694,8 @@ Disconnects this ability from the Service ability. This API uses a promise to re
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
......@@ -237,34 +706,16 @@ Disconnects this ability from the Service ability. This API uses a promise to re
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
class MainAbility extends ExtensionContext {
onWindowStageCreate(windowStage) {
let connection=1
this.context.disconnectAbility(connection).then((data) => { // connection is the return value of connectAbility.
let connection=1
this.context.disconnectAbility(connection).then((data) => {
// connection is the return value of connectAbility.
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
}
});
```
## ConnectOptions
Defines the **ConnectOptions** data structure.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Description|
| -------- | -------- |
| onConnect(elementName:ElementName,&nbsp;remote:IRemoteObject) | Called when this ability is connected to a Service ability.|
| onDisconnect(elementName:ElementName) | Called when the peer service is abnormal or killed.|
| onFailed(code:&nbsp;number) | Called when the connection fails.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册