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
```js
...
@@ -30,9 +31,9 @@ If this API is called for the first time, a root directory will be created.
...
@@ -30,9 +31,9 @@ If this API is called for the first time, a root directory will be created.
| 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**
...
@@ -96,8 +97,8 @@ Verifies whether a specific PID and UID have the given permission. This API uses
...
@@ -96,8 +97,8 @@ Verifies whether a specific PID and UID have the given permission. This API uses
| 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.|
**Example**
**Example**
...
@@ -136,23 +137,23 @@ Verifies whether a specific PID and UID have the given permission. This API uses
...
@@ -136,23 +137,23 @@ Verifies whether a specific PID and UID have the given permission. This API uses
| 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.|
| 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. |
| 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**
**Example**
...
@@ -651,9 +652,9 @@ If the distributed file path does not exist, the system will create one and retu
...
@@ -651,9 +652,9 @@ If the distributed file path does not exist, the system will create one and retu
**Return value**
**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.|
| 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**
**Example**
...
@@ -675,9 +676,9 @@ Obtains the application type. This API uses an asynchronous callback to return t
...
@@ -675,9 +676,9 @@ Obtains the application type. This API uses an asynchronous callback to return t
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
## Modules to Import
...
@@ -19,20 +19,20 @@ Obtains the ID attached to the end of a given URI.
...
@@ -19,20 +19,20 @@ Obtains the ID attached to the end of a given URI.
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Implements the ability context. This module is inherited from **Context**.
Implements the ability context. This module is inherited from **Context**.
## Modules to Import
```js
importAbilityfrom'@ohos.application.Ability'
```
## Usage
## Usage
Before using the **AbilityContext** module, you must define a child class that inherits from **Ability**.
Before using the **AbilityContext** module, you must define a child class that inherits from **Ability**.
```js
```js
importAbilityfrom'@ohos.application.Ability'
importAbilityfrom'@ohos.application.Ability'
classMainAbilityextendsAbility{
classMainAbilityextendsAbility{
...
@@ -28,7 +28,7 @@ class MainAbility extends Ability {
...
@@ -28,7 +28,7 @@ class MainAbility extends Ability {
console.log("startAbilityForResult Promise.resolve is called, result.resultCode = "+result.resultCode)
console.log("startAbilityForResult Promise.resolve is called, result.resultCode = "+result.resultCode)
},(error)=>{
},(error)=>{
console.log("startAbilityForResult Promise.Reject is called, error.code = "+error.code)
console.log("startAbilityForResult Promise.Reject is called, error.code = "+error.code)
...
@@ -244,7 +244,7 @@ Terminates this ability. This API uses a callback to return the result.
...
@@ -244,7 +244,7 @@ Terminates this ability. This API uses a callback to return the result.
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<void> | Yes| Callback used to return the result indicating whether the API is successfully called.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result indicating whether the API is successfully called.|
...
@@ -267,7 +267,7 @@ Terminates this ability. This API uses a promise to return the result.
...
@@ -267,7 +267,7 @@ Terminates this ability. This API uses a promise to return the result.
**Return value**
**Return value**
| Type | Description |
| Type| Description|
| -------- | -------- |
| -------- | -------- |
| Promise<void> | Promise used to return the result indicating whether the API is successfully called.|
| Promise<void> | Promise used to return the result indicating whether the API is successfully called.|
...
@@ -292,7 +292,7 @@ Terminates this ability. This API uses a callback to return the information to t
...
@@ -292,7 +292,7 @@ Terminates this ability. This API uses a callback to return the information to t
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
...
@@ -321,13 +321,13 @@ Terminates this ability. This API uses a promise to return information to the ca
...
@@ -321,13 +321,13 @@ Terminates this ability. This API uses a promise to return information to the ca
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
**Return value**
**Return value**
| Type | Description |
| Type| Description|
| -------- | -------- |
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
| Promise<void> | Promise used to return the result.|
...
@@ -355,13 +355,13 @@ Obtains the caller interface of the specified ability, and if the specified abil
...
@@ -355,13 +355,13 @@ Obtains the caller interface of the specified ability, and if the specified abil
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information about the ability to start, including the ability name, bundle name, and device ID. If the device ID is left blank or the default value is used, the local ability will be started.|
| want | [Want](js-apis-application-Want.md) | Yes| Information about the ability to start, including the ability name, bundle name, and device ID. If the device ID is left blank or the default value is used, the local ability will be started.|
**Return value**
**Return value**
| Type | Description |
| Type| Description|
| -------- | -------- |
| -------- | -------- |
| Promise<Caller> | Promise used to return the caller object to communicate with.|
| Promise<Caller> | Promise used to return the caller object to communicate with.|
...
@@ -378,7 +378,7 @@ Obtains the caller interface of the specified ability, and if the specified abil
...
@@ -378,7 +378,7 @@ Obtains the caller interface of the specified ability, and if the specified abil
deviceId:""
deviceId:""
}).then((obj)=>{
}).then((obj)=>{
caller=obj;
caller=obj;
console.log('Caller GetCaller Get '+call);
console.log('Caller GetCaller Get '+caller);
}).catch((e)=>{
}).catch((e)=>{
console.log('Caller GetCaller error '+e);
console.log('Caller GetCaller error '+e);
});
});
...
@@ -397,17 +397,19 @@ Requests permissions from the user by displaying a pop-up window. This API uses
...
@@ -397,17 +397,19 @@ Requests permissions from the user by displaying a pop-up window. This API uses
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| permissions | Array<string> | Yes| Permissions to request.|
| permissions | Array<string> | Yes| Permissions to request.|
| callback | AsyncCallback<[PermissionRequestResult](js-apis-permissionrequestresult.md)> | Yes| Callback used to return the result indicating whether the API is successfully called.|
| callback | AsyncCallback<[PermissionRequestResult](js-apis-permissionrequestresult.md)> | Yes| Callback used to return the result indicating whether the API is successfully called.|
@@ -421,24 +423,26 @@ Requests permissions from the user by displaying a pop-up window. This API uses
...
@@ -421,24 +423,26 @@ Requests permissions from the user by displaying a pop-up window. This API uses
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| permissions | Array<string> | Yes| Permissions to request.|
| permissions | Array<string> | Yes| Permissions to request.|
**Return value**
**Return value**
| Type | Description |
| Type| Description|
| -------- | -------- |
| -------- | -------- |
| Promise<[PermissionRequestResult](js-apis-permissionrequestresult.md)> | Promise used to return the result indicating whether the API is successfully called.|
| Promise<[PermissionRequestResult](js-apis-permissionrequestresult.md)> | Promise used to return the result indicating whether the API is successfully called.|
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
## Modules to Import
...
@@ -20,9 +20,9 @@ Creates an **AtManager** instance, which is used for ability access control.
...
@@ -20,9 +20,9 @@ Creates an **AtManager** instance, which is used for ability access control.
| tokenID | number | Yes | ID of the application. |
| tokenID | number | Yes | ID of the application. |
| permissionName | string | Yes | Name of the permission to grant. |
| permissionName | string | Yes | Name of the permission to grant.|
| permissionFlag | number | Yes | Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
| permissionFlag | number | Yes | Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
| tokenID | number | Yes | ID of the application. |
| tokenID | number | Yes | ID of the application. |
| permissionName | string | Yes | Name of the permission to grant. |
| permissionName | string | Yes | Name of the permission to grant.|
| permissionFlag | number | Yes | Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
| permissionFlag | number | Yes | Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
| callback | AsyncCallback<number> | Yes | Callback used to return the result. |
| callback | AsyncCallback<number> | Yes| Callback used to return the result.|
**Example**
**Example**
...
@@ -145,17 +146,17 @@ Revokes a user granted permission given to an application. This API uses a promi
...
@@ -145,17 +146,17 @@ Revokes a user granted permission given to an application. This API uses a promi
| tokenID | number | Yes | ID of the application. |
| tokenID | number | Yes | ID of the application. |
| permissionName | string | Yes | Name of the permission to revoke. |
| permissionName | string | Yes | Name of the permission to revoke.|
| permissionFlag | number | Yes | Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
| permissionFlag | number | Yes | Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
| tokenID | number | Yes | ID of the application. |
| tokenID | number | Yes | ID of the application. |
| permissionName | string | Yes | Name of the permission to revoke. |
| permissionName | string | Yes | Name of the permission to revoke.|
| permissionFlag | number | Yes | Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
| permissionFlag | number | Yes | Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
| callback | AsyncCallback<number> | Yes | Callback used to return the result. |
| callback | AsyncCallback<number> | Yes| Callback used to return the result.|
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Provides the snapshot of a mission.
Provides the snapshot of a mission.
## Modules to Import
## Modules to Import
```
```
import { ElementName } from '../bundle/elementName';
import abilitymanager from '@ohos.application.abilityManager';
import { image } from '../@ohos.multimedia.image';
import ElementName from '@ohos.bundle';
import image from '@ohos.multimedia.image';
```
```
## MissionSnapshot
## MissionSnapshot
Describes the mission snapshot.
Describes the mission snapshot.
| Name | Type | Readable | Writable | Description |
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Provides the context for running code, including **applicationInfo** and **resourceManager**.
Provides the context for running code, including **applicationInfo** and **resourceManager**.
## Modules to Import
```
import AbilityContext from '@ohos.application.Ability';
```
## Usage
## Usage
You must extend **AbilityContext** to implement this module.
You must extend **AbilityContext** to implement this module.
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...
@@ -34,7 +34,7 @@ Checks whether this application is undergoing a stability test. This API uses an
...
@@ -34,7 +34,7 @@ Checks whether this application is undergoing a stability test. This API uses an
> The initial APIs of this module are supported since API 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Implements event subscription, unsubscription, and triggering.
Implements event subscription, unsubscription, and triggering.
## Modules to Import
```js
importAbilityfrom'@ohos.application.Ability'
```
## Usage
## Usage
Before using any APIs in the **EventHub**, you must obtain an **EventHub** instance through the member variable **context** of the **Ability** instance.
Before using any APIs in the **EventHub**, you must obtain an **EventHub** instance through the member variable **context** of the **Ability** instance.
```js
```js
importAbilityfrom'@ohos.application.Ability'
importAbilityfrom'@ohos.application.Ability'
exportdefaultclassMainAbilityextendsAbility{
exportdefaultclassMainAbilityextendsAbility{
func1(){
console.log("func1 is called");
}
onForeground(){
onForeground(){
this.context.eventHub.on("123",this.func1);
this.context.eventHub.on("123",this.func1);
}
}
...
@@ -34,10 +42,10 @@ Subscribes to an event.
...
@@ -34,10 +42,10 @@ Subscribes to an event.
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| event | string | Yes | Event name. |
| event | string | Yes| Event name.|
| callback | Function | Yes | Callback invoked when the event is triggered. |
| callback | Function | Yes| Callback invoked when the event is triggered.|
**Example**
**Example**
...
@@ -72,10 +80,10 @@ Unsubscribes from an event. If **callback** is specified, this API unsubscribes
...
@@ -72,10 +80,10 @@ Unsubscribes from an event. If **callback** is specified, this API unsubscribes
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| event | string | Yes | Event name. |
| event | string | Yes| Event name.|
| callback | Function | No | Callback for the event. If **callback** is unspecified, all callbacks of the event are unsubscribed. |
| callback | Function | No| Callback for the event. If **callback** is unspecified, all callbacks of the event are unsubscribed.|
**Example**
**Example**
...
@@ -110,10 +118,10 @@ Triggers an event.
...
@@ -110,10 +118,10 @@ Triggers an event.
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| event | string | Yes | Event name. |
| event | string | Yes| Event name.|
| ...args | Object[] | Yes | Variable parameters, which are passed to the callback when the event is triggered. |
| ...args | Object[] | Yes| Variable parameters, which are passed to the callback when the event is triggered.|
> 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 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 initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Implements the context that provides the capabilities and APIs of **FormExtension**. This class is inherited from **ExtensionContext**.
Implements the context that provides the capabilities and APIs of **FormExtension**. This class is inherited from **ExtensionContext**.
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
missionManager provides APIs to lock, unlock, and clear missions, and switch a mission to the foreground.
missionManager provides APIs to lock, unlock, and clear missions, and switch a mission to the foreground.
## Modules to Import
## Modules to Import
```
```
import missionManager from '@ohos.application.missionManager'
import missionManager from '@ohos.application.missionManager'
```
```
## Required Permissions
ohos.permission.MANAGE_MISSIONS
## missionManager.registerMissionListener
## missionManager.registerMissionListener
...
@@ -40,10 +40,11 @@ Registers a listener to observe the mission status.
...
@@ -40,10 +40,11 @@ Registers a listener to observe the mission status.
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
| uri | string | Yes | URI of a file, for example, **fileshare:///com.samples.filesharetest.FileShare/person/10**. |
| uri | string | Yes| URI of a file, for example, **fileshare:///com.samples.filesharetest.FileShare/person/10**.|
| flag | wantConstant.Flags | Yes | Read or write permission on the file specified by the URI. |
| flag | wantConstant.Flags | Yes| Read or write permission on the file specified by the URI.|
| accessTokenId | number | Yes | Unique ID of an application, which is obtained through the **BundleManager** API. |
| accessTokenId | number | Yes| Unique ID of an application, which is obtained through the **BundleManager** API.|
| callback | AsyncCallback<number> | Yes | Callback used to return the check result. The value **0** means that the application has the specified permission, and **-1** means the opposite. |
| callback | AsyncCallback<number> | Yes| Callback used to return the check result. The value **0** means that the application has the specified permission, and **-1** means the opposite.|
| uri | string | Yes | URI of a file, for example, **fileshare:///com.samples.filesharetest.FileShare/person/10**. |
| uri | string | Yes| URI of a file, for example, **fileshare:///com.samples.filesharetest.FileShare/person/10**.|
| flag | wantConstant.Flags | Yes | Read or write permission on the file specified by the URI. |
| flag | wantConstant.Flags | Yes| Read or write permission on the file specified by the URI.|
| accessTokenId | number | Yes | Unique ID of an application, which is obtained through the **BundleManager** API. |
| accessTokenId | number | Yes| Unique ID of an application, which is obtained through the **BundleManager** API.|
**Return value**
**Return value**
| Type | Description |
| Type| Description|
| -------- | -------- |
| -------- | -------- |
| Promise<number> | Promise used to return the check result. The value **0** means that the application has the specified permission, and **-1** means the opposite. |
| Promise<number> | Promise used to return the check result. The value **0** means that the application has the specified permission, and **-1** means the opposite.|