| 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.|
| 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.|
**Example**
**Example**
...
@@ -107,10 +119,10 @@ Verifies whether the current PID and UID have the given permission. This method
...
@@ -107,10 +119,10 @@ Verifies whether the current PID and UID have the given permission. This method
| permission | string | Yes| Name of the permission to verify.|
| 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.|
| 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.|
| 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.|
| 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.|
...
@@ -160,14 +176,18 @@ requestPermissionsFromUser(permissions: Array\<string>, requestCode: number, res
...
@@ -160,14 +176,18 @@ requestPermissionsFromUser(permissions: Array\<string>, requestCode: number, res
Requests certain permissions from the system. This method uses a callback to return the result.
Requests certain permissions from the system. This method uses a callback to return the result.
> The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Implements the ability context. This module is inherited from **Context**.
Implements the ability context. This module is inherited from **Context**.
## Usage
Before using the **AbilityContext** module, you must define a child class that inherits from **Ability**.
Obtains the caller interface of the specified ability, and if the specified ability is not started, starts the ability in the background.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the ability to start, including the ability name, bundle name, and device ID. If the device ID is left blank or the default value is used, the local ability will be started.|
- Return value
| Type| Description|
| -------- | -------- |
| Promise<> | Promise used to return the caller object to communicate with.|
- Example
```
import Ability from '@ohos.application.Ability';
var caller;
export default class MainAbility extends Ability {
Requests permissions from the user by displaying a pop-up window. This method uses a callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| permissions | Array<string> | Yes| Permissions to request.|
| callback | AsyncCallback<[PermissionRequestResult](js-apis-permissionrequestresult.md)> | Yes| Callback used to return the result indicating whether the method is successfully called.|
Requests permissions from the user by displaying a pop-up window. This method uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| permissions | Array<string> | Yes| Permissions to request.|
- Return value
| Type| Description|
| -------- | -------- |
| Promise<[PermissionRequestResult](js-apis-permissionrequestresult.md)> | Promise used to return the result indicating whether the method is successfully called.|
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.|
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core|
| want | Read-only| [Want](#want) | Yes| Information about the ability to start.|
| want | Read-only | [Want](#want) | Yes | Information about the ability to start.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.FAModel |
| abilityStartSetting | Read-only| {[key: string]: any} | No| Special attribute of the ability to start. This attribute can be passed in the method call.|
| abilityStartSetting | Read-only | {[key: string]: any} | No | Special attribute of the ability to start. This attribute can be passed in the method call.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.FAModel|
| deviceId | Read-only| string | No| ID of the device running the ability to start.|
| deviceId | Read-only | string | No | ID of the device running the ability to start.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| bundleName | Read-only| string | No| Bundle name of the ability to start. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can directly match the specified ability.|
| bundleName | Read-only | string | No | Bundle name of the ability to start. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can directly match the specified ability.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase|
| abilityName | Read-only| string | No| Name of the ability to start. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can directly match the specified ability.|
| abilityName | Read-only | string | No | Name of the ability to start. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can directly match the specified ability.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase|
| uri | Read-only| string | No| URI information to match. If **uri** is specified in a **Want** object, the **Want** object will match the specified URI information, including **scheme**, **schemeSpecificPart**, **authority**, and **path**.|
| uri | Read-only | string | No | URI information to match. If **uri** is specified in a **Want** object, the **Want** object will match the specified URI information, including **scheme**, **schemeSpecificPart**, **authority**, and **path**.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase|
| type | Read-only| string | No| MIME type, for example, **text/plain** or **image/***.|
| type | Read-only | string | No | MIME type, for example, **text/plain** or **image/***.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| flags | Read-only| number | No| How the **Want** object will be handled. By default, numbers are passed in. For details, see [flags](#flags).|
| flags | Read-only | number | No | How the **Want** object will be handled. By default, numbers are passed in. For details, see [flags](#flags).<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase|
| parameters | Read-only| {[key: string]: any} | No| List of parameters in the **Want** object.|
| parameters | Read-only | {[key: string]: any} | No | List of parameters in the **Want** object.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| entities | Read-only| Array\<string> | No| List of entities.|
| entities | Read-only | Array\<string> | No | List of entities.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Indicates the permission to read the URI.|
| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Indicates the permission to read the URI.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Indicates the permission to write the URI.|
| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Indicates the permission to write the URI.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | Returns the result to the ability.|
| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | Returns the result to the ability.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| FLAG_ABILITY_CONTINUATION | 0x00000008 | Indicates whether the ability on the local device can be migrated to a remote device.|
| FLAG_ABILITY_CONTINUATION | 0x00000008 | Indicates whether the ability on the local device can be migrated to a remote device.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| FLAG_NOT_OHOS_COMPONENT | 0x00000010 | Indicates that a component does not belong to OHOS.|
| FLAG_NOT_OHOS_COMPONENT | 0x00000010 | Indicates that a component does not belong to OHOS.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | Indicates whether to enable an ability.|
| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | Indicates whether to enable an ability.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Indicates the permission to make the URI persistent.|
| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Indicates the permission to make the URI persistent.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | Indicates the permission to verify URIs by prefix matching.|
| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | Indicates the permission to verify URIs by prefix matching.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | Supports cross-device startup in a distributed scheduler.|
| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | Supports cross-device startup in a distributed scheduler.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | Indicates that the Service ability is started regardless of whether the host application has been started.|
| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | Indicates that the Service ability is started regardless of whether the host application has been started.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that the migration is reversible.|
| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that the migration is reversible.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| FLAG_INSTALL_ON_DEMAND | 0x00000800 | Indicates that the specific ability will be installed if it has not been installed.|
| FLAG_INSTALL_ON_DEMAND | 0x00000800 | Indicates that the specific ability will be installed if it has not been installed.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| FLAG_INSTALL_WITH_BACKGROUND_MODE | 0x80000000 | Indicates that the specific ability will be installed in the background 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.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| FLAG_ABILITY_CLEAR_MISSION | 0x00008000 | Clears other operation missions. This flag can be set for the **Want** object passed to **ohos.app.Context#startAbility** and must be used together with **flag_ABILITY_NEW_MISSION**.|
| FLAG_ABILITY_CLEAR_MISSION | 0x00008000 | Clears other operation missions. This flag can be set for the **Want** object passed to **ohos.app.Context#startAbility** and must be used together with **flag_ABILITY_NEW_MISSION**.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase|
| FLAG_ABILITY_NEW_MISSION | 0x10000000 | Creates a mission on the historical mission stack.|
| FLAG_ABILITY_NEW_MISSION | 0x10000000 | Creates a mission on the historical mission stack.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| FLAG_ABILITY_MISSION_TOP | 0x20000000 | Starts the mission on the top of the existing mission stack; creates an ability instance if no mission exists.|
| FLAG_ABILITY_MISSION_TOP | 0x20000000 | Starts the mission on the top of the existing mission stack; creates an ability instance if no mission exists.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase|
## AbilityStartSetting
## AbilityStartSetting
...
@@ -214,23 +238,23 @@ The **AbilityStartSetting** attribute is an object defined as [key: string]: any
...
@@ -214,23 +238,23 @@ The **AbilityStartSetting** attribute is an object defined as [key: string]: any
Defines special attributes of an ability, for example, **featureAbility.AbilityStartSetting.BOUNDS_KEY**.
Defines special attributes of an ability, for example, **featureAbility.AbilityStartSetting.BOUNDS_KEY**.
| WINDOW_MODE_UNDEFINED | 0 | The Page ability is in an undefined window display mode.|
| WINDOW_MODE_UNDEFINED | 0 | The Page ability is in an undefined window display mode.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.FAModel |
| WINDOW_MODE_FULLSCREEN | 1 | The Page ability is in full screen mode.|
| WINDOW_MODE_FULLSCREEN | 1 | The Page ability is in full screen mode.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.FAModel |
| WINDOW_MODE_SPLIT_PRIMARY | 100 | The Page ability is displayed in the primary window when it is in split-screen mode.|
| WINDOW_MODE_SPLIT_PRIMARY | 100 | The Page ability is displayed in the primary window when it is in split-screen mode.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.FAModel|
| WINDOW_MODE_SPLIT_SECONDARY | 101 | The Page ability is displayed in the secondary window when it is in split-screen mode.|
| WINDOW_MODE_SPLIT_SECONDARY | 101 | The Page ability is displayed in the secondary window when it is in split-screen mode.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.FAModel|
| WINDOW_MODE_FLOATING | 102 | The Page ability is displayed in floating window mode.|
| WINDOW_MODE_FLOATING | 102 | The Page ability is displayed in floating window mode.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.FAModel |
Requests a continuous task from the system. This method uses an asynchronous callback to return the result. (This method is of API 7 and will be deprecated. Use the counterpart in API 8.)
Requests a continuous task from the system. This method uses an asynchronous callback to return the result. (This method is of API 7 and will be deprecated. Use the counterpart in API 8.)
Requests a continuous task from the system. This method uses a promise to return the result. (This method is of API 7 and will be deprecated. Use the counterpart in API 8.)
Requests a continuous task from the system. This method uses a promise to return the result. (This method is of API 7 and will be deprecated. Use the counterpart in API 8.)
**Parameters**
**Parameters**
...
@@ -304,7 +336,7 @@ Requests a continuous task from the system. This method uses a promise to return
...
@@ -304,7 +336,7 @@ Requests a continuous task from the system. This method uses a promise to return
| request | NotificationRequest | Yes| Notification parameter, which is used to display information in the notification bar.|
| request | NotificationRequest | Yes| Notification parameter, which is used to display information in the notification bar.|
**Return value**
**Return value**
| Type| Description|
| Type | Description |
| -------------- | ------------------------- |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
| Promise\<void> | Promise used to return the result.|
Requests to cancel a continuous task from the system. This method uses an asynchronous callback to return the result. (This method is of API 7 and will be deprecated. Use the counterpart in API 8.)
Requests to cancel a continuous task from the system. This method uses an asynchronous callback to return the result. (This method is of API 7 and will be deprecated. Use the counterpart in API 8.)
Requests to cancel a continuous task from the system. This method uses a promise to return the result. (This method is of API 7 and will be deprecated. Use the counterpart in API 8.)
Requests to cancel a continuous task from the system. This method uses a promise to return the result. (This method is of API 7 and will be deprecated. Use the counterpart in API 8.)
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the ability to connect to, such as the ability name and bundle name.|
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the ability to connect to, such as the ability name and bundle name.|
| options | [ConnectOptions](#connectoptions) | Yes| Callback used to return the information indicating that the connection is successful, interrupted, or failed.|
| options | [ConnectOptions](#connectoptions) | Yes| Callback used to return the information indicating that the connection is successful, interrupted, or failed.|
Disconnects this ability from the Service ability. This method uses a promise to return the result.
Disconnects this ability from the Service ability. This method uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
- Parameters
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
...
@@ -171,7 +199,7 @@ Disconnects this ability from the Service ability. This method uses a promise to
...
@@ -171,7 +199,7 @@ Disconnects this ability from the Service ability. This method uses a promise to
| Type| Description|
| Type| Description|
| -------- | -------- |
| -------- | -------- |
| Promise<void> | Promise used to return the result indicating whether the method is successfully called.|
| Promise<void> | Promise used to return the result indicating whether the method is successfully called.|
- Example
- Example
```
```
this.context.disconnectAbility(connection).then((data) => { // connection is the return value of connectAbility.
this.context.disconnectAbility(connection).then((data) => { // connection is the return value of connectAbility.
...
@@ -188,6 +216,6 @@ Defines the **ConnectOptions** data structure.
...
@@ -188,6 +216,6 @@ Defines the **ConnectOptions** data structure.
| Name| Description|
| Name| Description|
| -------- | -------- |
| -------- | -------- |
| onConnect(elementName:ElementName, remote:IRemoteObject) | Called when this ability is connected to a Service ability.|
| onConnect(elementName:ElementName, remote:IRemoteObject) | Called when this ability is connected to a Service ability.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core|
| onDisconnect(elementName:ElementName) | Called when the peer service is abnormal or killed.|
| onDisconnect(elementName:ElementName) | Called when the peer service is abnormal or killed.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core|
| onFailed(code: number) | Called when the connection fails.|
| onFailed(code: number) | Called when the connection fails.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core|
Called after **onCreate** is invoked when an ability is started by calling **startAbility**. The value of **startId** is incremented for each ability that is started.
Called after **onCreate** is invoked when an ability is started by calling **startAbility**. The value of **startId** is incremented for each ability that is started.
Called after **onCreate** is invoked when an ability is started by calling **connectAbility**. A **RemoteObject** object is returned for communication with the client.
Called after **onCreate** is invoked when an ability is started by calling **connectAbility**. A **RemoteObject** object is returned for communication with the client.