提交 6d728462 编写于 作者: W wusongqing

updated docs

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 833fa63a
...@@ -7,7 +7,7 @@ import featureAbility from '@ohos.ability.featureAbility' ...@@ -7,7 +7,7 @@ import featureAbility from '@ohos.ability.featureAbility'
import bundle from '@ohos.bundle' import bundle from '@ohos.bundle'
``` ```
The **Context** object is created in a **featureAbility** and returned through its **getContext()** method. 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
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -15,26 +15,21 @@ var context = featureAbility.getContext(); ...@@ -15,26 +15,21 @@ var context = featureAbility.getContext();
context.getOrCreateLocalDir() context.getOrCreateLocalDir()
``` ```
## Context ## Context.getOrCreateLocalDir
### getOrCreateLocalDir
getOrCreateLocalDir(callback: AsyncCallback\<string>): void getOrCreateLocalDir(callback: AsyncCallback\<string>): void
Obtains the local root directory of the application. This method uses a callback to return the result. Obtains the local root directory of the application. This API uses an asynchronous callback to return the result.
If this method is called for the first time, a root directory is created.
**System capabilities** If this API is called for the first time, a root directory will be created.
SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | -------------------------- | | -------- | ---------------------- | ---- | -------------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the local root directory of the application.| | callback | AsyncCallback\<string> | Yes | Callback used to return the local root directory.|
**Example** **Example**
...@@ -48,23 +43,21 @@ context.getOrCreateLocalDir((err, data)=>{ ...@@ -48,23 +43,21 @@ context.getOrCreateLocalDir((err, data)=>{
### getOrCreateLocalDir ## Context.getOrCreateLocalDir
getOrCreateLocalDir(): Promise\<string> getOrCreateLocalDir(): Promise\<string>
Obtains the local root directory of the application. This method uses a promise to return the result. Obtains the local root directory of the application. This API uses a promise to return the result.
If this method is called for the first time, a root directory is created. If this API is called for the first time, a root directory will be created.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------- | ---------------------- | | ---------------- | ---------------------- |
| Promise\<string> | Promise used to return the local root directory of the application.| | Promise\<string> | Promise used to return the local root directory.|
**Example** **Example**
...@@ -78,19 +71,16 @@ context.getOrCreateLocalDir().then((data) => { ...@@ -78,19 +71,16 @@ context.getOrCreateLocalDir().then((data) => {
### verifyPermission ## Context.verifyPermission
verifyPermission(permission: string, options: PermissionOptions, callback: AsyncCallback\<number>): void verifyPermission(permission: string, options: PermissionOptions, callback: AsyncCallback\<number>): void
Verifies whether a specific PID and UID have the given permission. This method uses a callback to return the result. Verifies whether a specific PID and UID have the given permission. This API uses an asynchronous callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | ------------------------------------- | | ---------- | --------------------------------------- | ---- | ------------------------------------- |
| permission | string | Yes | Name of the permission to verify. | | permission | string | Yes | Name of the permission to verify. |
...@@ -110,14 +100,15 @@ bundle.getBundleInfo('com.context.test', 1, (datainfo) =>{ ...@@ -110,14 +100,15 @@ bundle.getBundleInfo('com.context.test', 1, (datainfo) =>{
### verifyPermission ## Context.verifyPermission
verifyPermission(permission: string, callback: AsyncCallback\<number>): void verifyPermission(permission: string, callback: AsyncCallback\<number>): void
Verifies whether the current PID and UID have the given permission. This method uses a callback to return the result. Verifies whether the current PID and UID have the given permission. This API uses an asynchronous callback to return the result.
**Parameters** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | ---------------------- | ---- | ------------------------------------- | | ---------- | ---------------------- | ---- | ------------------------------------- |
...@@ -132,19 +123,16 @@ var context = featureAbility.getContext(); ...@@ -132,19 +123,16 @@ var context = featureAbility.getContext();
context.verifyPermission("com.example.permission") context.verifyPermission("com.example.permission")
``` ```
### verifyPermission ## Context.verifyPermission
verifyPermission(permission: string, options?: PermissionOptions): Promise\<number> verifyPermission(permission: string, options?: PermissionOptions): Promise\<number>
Verifies whether a specific PID and UID have the given permission. This method uses a promise to return the result. Verifies whether a specific PID and UID have the given permission. This API uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | ---------------- | | ---------- | --------------------------------------- | ---- | ---------------- |
| permission | string | Yes | Name of the permission to verify.| | permission | string | Yes | Name of the permission to verify.|
...@@ -170,24 +158,22 @@ context.verifyPermission('com.context.permission',Permission).then((data) => { ...@@ -170,24 +158,22 @@ context.verifyPermission('com.context.permission',Permission).then((data) => {
### requestPermissionsFromUser ## Context.requestPermissionsFromUser
requestPermissionsFromUser(permissions: Array\<string>, requestCode: number, resultCallback: AsyncCallback<[PermissionRequestResult](#permissionrequestresult)>) requestPermissionsFromUser(permissions: Array\<string>, requestCode: number, resultCallback: AsyncCallback<[PermissionRequestResult](#permissionrequestresult)>): void
Requests certain permissions from the system. This method uses a callback to return the result. Requests certain permissions from the system. This API uses an asynchronous callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------------- | ------------------------------------------------------------ | ---- | ----------------------------------------------- | | -------------- | ------------------------------------------------------------ | ---- | ----------------------------------------------- |
| permissions | Array\<string> | Yes | Permissions to request. This parameter cannot be **null**. | | permissions | Array\<string> | Yes | Permissions to request. This parameter cannot be **null**. |
| requestCode | number | Yes | Request code to be passed to **PermissionRequestResult**.| | requestCode | number | Yes | Request code to be passed to **PermissionRequestResult**.|
| resultCallback | AsyncCallback<[PermissionRequestResult](#permissionrequestresult)> | Yes | Permission request result. | | resultCallback | AsyncCallback<[PermissionRequestResult](#permissionrequestresult)> | Yes | Permission request result. |
**Example** **Example**
```js ```js
...@@ -208,15 +194,13 @@ context.requestPermissionsFromUser( ...@@ -208,15 +194,13 @@ context.requestPermissionsFromUser(
### getApplicationInfo ## Context.getApplicationInfo
getApplicationInfo(callback: AsyncCallback\<ApplicationInfo>) getApplicationInfo(callback: AsyncCallback\<ApplicationInfo>): void
Obtains information about the current application. This method uses a callback to return the result. Obtains information about the current application. This API uses an asynchronous callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **Parameters**
...@@ -234,15 +218,13 @@ context.getApplicationInfo() ...@@ -234,15 +218,13 @@ context.getApplicationInfo()
### getApplicationInfo ## Context.getApplicationInfo
getApplicationInfo(): Promise\<ApplicationInfo> getApplicationInfo(): Promise\<ApplicationInfo>
Obtains information about the current application. This method uses a promise to return the result. Obtains information about the current application. This API uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value** **Return value**
...@@ -263,15 +245,13 @@ context.getApplicationInfo().then((data) => { ...@@ -263,15 +245,13 @@ context.getApplicationInfo().then((data) => {
### getBundleName ## Context.getBundleName
getBundleName(callback: AsyncCallback\<string>): void getBundleName(callback: AsyncCallback\<string>): void
Obtains the bundle name of the current ability. This method uses a callback to return the result. Obtains the bundle name of the current ability. This API uses an asynchronous callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **Parameters**
...@@ -289,15 +269,13 @@ context.getBundleName() ...@@ -289,15 +269,13 @@ context.getBundleName()
### getBundleName ## Context.getBundleName
getBundleName(): Promise\<string> getBundleName(): Promise\<string>
Obtains the bundle name of the current ability. This method uses a promise to return the result. Obtains the bundle name of the current ability. This API uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value** **Return value**
...@@ -318,15 +296,13 @@ context.getBundleName().then((data) => { ...@@ -318,15 +296,13 @@ context.getBundleName().then((data) => {
### getProcessInfo ## Context.getProcessInfo
getProcessInfo(callback: AsyncCallback\<ProcessInfo>) getProcessInfo(callback: AsyncCallback\<ProcessInfo>): void
Obtains information about the current process, including the PID and process name. This method uses a callback to return the result. Obtains information about the current process, including the PID and process name. This API uses an asynchronous callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **Parameters**
...@@ -344,15 +320,13 @@ context.getProcessInfo() ...@@ -344,15 +320,13 @@ context.getProcessInfo()
### getProcessInfo ## Context.getProcessInfo
getProcessInfo(): Promise\<ProcessInfo> getProcessInfo(): Promise\<ProcessInfo>
Obtains information about the current process, including the PID and process name. This method uses a promise to return the result. Obtains information about the current process, including the PID and process name. This API uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value** **Return value**
...@@ -373,17 +347,15 @@ context.getProcessInfo().then((data) => { ...@@ -373,17 +347,15 @@ context.getProcessInfo().then((data) => {
### getElementName ## Context.getElementName
getElementName(callback: AsyncCallback\<ElementName>): void getElementName(callback: AsyncCallback\<ElementName>): void
Obtains the **ohos.bundle.ElementName** object of the current ability. This method uses a callback to return the result. Obtains the **ohos.bundle.ElementName** object of the current ability. This API uses an asynchronous callback to return the result.
This method is available only to Page abilities. This API is available only to Page abilities.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **Parameters**
...@@ -401,17 +373,15 @@ context.getElementName() ...@@ -401,17 +373,15 @@ context.getElementName()
### getElementName ## Context.getElementName
getElementName(): Promise\<ElementName> getElementName(): Promise\<ElementName>
Obtains the **ohos.bundle.ElementName** object of the current ability. This method uses a promise to return the result. Obtains the **ohos.bundle.ElementName** object of the current ability. This API uses a promise to return the result.
This method is available only to Page abilities.
**System capabilities** This API is available only to Page abilities.
SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value** **Return value**
...@@ -430,15 +400,15 @@ context.getElementName().then((data) => { ...@@ -430,15 +400,15 @@ context.getElementName().then((data) => {
}); });
``` ```
### getProcessName ## Context.getProcessName
getProcessName(callback: AsyncCallback\<string>): void getProcessName(callback: AsyncCallback\<string>): void
Obtains the name of the current process. This method uses a callback to return the result. Obtains the name of the current process. This API uses an asynchronous callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | -------------------- | | -------- | ---------------------- | ---- | -------------------- |
...@@ -454,15 +424,13 @@ context.getProcessName() ...@@ -454,15 +424,13 @@ context.getProcessName()
### getProcessName ## Context.getProcessName
getProcessName(): Promise\<string> getProcessName(): Promise\<string>
Obtains the name of the current process. This method uses a promise to return the result. Obtains the name of the current process. This API uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Return value** **Return value**
...@@ -483,15 +451,13 @@ context.getProcessName().then((data) => { ...@@ -483,15 +451,13 @@ context.getProcessName().then((data) => {
### getCallingBundle ## Context.getCallingBundle
getCallingBundle(callback: AsyncCallback\<string>): void getCallingBundle(callback: AsyncCallback\<string>): void
Obtains the bundle name of the calling ability. This method uses a callback to return the result. Obtains the bundle name of the calling ability. This API uses an asynchronous callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **Parameters**
...@@ -509,15 +475,13 @@ context.getCallingBundle() ...@@ -509,15 +475,13 @@ context.getCallingBundle()
### getCallingBundle ## Context.getCallingBundle
getCallingBundle(): Promise\<string> getCallingBundle(): Promise\<string>
Obtains the bundle name of the calling ability. This method uses a promise to return the result. Obtains the bundle name of the calling ability. This API uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Return value** **Return value**
...@@ -536,17 +500,443 @@ context.getCallingBundle().then((data) => { ...@@ -536,17 +500,443 @@ context.getCallingBundle().then((data) => {
}); });
``` ```
## Context.getCacheDir
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.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the cache directory.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getCacheDir();
context.getCacheDir((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
});
```
## Context.getCacheDir
getCacheDir(): Promise\<string>
Obtains the cache directory of the application on the internal storage. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| --------------- | ------------------------- |
| Promise\<string> | Promise used to return the cache directory.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getCacheDir().then((data) => {
console.info("======================>getCacheDirPromsie====================>");
console.info("====>data====>" + JSON.stringify(data));
});
```
## Context.getFilesDir
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.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the file directory.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getFilesDir();
context.getFilesDir((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
});
```
## Context.getFilesDir
getFilesDir(): Promise\<string>
Obtains the file directory of the application on the internal storage. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| --------------- | ------------------------- |
| Promise\<string> | Promise used to return the file directory.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getFilesDir().then((data) => {
console.info("======================>getFilesDirPromsie====================>");
console.info("====>data====>" + JSON.stringify(data));
});
```
## Context.getOrCreateDistributedDir
getOrCreateDistributedDir(callback: AsyncCallback\<string>): void
Obtains the distributed file path for storing ability or application data files. This API uses an asynchronous callback to return the result.
If the distributed file path does not exist, the system will create one and return the created path.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**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.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getOrCreateDistributedDir((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
});
```
## Context.getOrCreateDistributedDir
getOrCreateDistributedDir(): Promise\<string>
Obtains the distributed file path for storing ability or application data files. This API uses a promise to return the result.
If the distributed file path does not exist, the system will create one and return the created path.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| 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**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getOrCreateDistributedDir().then((data) => {
console.info("====>data====>" + JSON.stringify(data));
});
```
## Context.getAppType
getAppType(callback: AsyncCallback\<string>): void
Obtains the application type. 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 application type.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getAppType((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
});
```
## Context.getAppType
getAppType(): Promise\<string>
Obtains the application type. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| --------------- | ------------------------- |
| Promise\<string> | Promise used to return the application type.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getAppType().then((data) => {
console.info("====>data====>" + JSON.stringify(data));
});
```
## Context.getHapModuleInfo
getHapModuleInfo(callback: AsyncCallback\<HapModuleInfo>): void
Obtains the **ModuleInfo** object of the application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------- |
| callback | AsyncCallback\<[HapModuleInfo](#hapmoduleinfo)> | Yes | Callback used to return the **ModuleInfo** object.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getHapModuleInfo((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
});
```
## Context.getHapModuleInfo
getHapModuleInfo(): Promise\<HapModuleInfo>
Obtains the **ModuleInfo** object of the application. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| --------------- | ------------------------- |
| Promise\<[HapModuleInfo](#hapmoduleinfo)> | Promise used to return the **ModuleInfo** object.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getHapModuleInfo().then((data) => {
console.info("====>data====>" + JSON.stringify(data));
});
```
## Context.getAppVersionInfo
getAppVersionInfo(callback: AsyncCallback\<HapModuleInfo>): void
Obtains the version information of the 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.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getAppVersionInfo((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
});
```
## Context.getAppVersionInfo
getAppVersionInfo(): Promise\<AppVersionInfo>
Obtains the version information of the application. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| --------------- | ------------------------- |
| Promise\<[AppVersionInfo](#appversioninfo)> | Promise used to return the version information.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getAppVersionInfo().then((data) => {
console.info("====>data====>" + JSON.stringify(data));
});
```
## Context.getAbilityInfo
getAbilityInfo(callback: AsyncCallback\<AbilityInfo>): void
Obtains information of the current 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](#abilityInfo)> | Yes |Callback used to return the ability information.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getAbilityInfo((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
});
```
## Context.getAbilityInfo
getAbilityInfo(): Promise\<AbilityInfo>
Obtains information of the current ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type | Description |
| --------------- | ------------------------- |
| Promise\<[AbilityInfo](#abilityInfo)> | Promise used to return the ability information.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getAbilityInfo().then((data) => {
console.info("====>data====>" + JSON.stringify(data));
});
```
## Context.getApplicationContext
getApplicationContext(): Context
Obtains the context of the application.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Parameters | Type | Description |
| --------------- | ------------------------- |------ |
| Context | Context |Application context.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext().getApplicationContext();
```
## PermissionOptions ## PermissionOptions
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Readable/Writable| Type | Mandatory| Description | | Name| Readable/Writable| Type | Mandatory| Description |
| ---- | -------- | ------ | ---- | ------ | | ---- | -------- | ------ | ---- | ------ |
| pid | Read-only | number | No | PID.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core| | pid | Read-only | number | No | Process ID.|
| uid | Read-only | number | No | UID.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core| | uid | Read-only | number | No | User ID.|
## PermissionRequestResult ## PermissionRequestResult
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Readable/Writable| Type | Mandatory| Description | | Name | Readable/Writable| Type | Mandatory| Description |
| ----------- | -------- | -------------- | ---- | ------------------ | | ----------- | -------- | -------------- | ---- | ------------------ |
| requestCode | Read-only | number | Yes | Request code passed.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core| | requestCode | Read-only | number | Yes | Request code passed.|
| permissions | Read-only | Array\<string> | Yes | Permissions passed.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core | | permissions | Read-only | Array\<string> | Yes | Permissions requested. |
| authResults | Read-only | Array\<number> | Yes | Permission request result.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core | | authResults | Read-only | Array\<number> | Yes | Permission request result. |
## HapModuleInfo
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 | Modes supported by the module. |
| reqCapabilities | Array<string> | Yes | No | Capabilities required for module running.|
| deviceTypes | Array<string> | Yes | No | An array of supported device types.|
| abilityInfo | Array<AbilityInfo> | Yes | No | Ability information. |
| moduleName | string | Yes | No | Module name. |
| mainAbilityName | string | Yes | No | Name of the entrance ability. |
| installationFree | boolean | Yes | No | When installation-free is supported. |
| mainElementName | string | Yes| No| Information about the entry ability.|
## AppVersionInfo
| Name | Type| Readable | Writable | Description|
| ------ | ------ | ------| ------ | ------ |
| appName | string | Yes | No | Module name. |
| versionCode | number | Yes | No | Module description. |
| versionName | string | Yes | No | Module description ID. |
# DataUriUtils Module # DataUriUtils Module
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
```js ```js
...@@ -12,15 +15,17 @@ getId(uri: string): number ...@@ -12,15 +15,17 @@ getId(uri: string): number
Obtains the ID attached to the end of a given URI. Obtains the ID attached to the end of a given URI.
**Parameters** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description| | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------------------- | | ---- | ------ | ---- | --------------------------- |
| uri | string | Yes| URI object from which the ID is to be obtained.| | uri | string | Yes | URI object from which the ID is to be obtained.|
**Return value** **Return value**
| Type| Description|
| Type | Description |
| ------ | ------------------------ | | ------ | ------------------------ |
| number | ID obtained from the URI object.| | number | ID obtained from the URI object.|
...@@ -38,16 +43,18 @@ attachId(uri: string, id: number): string ...@@ -38,16 +43,18 @@ attachId(uri: string, id: number): string
Attaches an ID to the end of a given URI. Attaches an ID to the end of a given URI.
**Parameters** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description| | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------------------- | | ---- | ------ | ---- | --------------------------- |
| uri | string | Yes| URI object to which an ID is to be attached.| | uri | string | Yes | URI object to which an ID is to be attached.|
| id | number | Yes| ID to be attached.| | id | number | Yes | ID to be attached. |
**Return value** **Return value**
| Type| Description|
| Type | Description |
| ------ | --------------------- | | ------ | --------------------- |
| string | URI object with the ID attached.| | string | URI object with the ID attached.|
...@@ -69,14 +76,17 @@ deleteId(uri: string): string ...@@ -69,14 +76,17 @@ deleteId(uri: string): string
Deletes the ID from the end of a given URI. Deletes the ID from the end of a given URI.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------------------- | | ---- | ------ | ---- | --------------------------- |
| uri | string | Yes| URI object from which the ID is to be deleted.| | uri | string | Yes | URI object from which the ID is to be deleted.|
**Return value** **Return value**
| Type| Description|
| Type | Description |
| ------ | ------------------- | | ------ | ------------------- |
| string | URI object with the ID deleted.| | string | URI object with the ID deleted.|
...@@ -94,15 +104,18 @@ updateId(uri: string, id: number): string ...@@ -94,15 +104,18 @@ updateId(uri: string, id: number): string
Updates the ID in a given URI. Updates the ID in a given URI.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ------------------- | | ---- | ------ | ---- | ------------------- |
| uri | string | Yes| URI object to be updated.| | uri | string | Yes | URI object to be updated.|
| id | number | Yes| New ID.| | id | number | Yes | New ID. |
**Return value** **Return value**
| Type| Description|
| Type | Description |
| ------ | --------------- | | ------ | --------------- |
| string | URI object with the new ID.| | string | URI object with the new ID.|
......
...@@ -14,7 +14,7 @@ Before using the **AbilityContext** module, you must define a child class that i ...@@ -14,7 +14,7 @@ Before using the **AbilityContext** module, you must define a child class that i
``` ```js
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
class MainAbility extends Ability { class MainAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
...@@ -28,28 +28,28 @@ class MainAbility extends Ability { ...@@ -28,28 +28,28 @@ class MainAbility extends Ability {
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| abilityInfo | AbilityInfo | Yes| No| Ability information.| | abilityInfo | AbilityInfo | Yes| No| Ability information.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.| | currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
## startAbility ## AbilityContext.startAbility
startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void
Starts an ability. This method uses a callback to return the result. Starts an ability. This API uses a callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.| | want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
- Example **Example**
```
```js
var want = { var want = {
"deviceId": "", "deviceId": "",
"bundleName": "com.extreme.test", "bundleName": "com.extreme.test",
...@@ -61,26 +61,25 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -61,26 +61,25 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## startAbility ## AbilityContext.startAbility
startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&gt;): void startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&gt;): void
Starts an ability. This method uses a callback to return the result. Starts an ability. This API uses a callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters | Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.| | want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | Yes| Parameters used for starting the ability.| | options | StartOptions | Yes| Parameters used for starting the ability.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
- Example **Example**
``` ```js
var want = { var want = {
"deviceId": "", "deviceId": "",
"bundleName": "com.extreme.test", "bundleName": "com.extreme.test",
...@@ -95,29 +94,30 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -95,29 +94,30 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## startAbility ## AbilityContext.startAbility
startAbility(want: Want, options: StartOptions): Promise&lt;void&gt;; startAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;;
Starts an ability. This method uses a promise to return the result. Starts an ability. This API uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.| | want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | Yes| Parameters used for starting the ability.| | options | StartOptions | No| Parameters used for starting the ability.|
**Return value**
- Return value
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
- Example **Example**
```
```js
var want = { var want = {
"deviceId": "", "deviceId": "",
"bundleName": "com.extreme.test", "bundleName": "com.extreme.test",
...@@ -135,25 +135,25 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -135,25 +135,25 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## startAbilityForResult ## AbilityContext.startAbilityForResult
startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;): void; startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;): void;
Starts an ability. This method uses a callback to return the execution result when the ability is terminated. Starts an ability. This API uses a callback to return the execution result when the ability is terminated.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want |[Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.| | want |[Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
- Example **Example**
```
```js
this.context.startAbilityForResult( this.context.startAbilityForResult(
{bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"},
(error, result) => { (error, result) => {
...@@ -163,17 +163,16 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -163,17 +163,16 @@ SystemCapability.Ability.AbilityRuntime.Core
); );
``` ```
## startAbilityForResult ## AbilityContext.startAbilityForResult
startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback&lt;AbilityResult&gt;): void; startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback&lt;AbilityResult&gt;): void;
Starts an ability. This method uses a callback to return the execution result when the ability is terminated. Starts an ability. This API uses a callback to return the execution result when the ability is terminated.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want |[Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.| | want |[Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
...@@ -181,8 +180,9 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -181,8 +180,9 @@ SystemCapability.Ability.AbilityRuntime.Core
| callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
- Example **Example**
```
```js
var options = { var options = {
windowMode: 0, windowMode: 0,
}; };
...@@ -196,30 +196,31 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -196,30 +196,31 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## startAbilityForResult ## AbilityContext.startAbilityForResult
startAbilityForResult(want: Want, options: StartOptions): Promise&lt;AbilityResult&gt;; startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityResult&gt;;
Starts an ability. This method uses a promise to return the execution result when the ability is terminated. Starts an ability. This API uses a promise to return the execution result when the ability is terminated.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.| | want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | Yes| Parameters used for starting the ability.| | options | StartOptions | No| Parameters used for starting the ability.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Promise used to return the result.| | Promise&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Promise used to return the result.|
- Example **Example**
```
```js
var options = { var options = {
windowMode: 0, windowMode: 0,
}; };
...@@ -231,46 +232,46 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -231,46 +232,46 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## terminateSelf ## AbilityContext.terminateSelf
terminateSelf(callback: AsyncCallback&lt;void&gt;): void; terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
Terminates this ability. This method uses a callback to return the result. Terminates this ability. This API uses a callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the method is successfully called.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.|
- Example **Example**
```
```js
this.context.terminateSelf((err) => { this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringfy(err)); console.log('terminateSelf result:' + JSON.stringfy(err));
}); });
``` ```
## terminateSelf ## AbilityContext.terminateSelf
terminateSelf(): Promise&lt;void&gt;; terminateSelf(): Promise&lt;void&gt;;
Terminates this ability. This method uses a promise to return the result. Terminates this ability. This API uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Return value**
- Return value
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the method is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
- Example **Example**
```
```js
this.context.terminateSelf(want).then((data) => { this.context.terminateSelf(want).then((data) => {
console.log('success:' + JSON.stringfy(data)); console.log('success:' + JSON.stringfy(data));
}).catch((error) => { }).catch((error) => {
...@@ -279,24 +280,24 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -279,24 +280,24 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## terminateSelfWithResult ## AbilityContext.terminateSelfWithResult
terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;void&gt;): void; terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;void&gt;): void;
Terminates this ability. This method uses a callback to return the information to the caller of **startAbilityForResult**. Terminates this ability. This API uses a callback to return the information to the caller of **startAbilityForResult**.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.| | parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
- Example **Example**
```
```js
this.context.terminateSelfWithResult( this.context.terminateSelfWithResult(
{ {
want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"}, want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"},
...@@ -308,28 +309,29 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -308,28 +309,29 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## terminateSelfWithResult ## AbilityContext.terminateSelfWithResult
terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;; terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;;
Terminates this ability. This method uses a promise to return information to the caller of **startAbilityForResult**. Terminates this ability. This API uses a promise to return information to the caller of **startAbilityForResult**.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.| | parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
- Example **Example**
```
```js
this.context.terminateSelfWithResult( this.context.terminateSelfWithResult(
{ {
want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"}, want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"},
...@@ -341,29 +343,29 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -341,29 +343,29 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## startAbilityByCall ## AbilityContext.startAbilityByCall
startAbilityByCall(want: Want): Promise&lt;Caller&gt;; startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
Obtains the caller interface of the specified ability, and if the specified ability is not started, starts the ability in the background. Obtains the caller interface of the specified ability, and if the specified ability is not started, starts the ability in the background.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters | Name| Type| Mandatory| Description|
| 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.| | 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 **Return value**
| Type| Description|
| Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;&gt; | Promise used to return the caller object to communicate with.| | Promise&lt;Caller&gt; | Promise used to return the caller object to communicate with.|
- Example **Example**
``` ```js
import Ability from '@ohos.application.Ability'; import Ability from '@ohos.application.Ability';
var caller; var caller;
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
...@@ -383,23 +385,22 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -383,23 +385,22 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## requestPermissionsFromUser ## AbilityContext.requestPermissionsFromUser
requestPermissionsFromUser(permissions: Array&lt;string&gt;, requestCallback: AsyncCallback&lt;PermissionRequestResult&gt;) : void; requestPermissionsFromUser(permissions: Array&lt;string&gt;, requestCallback: AsyncCallback&lt;PermissionRequestResult&gt;) : void;
Requests permissions from the user by displaying a pop-up window. This method uses a callback to return the result. Requests permissions from the user by displaying a pop-up window. This API uses a callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters | Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| Permissions to request.| | permissions | Array&lt;string&gt; | Yes| Permissions to request.|
| callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result indicating whether the method is successfully called.| | callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.|
- Example **Example**
``` ```
this.context.requestPermissionsFromUser(permissions,(result) => { this.context.requestPermissionsFromUser(permissions,(result) => {
...@@ -408,27 +409,27 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -408,27 +409,27 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## requestPermissionsFromUser ## AbilityContext.requestPermissionsFromUser
requestPermissionsFromUser(permissions: Array&lt;string&gt;) : Promise&lt;PermissionRequestResult&gt;; requestPermissionsFromUser(permissions: Array&lt;string&gt;) : Promise&lt;PermissionRequestResult&gt;;
Requests permissions from the user by displaying a pop-up window. This method uses a promise to return the result. Requests permissions from the user by displaying a pop-up window. This API uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters | Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| Permissions to request.| | permissions | Array&lt;string&gt; | Yes| Permissions to request.|
**Return value**
- Return value | Type| Description|
| Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result indicating whether the method is successfully called.| | Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result indicating whether the API is successfully called.|
- Example **Example**
``` ```
this.context.requestPermissionsFromUser(permissions).then((data) => { this.context.requestPermissionsFromUser(permissions).then((data) => {
...@@ -439,54 +440,53 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -439,54 +440,53 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## setMissionLabel ## AbilityContext.setMissionLabel
setMissionLabel(label: string, callback:AsyncCallback&lt;void&gt;): void; setMissionLabel(label: string, callback:AsyncCallback&lt;void&gt;): void;
Sets the label of the ability displayed in the task. This method uses a callback to return the result. Sets the label of the ability displayed in the task. This API uses a callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters | Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| label | string | Yes| Label of the ability to set.| | label | string | Yes| Label of the ability to set.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the method is successfully called.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.|
- Example **Example**
``` ```js
this.context.setMissionLabel("test",(result) => { this.context.setMissionLabel("test",(result) => {
console.log('requestPermissionsFromUserresult:' + JSON.stringfy(result)); console.log('requestPermissionsFromUserresult:' + JSON.stringfy(result));
}); });
``` ```
## setMissionLabel ## AbilityContext.setMissionLabel
setMissionLabel(label: string): Promise&lt;void&gt; setMissionLabel(label: string): Promise&lt;void&gt;
Sets the label of the ability displayed in the task. This method uses a promise to return the result. Sets the label of the ability displayed in the task. This API uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters | Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| label | string | Yes| Label of the ability to set.| | label | string | Yes| Label of the ability to set.|
- Return value **Return value**
| Type| Description|
| Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the method is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
- Example **Example**
``` ```js
this.context.setMissionLabel("test").then((data) => { this.context.setMissionLabel("test").then((data) => {
console.log('success:' + JSON.stringfy(data)); console.log('success:' + JSON.stringfy(data));
}).catch((error) => { }).catch((error) => {
......
...@@ -10,38 +10,39 @@ Provides ability running information. ...@@ -10,38 +10,39 @@ Provides ability running information.
## Usage ## Usage
The ability running information is obtained by using the **getAbilityRunningInfos** method in **abilityManager**. The ability running information is obtained by using the **getAbilityRunningInfos** API in **abilityManager**.
``` ```js
import abilitymanager from '@ohos.application.abilityManager'; import abilitymanager from '@ohos.application.abilityManager';
abilitymanager.getAbilityRunningInfos((err,data) => { abilitymanager.getAbilityRunningInfos((err,data) => {
console.log("getAbilityRunningInfos err: " + err + " data: " + JSON.stringify(data)); console.log("getAbilityRunningInfos err: " + err + " data: " + JSON.stringify(data));
}); });
``` ```
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| ability | ElementName | Yes| No| Information that matches an ability.| | ability | ElementName | Yes| No| Information that matches an ability. |
| pid | number | Yes| No| Process ID.| | pid | number | Yes| No| Process ID.|
| uid | number | Yes| No| User ID.| | uid | number | Yes| No| User ID. |
| processName | string | Yes| No| Process name.| | processName | string | Yes| No| Process name. |
| startTime | number | Yes| No| Ability start time.| | startTime | number | Yes| No| Ability start time. |
| abilityState | [abilityManager.AbilityState](#abilitymanager-abilitystate) | Yes| No| Ability state.| | abilityState | [abilityManager.AbilityState](#abilitymanager-abilitystate) | Yes| No| Ability state. |
## abilityManager.AbilityState ## abilityManager.AbilityState
Enumerates the ability states. Enumerates the ability states.
| Name| Value| Description| **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| INITIAL | 0 | The ability is in the initial state.| | INITIAL | 0 | The ability is in the initial state.|
| FOREGROUND | 9 | The ability is in the foreground state.| | FOREGROUND | 9 | The ability is in the foreground state. |
| BACKGROUND | 10 | The ability is in the background state.| | BACKGROUND | 10 | The ability is in the background state. |
| FOREGROUNDING | 11 | The ability is in the foregrounding state.| | FOREGROUNDING | 11 | The ability is in the foregrounding state. |
| BACKGROUNDING | 12 | The ability is in the backgrounding state.| | BACKGROUNDING | 12 | The ability is in the backgrounding state. |
...@@ -14,7 +14,7 @@ The ability stage context is obtained through an **AbilityStage** instance. ...@@ -14,7 +14,7 @@ The ability stage context is obtained through an **AbilityStage** instance.
``` ```js
import AbilityStage from '@ohos.application.AbilityStage'; import AbilityStage from '@ohos.application.AbilityStage';
class MyAbilityStage extends AbilityStage { class MyAbilityStage extends AbilityStage {
onCreate() { onCreate() {
...@@ -25,8 +25,9 @@ class MyAbilityStage extends AbilityStage { ...@@ -25,8 +25,9 @@ class MyAbilityStage extends AbilityStage {
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| currentHapModuleInfo | HapModuleInfo | Yes| No| **ModuleInfo** object corresponding to the **AbilityStage**.| | currentHapModuleInfo | HapModuleInfo | Yes| No| **ModuleInfo** object corresponding to the **AbilityStage**.|
| config | [Configuration](js-apis-configuration.md) | Yes| No| Configuration for the environment where the application is running.| | config | [Configuration](js-apis-configuration.md) | Yes| No| Configuration for the environment where the application is running.|
# Ability # Ability
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Manages the ability lifecycle and context. Manages the ability lifecycle and context.
...@@ -14,31 +14,33 @@ Manages the ability lifecycle and context. ...@@ -14,31 +14,33 @@ Manages the ability lifecycle and context.
import Ability from '@ohos.application.Ability'; import Ability from '@ohos.application.Ability';
``` ```
## Attributes ## Attributes
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| context | [AbilityContext](js-apis-ability-context.md) | Yes| No| Context of an ability.| | context | [AbilityContext](js-apis-ability-context.md) | Yes| No| Context of an ability.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore|
| launchWant | [Want](js-apis-featureAbility.md#Want)| Yes| No| Parameters for starting the ability.| | launchWant | [Want](js-apis-featureAbility.md#Want)| Yes| No| Parameters for starting the ability.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore|
| lastRequestWant | [Want](js-apis-featureAbility.md#Want)| Yes| No| Parameters used when the ability was started last time.| | lastRequestWant | [Want](js-apis-featureAbility.md#Want)| Yes| No| Parameters used when the ability was started last time.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore|
## onCreate ## Ability.onCreate
onCreate(want: Want, param: LaunchParam): void onCreate(want: Want, param: AbilityConstant.LaunchParam): void;
Called to initialize the service logic when an ability is created. Called to initialize the service logic when an ability is created.
- Parameters **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information related to this ability, including the ability name and bundle name.| | want | [Want](js-apis-featureAbility.md#Want)| Yes| Information related to this ability, including the ability name and bundle name.|
| param | LaunchParam | Yes| Parameters for starting the ability, and the reason for the last abnormal exit.| | param | AbilityConstant.LaunchParam | Yes| Parameters for starting the ability, and the reason for the last abnormal exit.|
- Example **Example**
``` ```js
class myAbility extends Ability { class myAbility extends Ability {
onCreate(want, param) { onCreate(want, param) {
console.log('onCreate, want:' + want.abilityName); console.log('onCreate, want:' + want.abilityName);
...@@ -47,20 +49,23 @@ Called to initialize the service logic when an ability is created. ...@@ -47,20 +49,23 @@ Called to initialize the service logic when an ability is created.
``` ```
## onWindowStageCreate ## Ability.onWindowStageCreate
onWindowStageCreate(windowStage: window.WindowStage): void onWindowStageCreate(windowStage: window.WindowStage): void
Called when a **WindowStage** is created for this ability. Called when a **WindowStage** is created for this ability.
- Parameters **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| windowStage | window.WindowStage | Yes| **WindowStage** information.| | windowStage | window.WindowStage | Yes| **WindowStage** information.|
- Example **Example**
``` ```js
class myAbility extends Ability { class myAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate'); console.log('onWindowStageCreate');
...@@ -69,15 +74,17 @@ Called when a **WindowStage** is created for this ability. ...@@ -69,15 +74,17 @@ Called when a **WindowStage** is created for this ability.
``` ```
## onWindowStageDestroy ## Ability.onWindowStageDestroy
onWindowStageDestroy(): void onWindowStageDestroy(): void
Called when the **WindowStage** is destroyed for this ability. Called when the **WindowStage** is destroyed for this ability.
- Example **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Example**
``` ```js
class myAbility extends Ability { class myAbility extends Ability {
onWindowStageDestroy() { onWindowStageDestroy() {
console.log('onWindowStageDestroy'); console.log('onWindowStageDestroy');
...@@ -86,20 +93,23 @@ Called when the **WindowStage** is destroyed for this ability. ...@@ -86,20 +93,23 @@ Called when the **WindowStage** is destroyed for this ability.
``` ```
## onWindowStageRestore ## Ability.onWindowStageRestore
onWindowStageRestore(windowStage: window.WindowStage): void onWindowStageRestore(windowStage: window.WindowStage): void
Called when the **WindowStage** is restored during the migration of this ability, which is a multi-instance ability. Called when the **WindowStage** is restored during the migration of this ability, which is a multi-instance ability.
- Parameters **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| windowStage | window.WindowStage | Yes| **WindowStage** information.| | windowStage | window.WindowStage | Yes| **WindowStage** information.|
- Example **Example**
``` ```js
class myAbility extends Ability { class myAbility extends Ability {
onWindowStageRestore(windowStage) { onWindowStageRestore(windowStage) {
console.log('onWindowStageRestore'); console.log('onWindowStageRestore');
...@@ -108,15 +118,17 @@ Called when the **WindowStage** is restored during the migration of this ability ...@@ -108,15 +118,17 @@ Called when the **WindowStage** is restored during the migration of this ability
``` ```
## onDestroy ## Ability.onDestroy
onDestroy(): void; onDestroy(): void;
Called when this ability is destroyed to clear resources. Called when this ability is destroyed to clear resources.
- Example **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Example**
``` ```js
class myAbility extends Ability { class myAbility extends Ability {
onDestroy() { onDestroy() {
console.log('onDestroy'); console.log('onDestroy');
...@@ -125,15 +137,17 @@ Called when this ability is destroyed to clear resources. ...@@ -125,15 +137,17 @@ Called when this ability is destroyed to clear resources.
``` ```
## onForeground ## Ability.onForeground
onForeground(): void; onForeground(): void;
Called when this ability is running in the foreground. Called when this ability is running in the foreground.
- Example **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Example**
``` ```js
class myAbility extends Ability { class myAbility extends Ability {
onForeground() { onForeground() {
console.log('onForeground'); console.log('onForeground');
...@@ -142,15 +156,17 @@ Called when this ability is running in the foreground. ...@@ -142,15 +156,17 @@ Called when this ability is running in the foreground.
``` ```
## onBackground ## Ability.onBackground
onBackground(): void; onBackground(): void;
Callback when this ability is switched to the background. Callback when this ability is switched to the background.
- Example **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Example**
``` ```js
class myAbility extends Ability { class myAbility extends Ability {
onBackground() { onBackground() {
console.log('onBackground'); console.log('onBackground');
...@@ -159,25 +175,29 @@ Callback when this ability is switched to the background. ...@@ -159,25 +175,29 @@ Callback when this ability is switched to the background.
``` ```
## onContinue ## Ability.onContinue
onContinue(wantParam : {[key: string]: any}): boolean; onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;
Called to save data during the ability migration preparation process. Called to save data during the ability migration preparation process.
- Parameters **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| wantParam | {[key:&nbsp;string]:&nbsp;any} | Yes| **want** parameter.| | wantParam | {[key:&nbsp;string]:&nbsp;any} | Yes| **want** parameter.|
- Return value **Return value**
| Type| Description|
| Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the migration is accepted; returns **false** otherwise.| | AbilityConstant.OnContinueResult | Continuation result.|
- Example **Example**
``` ```js
class myAbility extends Ability { class myAbility extends Ability {
onContinue(wantParams) { onContinue(wantParams) {
console.log('onContinue'); console.log('onContinue');
...@@ -188,20 +208,23 @@ Called to save data during the ability migration preparation process. ...@@ -188,20 +208,23 @@ Called to save data during the ability migration preparation process.
``` ```
## onNewWant ## Ability.onNewWant
onNewWant(want: Want): void; onNewWant(want: Want): void;
Called when the ability startup mode is set to singleton. Called when the ability startup mode is set to singleton.
- Parameters **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Want parameters, such as the ability name and bundle name.| | want | [Want](js-apis-featureAbility.md#Want)| Yes| Want parameters, such as the ability name and bundle name.|
- Example **Example**
``` ```js
class myAbility extends Ability { class myAbility extends Ability {
onNewWant(want) { onNewWant(want) {
console.log('onNewWant, want:' + want.abilityName); console.log('onNewWant, want:' + want.abilityName);
...@@ -210,20 +233,23 @@ Called when the ability startup mode is set to singleton. ...@@ -210,20 +233,23 @@ Called when the ability startup mode is set to singleton.
``` ```
## onConfigurationUpdated ## Ability.onConfigurationUpdated
onConfigurationUpdated(config: Configuration): void; onConfigurationUpdated(config: Configuration): void;
Called when the configuration of the environment where the ability is running is updated. Called when the configuration of the environment where the ability is running is updated.
- Parameters **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [Configuration](#section188911144124715) | Yes| New configuration.| | config | [Configuration](#section188911144124715) | Yes| New configuration.|
- Example **Example**
``` ```js
class myAbility extends Ability { class myAbility extends Ability {
onConfigurationUpdated(config) { onConfigurationUpdated(config) {
console.log('onConfigurationUpdated, config:' + JSON.stringify(config)); console.log('onConfigurationUpdated, config:' + JSON.stringify(config));
...@@ -237,31 +263,36 @@ Called when the configuration of the environment where the ability is running is ...@@ -237,31 +263,36 @@ Called when the configuration of the environment where the ability is running is
Implements sending of sequenceable data to the target ability when an ability (caller) invokes the target ability (callee). Implements sending of sequenceable data to the target ability when an ability (caller) invokes the target ability (callee).
### call ## Caller.call
call(method, data: rpc.Sequenceable): Promise&lt;void&gt;; call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;;
Sends sequenceable data to the target ability. Sends sequenceable data to the target ability.
- Parameters **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.| | method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.|
| data | rpc.Sequenceable | Yes| Sequenceable data. You need to customize the data.| | data | rpc.Sequenceable | Yes| Sequenceable data. You need to customize the data.|
- Return value **Return value**
| Type| Description|
| Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return a response.| | Promise&lt;void&gt; | Promise used to return a response.|
- Example **Example**
``` ```js
import Ability from '@ohos.application.Ability'; import Ability from '@ohos.application.Ability';
class MyMessageAble{ // Custom sequenceable data structure class MyMessageAble{ // Custom sequenceable data structure
num: 0 constructor(name, str) {
str: '' this.name = name;
constructor() {} this.str = str;
}
marshalling(messageParcel) { marshalling(messageParcel) {
messageParcel.writeInt(this.num); messageParcel.writeInt(this.num);
messageParcel.writeString(this.str); messageParcel.writeString(this.str);
...@@ -279,47 +310,59 @@ Sends sequenceable data to the target ability. ...@@ -279,47 +310,59 @@ Sends sequenceable data to the target ability.
var caller; var caller;
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
caller = await this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: "com.example.myservice", bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility", abilityName: "com.example.myservice.MainAbility",
deviceId: "" deviceId: ""
}); }).then((obj) => {
let msg = new MyMessageAble(1, "world"); // See the definition of Sequenceable. caller = obj;
caller.call(method, msg) let msg = new MyMessageAble(1, "world"); // See the definition of Sequenceable.
.then(() => { caller.call(method, msg)
console.log('Caller call() called'); .then(() => {
}).catch((e) => { console.log('Caller call() called');
console.log('Caller call() catch error ' + e); }).catch((e) => {
}); console.log('Caller call() catch error ' + e);
});
console.log('Caller GetCaller Get ' + caller);
}).catch((e) => {
console.log('Caller GetCaller error ' + e);
});
} }
} }
``` ```
### callWithResult ## Caller.callWithResult
callWithResult(method, data: rpc.Sequenceable): Promise&lt;rpc.MessageParcel&gt;; callWithResult(method: string, data: rpc.Sequenceable): Promise&lt;rpc.MessageParcel&gt;;
Sends sequenceable data to the target ability and obtains the sequenceable data returned by the target ability. Sends sequenceable data to the target ability and obtains the sequenceable data returned by the target ability.
- Parameters **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.| | method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.|
| data | rpc.Sequenceable | Yes| Sequenceable data. You need to customize the data.| | data | rpc.Sequenceable | Yes| Sequenceable data. You need to customize the data.|
- Return value **Return value**
| Type| Description|
| Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;rpc.MessageParcel&gt; | Promise used to return the sequenceable data from the target ability.| | Promise&lt;rpc.MessageParcel&gt; | Promise used to return the sequenceable data from the target ability.|
- Example **Example**
``` ```js
import Ability from '@ohos.application.Ability'; import Ability from '@ohos.application.Ability';
class MyMessageAble{ class MyMessageAble{
num: 0 constructor(name, str) {
str: '' this.name = name;
this.str = str;
}
constructor() {} constructor() {}
marshalling(messageParcel) { marshalling(messageParcel) {
messageParcel.writeInt(this.num); messageParcel.writeInt(this.num);
...@@ -338,83 +381,104 @@ Sends sequenceable data to the target ability and obtains the sequenceable data ...@@ -338,83 +381,104 @@ Sends sequenceable data to the target ability and obtains the sequenceable data
var caller; var caller;
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
caller = await this.context.startAbilityByCall({ onWindowStageCreate(windowStage) {
bundleName: "com.example.myservice", this.context.startAbilityByCall({
abilityName: "com.example.myservice.MainAbility", bundleName: "com.example.myservice",
deviceId: "" abilityName: "com.example.myservice.MainAbility",
}); deviceId: ""
let msg = new MyMessageAble(1, "world"); }).then((obj) => {
caller.callWithResult(method, msg) caller = obj;
.then((data) => { let msg = new MyMessageAble(1, "world");
console.log('Caller call() called'); caller.callWithResult(method, msg)
let retmsg = new MyMessageAble(0, ""); .then((data) => {
data.readSequenceable(retmsg); console.log('Caller callWithResult() called');
}).catch((e) => { let retmsg = new MyMessageAble(0, "");
console.log('Caller call() catch error ' + e); data.readSequenceable(retmsg);
}); }).catch((e) => {
console.log('Caller callWithResult() catch error ' + e);
});
console.log('Caller GetCaller Get ' + caller);
}).catch((e) => {
console.log('Caller GetCaller error ' + e);
});
} }
} }
``` ```
### release ## Caller.release
release(): void; release(): void;
Releases the caller interface of the target ability. Releases the caller interface of the target ability.
- Example **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Example**
``` ```js
import Ability from '@ohos.application.Ability'; import Ability from '@ohos.application.Ability';
var caller; var caller;
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
caller = await this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: "com.example.myservice", bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility", abilityName: "com.example.myservice.MainAbility",
deviceId: "" deviceId: ""
}); }).then((obj) => {
try { caller = obj;
caller.release(); try {
} catch (e) { caller.release();
console.log('Caller Release error ' + e); } catch (e) {
} console.log('Caller Release error ' + e);
}
console.log('Caller GetCaller Get ' + caller);
}).catch((e) => {
console.log('Caller GetCaller error ' + e);
});
} }
} }
``` ```
### onRelease ## Caller.onRelease
onRelease(callback: function): void; onRelease(callback: OnReleaseCallBack): void;
Registers a callback that is invoked when the Stub on the target ability is disconnected. Registers a callback that is invoked when the Stub on the target ability is disconnected.
- Parameters **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | function | Yes| Callback used for the **onRelease** method.| | callback | OnReleaseCallBack | Yes| Callback used for the **onRelease** API.|
- Example **Example**
``` ```js
import Ability from '@ohos.application.Ability'; import Ability from '@ohos.application.Ability';
var caller; var caller;
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
caller = await this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: "com.example.myservice", bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility", abilityName: "com.example.myservice.MainAbility",
deviceId: "" deviceId: ""
}); }).then((obj) => {
try { caller = obj;
caller.onRelease((str) => { try {
console.log(' Caller OnRelease CallBack is called ' + str); caller.onRelease((str) => {
}); console.log(' Caller OnRelease CallBack is called ' + str);
} catch (e) { });
console.log('Caller Release error ' + e); } catch (e) {
} console.log('Caller Release error ' + e);
}
console.log('Caller GetCaller Get ' + caller);
}).catch((e) => {
console.log('Caller GetCaller error ' + e);
});
} }
} }
``` ```
...@@ -425,26 +489,30 @@ Registers a callback that is invoked when the Stub on the target ability is disc ...@@ -425,26 +489,30 @@ Registers a callback that is invoked when the Stub on the target ability is disc
Implements callbacks for caller notification registration and unregistration. Implements callbacks for caller notification registration and unregistration.
### on ## Callee.on
on(method: string, callback: function): void; on(method: string, callback: CaleeCallBack): void;
Registers a caller notification callback, which is invoked when the target ability registers a function. Registers a caller notification callback, which is invoked when the target ability registers a function.
- Parameters **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| method | string | Yes| Notification message string negotiated between the two abilities.| | method | string | Yes| Notification message string negotiated between the two abilities.|
| callback | function | Yes| JS notification synchronization callback of the **rpc.MessageParcel** type. The callback must return at least one empty **rpc.Sequenceable** object. Otherwise, the function execution fails.| | callback | CaleeCallBack | Yes| JS notification synchronization callback of the **rpc.MessageParcel** type. The callback must return at least one empty **rpc.Sequenceable** object. Otherwise, the function execution fails.|
- Example **Example**
``` ```js
import Ability from '@ohos.application.Ability'; import Ability from '@ohos.application.Ability';
class MyMessageAble{ class MyMessageAble{
num: 0 constructor(name, str) {
str: '' this.name = name;
constructor() {} this.str = str;
}
marshalling(messageParcel) { marshalling(messageParcel) {
messageParcel.writeInt(this.num); messageParcel.writeInt(this.num);
messageParcel.writeString(this.str); messageParcel.writeString(this.str);
...@@ -474,20 +542,23 @@ Registers a caller notification callback, which is invoked when the target abili ...@@ -474,20 +542,23 @@ Registers a caller notification callback, which is invoked when the target abili
``` ```
### off ## Callee.off
off(method: string): void; off(method: string): void;
Unregisters a caller notification callback, which is invoked when the target ability registers a function. Unregisters a caller notification callback, which is invoked when the target ability registers a function.
- Parameters **System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| method | string | Yes| Registered notification message string.| | method | string | Yes| Registered notification message string.|
- Example **Example**
``` ```js
import Ability from '@ohos.application.Ability'; import Ability from '@ohos.application.Ability';
var method = 'call_Function'; var method = 'call_Function';
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
...@@ -497,3 +568,20 @@ Unregisters a caller notification callback, which is invoked when the target abi ...@@ -497,3 +568,20 @@ Unregisters a caller notification callback, which is invoked when the target abi
} }
} }
``` ```
## OnReleaseCallBack
(msg: string): void;
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| (msg: string) | function | Yes| No| Prototype of the listener function interface registered by the caller.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore |
## CaleeCallBack
(indata: rpc.MessageParcel): rpc.Sequenceable;
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| (indata: rpc.MessageParcel) | rpc.Sequenceable | Yes| No| Prototype of the message listener function interface registered by the callee.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore |
...@@ -4,26 +4,29 @@ ...@@ -4,26 +4,29 @@
> 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.
Runtime class for HAP files. It provides methods to notify you when a HAP file starts loading. You can then initialize the HAP file, for example, pre-load resources and create threads. Runtime class for HAP files. It provides APIs to notify you when a HAP file starts loading. You can then initialize the HAP file, for example, pre-load resources and create threads.
## Modules to Import ## Modules to Import
``` ```js
import AbilityStage from '@ohos.application.AbilityStage'; import AbilityStage from '@ohos.application.AbilityStage';
``` ```
## AbilityStage.onCreate
## onCreate
onCreate(): void onCreate(): void
Called when the application is created. Called when the application is created.
- Example **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Example**
``` ```js
class MyAbilityStage extends AbilityStage { class MyAbilityStage extends AbilityStage {
onCreate() { onCreate() {
console.log("MyAbilityStage.onCreate is called") console.log("MyAbilityStage.onCreate is called")
...@@ -32,25 +35,29 @@ Called when the application is created. ...@@ -32,25 +35,29 @@ Called when the application is created.
``` ```
## onAcceptWant ## AbilityStage.onAcceptWant
onAcceptWant(want: Want): string; onAcceptWant(want: Want): string;
Called when a specified ability is started. Called when a specified ability is started.
- Parameters **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the ability to start, such as the ability name and bundle name.| | want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the ability to start, such as the ability name and bundle name.|
- Return value **Return value**
| Type| Description|
| Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Returns an ability ID. If this ability has been started, no new instance is created and the ability is placed at the top of the stack. Otherwise, a new instance is created and started.| | string | Returns an ability ID. If this ability has been started, no new instance is created and the ability is placed at the top of the stack. Otherwise, a new instance is created and started.|
- Example **Example**
``` ```js
class MyAbilityStage extends AbilityStage { class MyAbilityStage extends AbilityStage {
onAcceptWant(want) { onAcceptWant(want) {
console.log("MyAbilityStage.onAcceptWant called"); console.log("MyAbilityStage.onAcceptWant called");
...@@ -60,23 +67,33 @@ Called when a specified ability is started. ...@@ -60,23 +67,33 @@ Called when a specified ability is started.
``` ```
## onConfigurationUpdated ## AbilityStage.onConfigurationUpdated
onConfigurationUpdated(config: Configuration): void; onConfigurationUpdated(config: Configuration): void;
Called when the global configuration is updated. Called when the global configuration is updated.
- Parameters **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [Configuration](js-apis-configuration.md) | Yes| Callback invoked when the global configuration is updated. The global configuration indicates the configuration of the environment where the application is running and includes the language and color mode.| | config | [Configuration](js-apis-configuration.md) | Yes| Callback invoked when the global configuration is updated. The global configuration indicates the configuration of the environment where the application is running and includes the language and color mode.|
- Example **Example**
``` ```js
class MyAbilityStage extends AbilityStage { class MyAbilityStage extends AbilityStage {
onConfigurationUpdated(config) { onConfigurationUpdated(config) {
console.log('onConfigurationUpdated, language:' + config.language); console.log('onConfigurationUpdated, language:' + config.language);
} }
} }
``` ```
## AbilityStage.context
Describes the configuration information about the context.
| Name | Type | Description |
| ----------- | --------------------------- | ------------------------------------------------------------ |
| context | [AbilityStageContext](js-apis-featureAbility.md) | Called when initialization is performed during ability startup.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
...@@ -14,6 +14,7 @@ You must extend **AbilityContext** to implement this module. ...@@ -14,6 +14,7 @@ You must extend **AbilityContext** to implement this module.
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
...@@ -29,44 +30,51 @@ You must extend **AbilityContext** to implement this module. ...@@ -29,44 +30,51 @@ You must extend **AbilityContext** to implement this module.
| eventHub | [EventHub](js-apis-eventhub.md) | Yes| No| Event hub information.| | eventHub | [EventHub](js-apis-eventhub.md) | Yes| No| Event hub information.|
## createBundleContext ## Context.createBundleContext
createBundleContext(bundleName: string): Context; createBundleContext(bundleName: string): Context;
Creates an application context. Creates an application context.
- **Parameters** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Application bundle name.| | bundleName | string | Yes| Application bundle name.|
- Return value **Return value**
| Type| Description|
| Type| Description|
| -------- | -------- | | -------- | -------- |
| Context | Context of the application created.| | Context | Context of the application created.|
- Example **Example**
``` ```js
let test = "com.example.test"; let test = "com.example.test";
let context = this.context.createBundleContext(test); let context = this.context.createBundleContext(test);
``` ```
## getApplicationContext ## Context.getApplicationContext
getApplicationContext(): Context; getApplicationContext(): Context;
Obtains the context of this application. Obtains the context of this application.
- Return value **System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Type| Description|
**Return value**
| Type| Description|
| -------- | -------- | | -------- | -------- |
| Context | Context obtained.| | Context | Context obtained.|
- Example **Example**
``` ```js
// This part is mandatory. // This part is mandatory.
let context = this.context.getApplicationContext(); let context = this.context.getApplicationContext();
``` ```
# appManager # appManager
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> 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 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Implements application management. Implements application management.
...@@ -10,50 +10,159 @@ Implements application management. ...@@ -10,50 +10,159 @@ Implements application management.
## Modules to Import ## Modules to Import
``` ```js
import app from '@ohos.application.appManager'; import app from '@ohos.application.appManager';
``` ```
## isRunningInStabilityTest ## appManager.isRunningInStabilityTest<sup>8+</sup>
static isRunningInStabilityTest(callback: AsyncCallback&lt;boolean&gt;): void static isRunningInStabilityTest(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether this application is undergoing a stability test. This API uses a callback to return the result. Checks whether this application is undergoing a stability test. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters | Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return the result.| | callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
- Example **Example**
``` ```js
import app from '@ohos.application.appManager'; import app from '@ohos.application.appManager';
app.isRunningInStabilityTest((err, flag) => { app.isRunningInStabilityTest((err, flag) => {
console.log('startAbility result:' + JSON.stringfy(err); console.log('startAbility result:' + JSON.stringfy(err));
} })
``` ```
## isRunningInStabilityTest ## appManager.isRunningInStabilityTest<sup>8+</sup>
static isRunningInStabilityTest(): Promise&lt;boolean&gt; static isRunningInStabilityTest(): Promise&lt;boolean&gt;
Checks whether this application is undergoing a stability test. This method uses a promise to return the result. Checks whether this application is undergoing a stability test. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
- Return value | Type| Description|
| Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the result.| | Promise&lt;boolean&gt; | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
- Example **Example**
``` ```js
import app from '@ohos.application.appManager'; import app from '@ohos.application.appManager';
app.isRunningInStabilityTest().then((flag) => { app.isRunningInStabilityTest().then((flag) => {
console.log('success:' + JSON.stringfy(flag)); console.log('success:' + JSON.stringfy(flag));
)).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringfy(error)); console.log('failed:' + JSON.stringfy(error));
}); });
``` ```
## appManager.isRamConstrainedDevice
isRamConstrainedDevice(): Promise\<boolean>;
Checks whether this application is running in a RAM constrained device. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return whether the the application is running in a RAM constrained device. If the the application is running in a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
**Example**
```js
IsRamConstrainedDevicePromise(){
app.isRamConstrainedDevicePromise().then((data) => {
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
```
## appManager.isRamConstrainedDevice
isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void;
Checks whether this application is running in a RAM constrained device. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return whether the the application is running in a RAM constrained device. If the the application is running in a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
**Example**
```js
IsRamConstrainedDeviceCallBack(){
app.isRamConstrainedDevicePromise((err, data) => {
console.log('startAbility result failed:' + JSON.stringify(err));
console.log('startAbility result success:' + JSON.stringify(data));
})
}
```
## appManager.getAppMemorySize
getAppMemorySize(): Promise\<number>;
Obtains the memory size of this application. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Size of the application memory.|
**Example**
```js
GetAppMemorySize(){
app.getAppMemorySize().then((data) => {
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
```
## appManager.getAppMemorySize
getAppMemorySize(callback: AsyncCallback\<number>): void;
Obtains the memory size 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&lt;number&gt; | No| Size of the application memory.|
**Example**
```js
GetAppMemorySizeCallBack(){
app.getAppMemorySize((err, data) => {
console.log('startAbility result failed :' + JSON.stringify(err));
console.log('startAbility result success:' + JSON.stringify(data));
})
}
```
...@@ -10,17 +10,19 @@ Provides the configuration for the environment where the ability is running. ...@@ -10,17 +10,19 @@ Provides the configuration for the environment where the ability is running.
## Modules to Import ## Modules to Import
``` ```js
import Configuration from '@ohos.application.Configuration'; import Configuration from '@ohos.application.Configuration';
``` ```
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| language | string | Yes| Yes| Language of the application.| | language | string | Yes| Yes| Language of the application.|
| colorMode | [ColorMode](js-apis-configurationconstant.md) | Yes| Yes| Color mode, which can be **COLOR_MODE_LIGHT** or **COLOR_MODE_DARK**. The default value is **COLOR_MODE_LIGHT**.| | colorMode | [ColorMode](js-apis-configurationconstant.md) | Yes| Yes| Color mode, which can be **COLOR_MODE_LIGHT** or **COLOR_MODE_DARK**. The default value is **COLOR_MODE_LIGHT**.|
| direction | Direction | Yes| No| Screen orientation, which can be **DIRECTION_HORIZONTAL** or **DIRECTION_VERTICAL**.| | direction<sup>9+</sup> | Direction | Yes| No| Screen orientation, which can be **DIRECTION_HORIZONTAL** or **DIRECTION_VERTICAL**.|
| screenDensity | ScreenDensity | Yes| No| Screen resolution, which can be **SCREEN_DENSITY_SDPI** (120), **SCREEN_DENSITY_MDPI** (160), **SCREEN_DENSITY_LDPI** (240), **SCREEN_DENSITY_XLDPI** (320), **SCREEN_DENSITY_XXLDPI** (480), or **SCREEN_DENSITY_XXXLDPI** (640).| | screenDensity<sup>9+</sup> | ScreenDensity | Yes| No| Screen resolution, which can be **SCREEN_DENSITY_SDPI** (120), **SCREEN_DENSITY_MDPI** (160), **SCREEN_DENSITY_LDPI** (240), **SCREEN_DENSITY_XLDPI** (320), **SCREEN_DENSITY_XXLDPI** (480), or **SCREEN_DENSITY_XXXLDPI** (640).|
| displayId | number | Yes| No| ID of the display where the application is located.| | displayId<sup>9+</sup> | number | Yes| No| ID of the display where the application is located.|
...@@ -10,46 +10,67 @@ Defines enumerated values of the configuration for the environment where the abi ...@@ -10,46 +10,67 @@ Defines enumerated values of the configuration for the environment where the abi
## Modules to Import ## Modules to Import
``` ```js
import ConfigurationConstant from '@ohos.application.ConfigurationConstant'; import ConfigurationConstant from '@ohos.application.ConfigurationConstant';
``` ```
## ColorMode ## ConfigurationConstant.ColorMode
The value is obtained through the **ConfigurationConstant.ColorMode** API.
To obtain the value, use **ConfigurationConstant.ColorMode**, for example, **ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT**. **Example**
```
ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT
```
| Name| Value| Description| **System capability**: SystemCapability.Ability.AbilityBase
| Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| COLOR_MODE_NOT_SET | -1 | Unspecified color mode.| | COLOR_MODE_NOT_SET | -1 | Unspecified color mode.|
| COLOR_MODE_DARK | 0 | Dark mode.| | COLOR_MODE_DARK | 0 | Dark mode.|
| COLOR_MODE_LIGHT | 1 | Light mode.| | COLOR_MODE_LIGHT | 1 | Light mode.|
## Direction ## ConfigurationConstant.Direction
To obtain the value, use **ConfigurationConstant.Direction**, for example, **ConfigurationConstant.Direction.DIRECTION_VERTICAL**. The value is obtained through the **ConfigurationConstant.Direction** API.
**Example**
| Name| Value| Description| ```
ConfigurationConstant.Direction.DIRECTION_VERTICAL
```
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| DIRECTION_NOT_SET | -1 | Unspecified direction.| | DIRECTION_NOT_SET<sup>9+</sup> | -1 | Unspecified direction.|
| DIRECTION_VERTICAL | 0 | Vertical direction.| | DIRECTION_VERTICAL<sup>9+</sup> | 0 | Vertical direction.|
| DIRECTION_HORIZONTAL | 1 | Horizontal direction.| | DIRECTION_HORIZONTAL<sup>9+</sup> | 1 | Horizontal direction.|
## ConfigurationConstant.ScreenDensity
## ScreenDensity The value is obtained through the **ConfigurationConstant.ScreenDensity** API.
To obtain the value, use **ConfigurationConstant.ScreenDensity**, for example, **ConfigurationConstant.ScreenDensity.SCREEN_DENSITY_NOT_SET**. **Example**
```
ConfigurationConstant.ScreenDensity.SCREEN_DENSITY_NOT_SET
```
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| SCREEN_DENSITY_NOT_SET | 0 | Unspecified screen resolution.| | SCREEN_DENSITY_NOT_SET<sup>9+</sup> | 0 | Unspecified screen resolution.|
| SCREEN_DENSITY_SDPI | 120 | The screen resolution is sdpi.| | SCREEN_DENSITY_SDPI<sup>9+</sup> | 120 | The screen resolution is sdpi.|
| SCREEN_DENSITY_MDPI | 160 | The screen resolution is mdpi.| | SCREEN_DENSITY_MDPI<sup>9+</sup> | 160 | The screen resolution is mdpi.|
| SCREEN_DENSITY_LDPI | 240 | The screen resolution is ldpi.| | SCREEN_DENSITY_LDPI<sup>9+</sup> | 240 | The screen resolution is ldpi.|
| SCREEN_DENSITY_XLDPI | 320 | The screen resolution is xldpi.| | SCREEN_DENSITY_XLDPI<sup>9+</sup> | 320 | The screen resolution is xldpi.|
| SCREEN_DENSITY_XXLDPI | 480 | The screen resolution is xxldpi.| | SCREEN_DENSITY_XXLDPI<sup>9+</sup> | 480 | The screen resolution is xxldpi.|
| SCREEN_DENSITY_XXXLDPI | 640 | The screen resolution is xxxldpi.| | SCREEN_DENSITY_XXXLDPI<sup>9+</sup> | 640 | The screen resolution is xxxldpi.|
...@@ -8,17 +8,13 @@ import ohos_data_ability from '@ohos.data.dataability' ...@@ -8,17 +8,13 @@ import ohos_data_ability from '@ohos.data.dataability'
import ohos_data_rdb from '@ohos.data.rdb' import ohos_data_rdb from '@ohos.data.rdb'
``` ```
## DataAbilityHelper ## DataAbilityHelper.openFile
### openFile
openFile(uri: string, mode: string, callback: AsyncCallback\<number>): void openFile(uri: string, mode: string, callback: AsyncCallback\<number>): void
Opens a file with a specified URI. This method uses a callback to return the result. Opens a file with a specified URI. This API uses an asynchronous callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -44,15 +40,13 @@ DAHelper.openFile( ...@@ -44,15 +40,13 @@ DAHelper.openFile(
}); });
``` ```
### openFile ## DataAbilityHelper.openFile
openFile(uri: string, mode: string): Promise\<number> openFile(uri: string, mode: string): Promise\<number>
Opens a file with a specified URI. This method uses a promise to return the result. Opens a file with a specified URI. This API uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -62,6 +56,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel ...@@ -62,6 +56,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel
| mode | string | Yes | Mode for opening the file. The value can be **rwt**. | | mode | string | Yes | Mode for opening the file. The value can be **rwt**. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------- | ---------------- | | ---------------- | ---------------- |
| Promise\<number> | Promise used to return the file descriptor.| | Promise\<number> | Promise used to return the file descriptor.|
...@@ -81,15 +76,13 @@ DAHelper.openFile( ...@@ -81,15 +76,13 @@ DAHelper.openFile(
}); });
``` ```
### on('dataChange') ## DataAbilityHelper.on
on(type: 'dataChange', uri: string, callback: AsyncCallback\<void>): void on(type: 'dataChange', uri: string, callback: AsyncCallback\<void>): void
Registers an observer to observe data specified by a given URI. This method uses a callback to return the result. Registers an observer to observe data specified by a given URI. This API uses an asynchronous callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -116,15 +109,13 @@ helper.on( ...@@ -116,15 +109,13 @@ helper.on(
) )
``` ```
### off('dataChange') ## DataAbilityHelper.off
off(type: 'dataChange', uri: string, callback?: AsyncCallback\<void>): void off(type: 'dataChange', uri: string, callback?: AsyncCallback\<void>): void
Unregisters the observer used to observe data specified by a given URI. This method uses a callback to return the result. Unregisters the observer used to observe data specified by a given URI. This API uses an asynchronous callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -155,15 +146,13 @@ helper.off( ...@@ -155,15 +146,13 @@ helper.off(
) )
``` ```
### getType ## DataAbilityHelper.getType
getType(uri: string, callback: AsyncCallback\<string>): void getType(uri: string, callback: AsyncCallback\<string>): void
Obtains the MIME type of the data specified by a given URI. This method uses a callback to return the result. Obtains the MIME type of the data specified by a given URI. This API uses an asynchronous callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -186,15 +175,13 @@ DAHelper.getType( ...@@ -186,15 +175,13 @@ DAHelper.getType(
}); });
``` ```
### getType ## DataAbilityHelper.getType
getType(uri: string): Promise\<string> getType(uri: string): Promise\<string>
Obtains the MIME type of the data specified by a given URI. This method uses a promise to return the result. Obtains the MIME type of the data specified by a given URI. This API uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -203,6 +190,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel ...@@ -203,6 +190,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel
| uri | string | Yes | URI of the data.| | uri | string | Yes | URI of the data.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------- | ----------------------------------- | | ---------------- | ----------------------------------- |
| Promise\<string> | Promise used to return the MIME type.| | Promise\<string> | Promise used to return the MIME type.|
...@@ -221,15 +209,13 @@ DAHelper.getType( ...@@ -221,15 +209,13 @@ DAHelper.getType(
}); });
``` ```
### getFileTypes ## DataAbilityHelper.getFileTypes
getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array\<string>>): void getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array\<string>>): void
Obtains the supported MIME types of a specified file. This method uses a callback to return the result. Obtains the supported MIME types of a specified file. This API uses an asynchronous callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -256,15 +242,13 @@ DAHelper.getFileTypes( ...@@ -256,15 +242,13 @@ DAHelper.getFileTypes(
### getFileTypes ## DataAbilityHelper.getFileTypes
getFileTypes(uri: string, mimeTypeFilter: string): Promise\<Array\<string>> getFileTypes(uri: string, mimeTypeFilter: string): Promise\<Array\<string>>
Obtains the supported MIME types of a specified file. This method uses a promise to return the result. Obtains the supported MIME types of a specified file. This API uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -274,6 +258,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel ...@@ -274,6 +258,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel
| mimeTypeFilter | string | Yes | MIME type of the file.| | mimeTypeFilter | string | Yes | MIME type of the file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------ | ------------------------ | | ------------------------ | ------------------------ |
| Promise\<Array\<string>> | Promise used to return the supported MIME types.| | Promise\<Array\<string>> | Promise used to return the supported MIME types.|
...@@ -293,15 +278,13 @@ DAHelper.getFileTypes( ...@@ -293,15 +278,13 @@ DAHelper.getFileTypes(
}); });
``` ```
### normalizeUri ## DataAbilityHelper.normalizeUri
normalizeUri(uri: string, callback: AsyncCallback\<string>): void normalizeUri(uri: string, callback: AsyncCallback\<string>): void
Converts the URI that refers to a Data ability into a normalized URI. This method uses a callback to return the result. Converts the URI that refers to a Data ability into a normalized URI. This API uses an asynchronous callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -324,15 +307,13 @@ DAHelper.normalizeUri( ...@@ -324,15 +307,13 @@ DAHelper.normalizeUri(
}); });
``` ```
### normalizeUri ## DataAbilityHelper.normalizeUri
normalizeUri(uri: string): Promise\<string> normalizeUri(uri: string): Promise\<string>
Converts the URI that refers to a Data ability into a normalized URI. This method uses a promise to return the result. Converts the URI that refers to a Data ability into a normalized URI. This API uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -341,6 +322,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel ...@@ -341,6 +322,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel
| uri | string | Yes | URI object to normalize.| | uri | string | Yes | URI object to normalize.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------- | ------------------------------------------------------ | | ---------------- | ------------------------------------------------------ |
| Promise\<string> | Promise used to return the normalized URI object if the Data ability supports URI normalization. If the Data ability does not support URI normalization, **null** is returned.| | Promise\<string> | Promise used to return the normalized URI object if the Data ability supports URI normalization. If the Data ability does not support URI normalization, **null** is returned.|
...@@ -359,15 +341,13 @@ DAHelper.normalizeUri( ...@@ -359,15 +341,13 @@ DAHelper.normalizeUri(
}); });
``` ```
### denormalizeUri ## DataAbilityHelper.denormalizeUri
denormalizeUri(uri: string, callback: AsyncCallback\<string>): void denormalizeUri(uri: string, callback: AsyncCallback\<string>): void
Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: string, callback: AsyncCallback\<string>)** to a denormalized one. This method uses a callback to return the result. Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: string, callback: AsyncCallback\<string>)** to a denormalized one. This API uses an asynchronous callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -392,15 +372,13 @@ DAHelper.denormalizeUri( ...@@ -392,15 +372,13 @@ DAHelper.denormalizeUri(
### denormalizeUri ## DataAbilityHelper.denormalizeUri
denormalizeUri(uri: string): Promise\<string> denormalizeUri(uri: string): Promise\<string>
Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: string)** to a denormalized one. This method uses a promise to return the result. Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: string)** to a denormalized one. This API uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -409,6 +387,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel ...@@ -409,6 +387,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel
| uri | string | Yes | URI object to normalize.| | uri | string | Yes | URI object to normalize.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------- | ----------------------------------------- | | ---------------- | ----------------------------------------- |
| Promise\<string> | Promise used to return the denormalized URI object.| | Promise\<string> | Promise used to return the denormalized URI object.|
...@@ -427,15 +406,13 @@ DAHelper.denormalizeUri( ...@@ -427,15 +406,13 @@ DAHelper.denormalizeUri(
}); });
``` ```
### notifyChange ## DataAbilityHelper.notifyChange
notifyChange(uri: string, callback: AsyncCallback\<void>): void notifyChange(uri: string, callback: AsyncCallback\<void>): void
Notifies the registered observer of a change to the data specified by the URI. This method uses a callback to return the result. Notifies the registered observer of a change to the data specified by the URI. This API uses an asynchronous callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -458,15 +435,13 @@ helper.notifyChange( ...@@ -458,15 +435,13 @@ helper.notifyChange(
}); });
``` ```
### notifyChange ## DataAbilityHelper.notifyChange
notifyChange(uri: string): Promise\<void> notifyChange(uri: string): Promise\<void>
Notifies the registered observer of a change to the data specified by the URI. This method uses a promise to return the result. Notifies the registered observer of a change to the data specified by the URI. This API uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -475,6 +450,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel ...@@ -475,6 +450,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel
| uri | string | Yes | URI of the data.| | uri | string | Yes | URI of the data.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------- | | -------------- | --------------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result.|
...@@ -493,15 +469,13 @@ DAHelper.notifyChange( ...@@ -493,15 +469,13 @@ DAHelper.notifyChange(
}); });
``` ```
### insert ## DataAbilityHelper.insert
insert(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback\<number>): void insert(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback\<number>): void
Inserts a single data record into the database. This method uses a callback to return the result. Inserts a single data record into the database. This API uses an asynchronous callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -532,15 +506,13 @@ DAHelper.insert( ...@@ -532,15 +506,13 @@ DAHelper.insert(
}); });
``` ```
### insert ## DataAbilityHelper.insert
insert(uri: string, valuesBucket: rdb.ValuesBucket): Promise\<number> insert(uri: string, valuesBucket: rdb.ValuesBucket): Promise\<number>
Inserts a single data record into the database. This method uses a promise to return the result. Inserts a single data record into the database. This API uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -550,6 +522,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel ...@@ -550,6 +522,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel
| valuesBucket | rdb.ValuesBucket | Yes | Data record to insert. If this parameter is **null**, a blank row will be inserted.| | valuesBucket | rdb.ValuesBucket | Yes | Data record to insert. If this parameter is **null**, a blank row will be inserted.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------- | ------------------------ | | ---------------- | ------------------------ |
| Promise\<number> | Promise used to return the index of the inserted data record.| | Promise\<number> | Promise used to return the index of the inserted data record.|
...@@ -575,15 +548,13 @@ DAHelper.insert( ...@@ -575,15 +548,13 @@ DAHelper.insert(
}); });
``` ```
### batchInsert ## DataAbilityHelper.batchInsert
batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>, callback: AsyncCallback\<number>): void batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>, callback: AsyncCallback\<number>): void
Inserts multiple data records into the database. This method uses a callback to return the result. Inserts multiple data records into the database. This API uses an asynchronous callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -611,15 +582,13 @@ DAHelper.batchInsert( ...@@ -611,15 +582,13 @@ DAHelper.batchInsert(
}); });
``` ```
### batchInsert ## DataAbilityHelper.batchInsert
batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>): Promise\<number> batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>): Promise\<number>
Inserts multiple data records into the database. This method uses a promise to return the result. Inserts multiple data records into the database. This API uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -629,6 +598,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel ...@@ -629,6 +598,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel
| valuesBucket | Array<rdb.ValuesBucket> | Yes | Data record to insert. | | valuesBucket | Array<rdb.ValuesBucket> | Yes | Data record to insert. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------- | ---------------------- | | ---------------- | ---------------------- |
| Promise\<number> | Promise used to return the number of inserted data records.| | Promise\<number> | Promise used to return the number of inserted data records.|
...@@ -651,15 +621,13 @@ DAHelper.batchInsert( ...@@ -651,15 +621,13 @@ DAHelper.batchInsert(
}); });
``` ```
### delete ## DataAbilityHelper.delete
delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<number>): void delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<number>): void
Deletes one or more data records from the database. This method uses a callback to return the result. Deletes one or more data records from the database. This API uses an asynchronous callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -686,15 +654,13 @@ DAHelper.delete( ...@@ -686,15 +654,13 @@ DAHelper.delete(
}); });
``` ```
### delete ## DataAbilityHelper.delete
delete(uri: string, predicates: dataAbility.DataAbilityPredicates): Promise\<number> delete(uri: string, predicates: dataAbility.DataAbilityPredicates): Promise\<number>
Deletes one or more data records from the database. This method uses a promise to return the result. Deletes one or more data records from the database. This API uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -704,6 +670,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel ...@@ -704,6 +670,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel
| valuesBucket | dataAbility.DataAbilityPredicates | Yes | Filter criteria. You should define the processing logic when this parameter is **null**.| | valuesBucket | dataAbility.DataAbilityPredicates | Yes | Filter criteria. You should define the processing logic when this parameter is **null**.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------- | ------------------------ | | ---------------- | ------------------------ |
| Promise\<number> | Promise used to return the number of deleted data records.| | Promise\<number> | Promise used to return the number of deleted data records.|
...@@ -724,15 +691,13 @@ DAHelper.delete( ...@@ -724,15 +691,13 @@ DAHelper.delete(
}); });
``` ```
### update ## DataAbilityHelper.update
update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<number>): void update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<number>): void
Updates data records in the database. This method uses a callback to return the result. Updates data records in the database. This API uses an asynchronous callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -767,15 +732,13 @@ DAHelper.update( ...@@ -767,15 +732,13 @@ DAHelper.update(
}); });
``` ```
### update ## DataAbilityHelper.update
update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates): Promise\<number> update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates): Promise\<number>
Updates data records in the database. This method uses a promise to return the result. Updates data records in the database. This API uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -786,9 +749,10 @@ SystemCapability.Ability.AbilityRuntime.FAModel ...@@ -786,9 +749,10 @@ SystemCapability.Ability.AbilityRuntime.FAModel
| predicates | dataAbility.DataAbilityPredicates | Yes | Filter criteria. You should define the processing logic when this parameter is **null**.| | predicates | dataAbility.DataAbilityPredicates | Yes | Filter criteria. You should define the processing logic when this parameter is **null**.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------- | -------------------------------------------- | | ---------------- | -------------------------------------------- |
| Promise\<number> | Promise used to return the number of updated data records.| | Promise\<number> | Promise used to return the number of updated data records. |
**Example** **Example**
...@@ -814,15 +778,13 @@ DAHelper.update( ...@@ -814,15 +778,13 @@ DAHelper.update(
}); });
``` ```
### query ## DataAbilityHelper.query
query(uri: string, columns: Array\<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<ResultSet>): void query(uri: string, columns: Array\<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<ResultSet>): void
Queries data in the database. This method uses a callback to return the result. Queries data in the database. This API uses an asynchronous callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -854,15 +816,13 @@ DAHelper.query( ...@@ -854,15 +816,13 @@ DAHelper.query(
### query ## DataAbilityHelper.query
query(uri: string, columns: Array\<string>, predicates: dataAbility.DataAbilityPredicates): Promise\<ResultSet> query(uri: string, columns: Array\<string>, predicates: dataAbility.DataAbilityPredicates): Promise\<ResultSet>
Queries data in the database. This method uses a promise to return the result. Queries data in the database. This API uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -873,6 +833,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel ...@@ -873,6 +833,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel
| predicates | dataAbility.DataAbilityPredicates | Yes | Filter criteria. You should define the processing logic when this parameter is **null**.| | predicates | dataAbility.DataAbilityPredicates | Yes | Filter criteria. You should define the processing logic when this parameter is **null**.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | -------------- | | ------------------- | -------------- |
| Promise\<ResultSet> | Promise used to return the data queried.| | Promise\<ResultSet> | Promise used to return the data queried.|
...@@ -895,3 +856,77 @@ DAHelper.query( ...@@ -895,3 +856,77 @@ DAHelper.query(
console.info("==========================>queryCallback=======================>"); console.info("==========================>queryCallback=======================>");
}); });
``` ```
## DataAbilityHelper.call
call(uri: string, method: string, arg: string, extras: PacMap): Promise<PacMap>
Calls the extended API of the Data ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------- | ---- | ------------------------------------------------ |
| uri | string | Yes | URI of the Data ability. Example: "dataability:///com.example.xxx.xxxx" |
| method | string | Yes | Name of the API to call. |
| arg | string | Yes |Parameter to pass. |
| extras | [PacMap](#pacmap) | Yes | Key-value pair parameter. |
**Return value**
| Type| Description|
|------ | ------- |
|Promise<[PacMap](#pacmap)> | Promise used to return the result.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper("dataability:///com.example.jsapidemo.UserDataAbility");
dataAbilityHelper.call("dataability:///com.example.jsapidemo.UserDataAbility", "method", "arg", {"key1":"value1"}).then((data) => {
console.info('Operation succeeded: ' + data);
}).catch((error) => {
console.error('Operation failed. Cause: ' + error);
});
```
## DataAbilityHelper.call
call(uri: string, method: string, arg: string, extras: PacMap, callback: AsyncCallback<PacMap>): void
Calls the extended API of the Data ability. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------- | ---- | ------------------------------------------------ |
| uri | string | Yes | URI of the Data ability. Example: "dataability:///com.example.xxx.xxxx" |
| method | string | Yes | Name of the API to call. |
| arg | string | Yes |Parameter to pass. |
| extras | [PacMap](#pacmap) | Yes | Key-value pair parameter. |
| callback | AsyncCallback<[PacMap](#pacmap)> | Yes| Callback used to return the result. |
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper("dataability:///com.example.jsapidemo.UserDataAbility");
dataAbilityHelper.call("dataability:///com.example.jsapidemo.UserDataAbility", "method", "arg", {"key1":"value1"}, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + err);
return;
}
console.info('Operation succeeded: ' + data);
});
```
## PacMap
| Name| Type| Mandatory| Description|
| ------ | ------ | ------ | ------ |
| [key: string] | number \| string \| boolean \| Array\<string \| number \| boolean\> \| null | Yes| Data stored in key-value pairs.|
...@@ -10,11 +10,11 @@ Implements event subscription, unsubscription, and triggering. ...@@ -10,11 +10,11 @@ Implements event subscription, unsubscription, and triggering.
## Usage ## Usage
Before using any methods 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
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
onForeground() { onForeground() {
...@@ -24,25 +24,24 @@ export default class MainAbility extends Ability { ...@@ -24,25 +24,24 @@ export default class MainAbility extends Ability {
``` ```
## on ## EventHub.on
on(event: string, callback: Function): void; on(event: string, callback: Function): void;
Subscribes to an event. Subscribes to an event.
**System capability**: **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **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**
``` ```js
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
...@@ -63,25 +62,24 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -63,25 +62,24 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## off ## EventHub.off
off(event: string, callback?: Function): void; off(event: string, callback?: Function): void;
Unsubscribes from an event. If **callback** is specified, this method unsubscribes from the specified callback. If **callback** is not specified, this method unsubscribes from all callbacks in the event. Unsubscribes from an event. If **callback** is specified, this API unsubscribes from the specified callback. If **callback** is not specified, this API unsubscribes from all callbacks in the event.
**System capability**: **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **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**
``` ```js
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
...@@ -102,25 +100,24 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -102,25 +100,24 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## emit ## EventHub.emit
emit(event: string, ...args: Object[]): void; emit(event: string, ...args: Object[]): void;
Triggers an event. Triggers an event.
**System capability**: **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters | Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| event | string | Yes| Event name.| | event | string | Yes| Event name.|
| ...args | Object[] | Yes| Variable parameters, which are passed to the callback when the event is triggered.| | ...args | Object[] | Yes| Variable parameters, which are passed to the callback when the event is triggered.|
- Example **Example**
``` ```js
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
......
# ExtensionContext # ExtensionContext
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> 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 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -11,4 +11,4 @@ Implements the extension context. This module is inherited from **Context**. ...@@ -11,4 +11,4 @@ Implements the extension context. This module is inherited from **Context**.
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core| | currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core |
# FeatureAbility Module (JavaScript) # FeatureAbility Module (JavaScript)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **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.
## Constraints ## Constraints
APIs of the **FeatureAbility** module can be called only by Page abilities. APIs of the **FeatureAbility** module can be called only by Page abilities.
...@@ -16,9 +19,7 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<number>) ...@@ -16,9 +19,7 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<number>)
Starts an ability. This method uses a callback to return the result. Starts an ability. This method uses a callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -57,9 +58,7 @@ startAbility(parameter: StartAbilityParameter): Promise\<number> ...@@ -57,9 +58,7 @@ startAbility(parameter: StartAbilityParameter): Promise\<number>
Starts an ability. This method uses a promise to return the result. Starts an ability. This method uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -91,15 +90,13 @@ featureAbility.startAbility( ...@@ -91,15 +90,13 @@ featureAbility.startAbility(
}); });
``` ```
## featureAbility.acquireDataAbilityHelper ## featureAbility.acquireDataAbilityHelper<sup>7+</sup>
acquireDataAbilityHelper(uri: string): DataAbilityHelper acquireDataAbilityHelper(uri: string): DataAbilityHelper
Obtains a **dataAbilityHelper** object. Obtains a **dataAbilityHelper** object.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -122,15 +119,13 @@ featureAbility.acquireDataAbilityHelper( ...@@ -122,15 +119,13 @@ featureAbility.acquireDataAbilityHelper(
) )
``` ```
## featureAbility.startAbilityForResult ## featureAbility.startAbilityForResult<sup>7+</sup>
startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\<AbilityResult>): void startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\<AbilityResult>): void
Starts an ability. This method uses a callback to return the execution result when the ability is destroyed. Starts an ability. This method uses a callback to return the execution result when the ability is destroyed.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -161,15 +156,13 @@ featureAbility.startAbilityForResult( ...@@ -161,15 +156,13 @@ featureAbility.startAbilityForResult(
) )
``` ```
## featureAbility.startAbilityForResult ## featureAbility.startAbilityForResult<sup>7+</sup>
startAbilityForResult(parameter: StartAbilityParameter): Promise\<AbilityResult> startAbilityForResult(parameter: StartAbilityParameter): Promise\<AbilityResult>
Starts an ability. This method uses a promise to return the execution result when the ability is destroyed. Starts an ability. This method uses a promise to return the execution result when the ability is destroyed.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -178,6 +171,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel ...@@ -178,6 +171,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel
| parameter | [StartAbilityParameter](#startabilityparameter) | Yes | Ability to start.| | parameter | [StartAbilityParameter](#startabilityparameter) | Yes | Ability to start.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------- | -------------- | | ----------------------------------------- | -------------- |
| Promise\<[AbilityResult](#abilityresult)> | Promised returned with the execution result.| | Promise\<[AbilityResult](#abilityresult)> | Promised returned with the execution result.|
...@@ -218,15 +212,13 @@ featureAbility.startAbilityForResult( ...@@ -218,15 +212,13 @@ featureAbility.startAbilityForResult(
}); });
``` ```
## featureAbility.terminateSelfWithResult ## featureAbility.terminateSelfWithResult<sup>7+</sup>
terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\<void>): void terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\<void>): void
Destroys this Page ability, with the result code and data sent to the caller. This method uses a callback to return the result. Destroys this Page ability, with the result code and data sent to the caller. This method uses a callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -268,15 +260,13 @@ featureAbility.terminateSelfWithResult( ...@@ -268,15 +260,13 @@ featureAbility.terminateSelfWithResult(
); );
``` ```
## featureAbility.terminateSelfWithResult ## featureAbility.terminateSelfWithResult<sup>7+</sup>
terminateSelfWithResult(parameter: AbilityResult): Promise\<void> terminateSelfWithResult(parameter: AbilityResult): Promise\<void>
Destroys this Page ability, with the result code and data sent to the caller. This method uses a promise to return the result. Destroys this Page ability, with the result code and data sent to the caller. This method uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -285,6 +275,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel ...@@ -285,6 +275,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel
| parameter | [AbilityResult](#abilityresult) | Yes | Ability to start.| | parameter | [AbilityResult](#abilityresult) | Yes | Ability to start.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ----------------------- | | -------------- | ----------------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result.|
...@@ -326,15 +317,13 @@ featureAbility.terminateSelfWithResult( ...@@ -326,15 +317,13 @@ featureAbility.terminateSelfWithResult(
## featureAbility.hasWindowFocus ## featureAbility.hasWindowFocus<sup>7+<sup>
hasWindowFocus(callback: AsyncCallback\<boolean>): void hasWindowFocus(callback: AsyncCallback\<boolean>): void
Checks whether the main window of this ability has the focus. This method uses a callback to return the result. Checks whether the main window of this ability has the focus. This method uses a callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -351,15 +340,13 @@ featureAbility.hasWindowFocus() ...@@ -351,15 +340,13 @@ featureAbility.hasWindowFocus()
## featureAbility.hasWindowFocus ## featureAbility.hasWindowFocus<sup>7+<sup>
hasWindowFocus(): Promise\<boolean> hasWindowFocus(): Promise\<boolean>
Checks whether the main window of this ability has the focus. This method uses a promise to return the result. Checks whether the main window of this ability has the focus. This method uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Return value** **Return value**
...@@ -384,9 +371,7 @@ getWant(callback: AsyncCallback\<Want>): void ...@@ -384,9 +371,7 @@ getWant(callback: AsyncCallback\<Want>): void
Obtains the **Want** object sent from this ability. This method uses a callback to return the result. Obtains the **Want** object sent from this ability. This method uses a callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -409,11 +394,10 @@ getWant(): Promise\<Want> ...@@ -409,11 +394,10 @@ getWant(): Promise\<Want>
Obtains the **Want** object sent from this ability. This method uses a promise to return the result. Obtains the **Want** object sent from this ability. This method uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------- | ------------------------- | | ----------------------- | ------------------------- |
| Promise\<[Want](#want)> | Promise used to return the result.| | Promise\<[Want](#want)> | Promise used to return the result.|
...@@ -433,11 +417,10 @@ getContext(): Context ...@@ -433,11 +417,10 @@ getContext(): Context
Obtains the application context. Obtains the application context.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | -------------------- | | ------- | -------------------- |
| Context | Application context returned.| | Context | Application context returned.|
...@@ -452,15 +435,13 @@ context.getBundleName() ...@@ -452,15 +435,13 @@ context.getBundleName()
## featureAbility.terminateSelf ## featureAbility.terminateSelf<sup>7+</sup>
terminateSelf(callback: AsyncCallback\<void>): void terminateSelf(callback: AsyncCallback\<void>): void
Destroys this Page ability, with the result code and data sent to the caller. This method uses a callback to return the result. Destroys this Page ability, with the result code and data sent to the caller. This method uses a callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -477,17 +458,16 @@ featureAbility.terminateSelf() ...@@ -477,17 +458,16 @@ featureAbility.terminateSelf()
## featureAbility.terminateSelf ## featureAbility.terminateSelf<sup>7+</sup>
terminateSelf(): Promise\<void> terminateSelf(): Promise\<void>
Destroys this Page ability, with the result code and data sent to the caller. This method uses a promise to return the result. Destroys this Page ability, with the result code and data sent to the caller. This method uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ------------------------- | | -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result.|
...@@ -500,15 +480,13 @@ featureAbility.terminateSelf().then((data) => { console.info("============= ...@@ -500,15 +480,13 @@ featureAbility.terminateSelf().then((data) => { console.info("=============
}); });
``` ```
## featureAbility.connectAbility ## featureAbility.connectAbility<sup>7+</sup>
connectAbility(request: Want, options:ConnectOptions): number connectAbility(request: Want, options:ConnectOptions): number
Connects this ability to a specific Service ability. This method uses a callback to return the result. Connects this ability to a specific Service ability. This method uses a callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -519,21 +497,26 @@ SystemCapability.Ability.AbilityRuntime.FAModel ...@@ -519,21 +497,26 @@ SystemCapability.Ability.AbilityRuntime.FAModel
Want Want
**System capability**: SystemCapability.Ability.AbilityBase
| Name | Readable/Writable | Type | Mandatory| Description | | Name | Readable/Writable | Type | Mandatory| Description |
| ------------ | -------- | -------- | ---- | ---------------------------------- | | ------------ | -------- | -------- | ---- | ---------------------------------- |
| deviceId | Read-only | string | No | Device ID of the Service ability to connect. The default value is the local device ID.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase| | deviceId | Read-only | string | No | Device ID of the Service ability to connect. The default value is the local device ID.|
| bundleName | Read-only | string | Yes | Bundle name of the Service ability to connect.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | bundleName | Read-only | string | Yes | Bundle name of the Service ability to connect. |
| abilityName | Read-only | string | Yes | Class name of the Service ability to connect.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | abilityName | Read-only | string | Yes | Class name of the Service ability to connect. |
ConnectOptions ConnectOptions
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Readable/Writable| Type | Mandatory| Description | | Name | Readable/Writable| Type | Mandatory| Description |
| ------------ | -------- | -------- | ---- | ---------------------------------- | | ------------ | -------- | -------- | ---- | ---------------------------------- |
| onConnect | Read-only | function | Yes | Callback invoked when the connection is successful.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.Core | | onConnect | Read-only | function | Yes | Callback invoked when the connection is successful. |
| onDisconnect | Read-only | function | Yes | Callback invoked when the connection fails.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.Core | | onDisconnect | Read-only | function | Yes | Callback invoked when the connection fails. |
| onFailed | Read-only | function | Yes | Callback invoked when **connectAbility** fails to be called.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.Core| | onFailed | Read-only | function | Yes | Callback invoked when **connectAbility** fails to be called.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | ------------------------ | | ------ | ------------------------ |
| number | Returns the ID of the Service ability connected.| | number | Returns the ID of the Service ability connected.|
...@@ -566,15 +549,13 @@ var connId = featureAbility.connectAbility( ...@@ -566,15 +549,13 @@ var connId = featureAbility.connectAbility(
); );
``` ```
## featureAbility.disconnectAbility ## featureAbility.disconnectAbility<sup>7+</sup>
disconnectAbility(connection: number, callback:AsyncCallback\<void>): void disconnectAbility(connection: number, callback:AsyncCallback\<void>): void
Disconnects this ability from a specific Service ability. This method uses a callback to return the result. Disconnects this ability from a specific Service ability. This method uses a callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -615,15 +596,13 @@ var result = featureAbility.disconnectAbility(connId, ...@@ -615,15 +596,13 @@ var result = featureAbility.disconnectAbility(connId,
); );
``` ```
## featureAbility.disconnectAbility ## featureAbility.disconnectAbility<sup>7+</sup>
disconnectAbility(connection: number): Promise\<void> disconnectAbility(connection: number): Promise\<void>
Disconnects this ability from a specific Service ability. This method uses a promise to return the result. Disconnects this ability from a specific Service ability. This method uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -632,6 +611,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel ...@@ -632,6 +611,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel
| connection | number | Yes | ID of the Service ability to disconnect.| | connection | number | Yes | ID of the Service ability to disconnect.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ----------------------- | | -------------- | ----------------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result.|
...@@ -661,54 +641,176 @@ var connId = featureAbility.connectAbility( ...@@ -661,54 +641,176 @@ var connId = featureAbility.connectAbility(
onFailed: onFailedCallback, onFailed: onFailedCallback,
}, },
); );
var result = await featureAbility.disconnectAbility(connId);
featureAbility.disconnectAbility(connId).then((error,data)=>{
console.log('featureAbilityTest result errCode : ' + error.code + " data: " + data);
});
``` ```
## featureAbility.getWindow<sup>7+</sup>
getWindow(callback: AsyncCallback\<window.Window>): void
Obtains the window corresponding to this ability. This method uses a callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback\<window.Window> | Yes | Callback used to return the window.|
**Example**
```javascript
GetWindow(){
featureAbility.getWindow()
}
```
## featureAbility.getWindow<sup>7+</sup>
getWindow(): Promise\<window.Window>;
Obtains the window corresponding to this ability. This method uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Return value**
| Type | Description |
| ----------------- | ---------------------------------------------------------- |
| Promise\<window.Window> | Promise used to return the window.|
**Example**
```javascript
GetWindowPromise(){
featureAbility.getWindow().then((data) => {
console.info("=============getWindowPromise========== " + JSON.stringify(data));
});
}
```
## AbilityWindowConfiguration
The value is obtained through the **featureAbility.AbilityWindowConfiguration** API.
**Example**
```
featureAbility.AbilityWindowConfiguration.WINDOW_MODE_UNDEFINED
```
| Name | Name| Description |
| --------------------------- | ---- | ---------- |
| WINDOW_MODE_UNDEFINED<sup>7+</sup> | 0 | The Page ability is in an undefined window display mode.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel |
| WINDOW_MODE_FULLSCREEN<sup>7+</sup> | 1 | The Page ability is in full screen mode.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel |
| WINDOW_MODE_SPLIT_PRIMARY<sup>7+</sup> | 100 | The Page ability is displayed in the primary window when it is in split-screen mode.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
| WINDOW_MODE_SPLIT_SECONDARY<sup>7+</sup> | 101 | The Page ability is displayed in the secondary window when it is in split-screen mode.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
| WINDOW_MODE_FLOATING<sup>7+</sup> | 102 | The Page ability is displayed in floating window mode.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel |
## AbilityStartSetting
The **AbilityStartSetting** attribute is an object defined as [key: string]: any. The key is a type of **AbilityStartSetting**, and the value is a type of **AbilityWindowConfiguration**.
The value is obtained through the **featureAbility.AbilityStartSetting** API.
**Example**
```
featureAbility.AbilityStartSetting.BOUNDS_KEY
```
| Name | Name | Description |
| --------------- | --------------- | -------------------------- |
| BOUNDS_KEY<sup>7+</sup> | "abilityBounds" | Ability window size.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel |
| WINDOW_MODE_KEY<sup>7+</sup> | "windowMode" | Ability window display mode.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel |
| DISPLAY_ID_KEY<sup>7+</sup> | "displayId" | Display device ID.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
## ErrorCode
Enumerates error codes.
| Variable | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| NO_ERROR<sup>7+</sup> | 0 | No error occurs.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
| INVALID_PARAMETER<sup>7+</sup> | -1 | Invalid parameter.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
| ABILITY_NOT_FOUND<sup>7+</sup> | -2 | The ability is not found.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
| PERMISSION_DENY<sup>7+</sup> | -3 | The request is denied.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
## DataAbilityOperationType
Enumerates operation types of the Data ability.
| Variable | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| TYPE_INSERT<sup>7+</sup> | 1 | Insert operation.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
| TYPE_UPDATE<sup>7+</sup> | 2 | Update operation.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
| TYPE_DELETE<sup>7+</sup> | 3 | Deletion operation.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
| TYPE_ASSERT<sup>7+</sup> | 4 | Assert operation.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
## AbilityResult ## AbilityResult
**System capability**: SystemCapability.Ability.AbilityBase
| Name | Readable/Writable| Type | Mandatory| Description | | Name | Readable/Writable| Type | Mandatory| Description |
| ---------- | -------- | --------------------- | ---- | ------------------------------------------------------------ | | ---------- | -------- | --------------------- | ---- | ------------------------------------------------------------ |
| resultCode | Read-only | number | Yes | Result code returned after the ability is destroyed. The feature for defining error-specific result codes is coming soon.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase| | resultCode<sup>7+</sup> | Read-only | number | Yes | Result code returned after the ability is destroyed. The feature for defining error-specific result codes is coming soon.|
| want | Read-only | [Want](#want) | No | Data returned after the ability is destroyed. You can define the data to be returned. This parameter can be **null**.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | want<sup>7+</sup> | Read-only | [Want](#want) | No | Data returned after the ability is destroyed. You can define the data to be returned. This parameter can be **null**. |
## StartAbilityParameter ## StartAbilityParameter
**System capability**: SystemCapability.AbilityRuntime.FAModel
| Name | Readable/Writable| Type | Mandatory| Description | | Name | Readable/Writable| Type | Mandatory| Description |
| ------------------- | -------- | -------------------- | ---- | ------------------------------------------------------------ | | ------------------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
| want | Read-only | [Want](#want) | Yes | Information about the ability to start.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.FAModel | | want | Read-only | [Want](#want) | Yes | Information about the ability to start. |
| 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| | abilityStartSetting | Read-only | {[key: string]: any} | No | Special attribute of the ability to start. This attribute can be passed in the method call.|
## Want ## Want
**System capability**: SystemCapability.Ability.AbilityBase
| Name | Readable/Writable| Type | Mandatory| Description | | Name | Readable/Writable| Type | Mandatory| Description |
| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ | | ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
| deviceId | Read-only | string | No | ID of the device that runs the ability.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | deviceId<sup>8+</sup> | Read-only | string | No | ID of the device that runs the 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| | bundleName<sup>8+</sup> | 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.|
| 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| | abilityName<sup>8+</sup> | 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.|
| 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| | uri<sup>8+</sup> | 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**.|
| type | Read-only | string | No | MIME type, for example, text/plain or image/*.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | type<sup>8+</sup> | Read-only | string | No | MIME type, for example, text/plain or image/*. |
| flags | Read-only | number | No | How the **Want** object will be handled. By default, a number is passed. For details, see [flags](#flags).<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase| | flags<sup>8+</sup> | Read-only | number | No | How the **Want** object will be handled. By default, a number is passed. For details, see [flags](#flags).|
| action | Read-only | string | No | Action option.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | action<sup>8+</sup> | Read-only | string | No | Action option. |
| parameters | Read-only | {[key: string]: any} | No | List of parameters in a **Want** object.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | parameters<sup>8+</sup> | Read-only | {[key: string]: any} | No | List of parameters in a **Want** object. |
| entities | Read-only | Array\<string> | No | List of entities.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | entities<sup>8+</sup> | Read-only | Array\<string> | No | List of entities. |
## flags ## flags
**System capability**: SystemCapability.Ability.AbilityBase
| Name | Name | Description | | Name | Name | Description |
| ------------------------------------ | ---------- | ------------------------------------------------------------ | | ------------------------------------ | ---------- | ------------------------------------------------------------ |
| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Indicates the permission to read the URI.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | 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.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Indicates the permission to write the URI. |
| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | Returns the result to the ability.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | 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 migrated to a remote device.<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_NOT_OHOS_COMPONENT | 0x00000010 | Indicates that a component does not belong to OHOS.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | FLAG_NOT_OHOS_COMPONENT | 0x00000010 | Indicates that a component does not belong to OHOS. |
| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | Indicates whether to enable an ability.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | FLAG_ABILITY_FORM_ENABLED | 0x00000020 | Indicates whether to enable an ability. |
| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Indicates the permission to make the URI persistent.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | 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.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | Indicates the permission to verify URIs by prefix matching. |
| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | Supports cross-device startup in a distributed scheduler.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | 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.<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_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that the migration is reversible.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that the migration is reversible. |
| 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_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.<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_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_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_NEW_MISSION | 0x10000000 | Creates a mission on the historical mission stack.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase | | FLAG_ABILITY_NEW_MISSION | 0x10000000 | Creates a mission on the historical mission stack. |
| 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| | FLAG_ABILITY_MISSION_TOP | 0x20000000 | Starts the mission on the top of the existing mission stack; creates an ability instance if no mission exists.|
# FormBindingData # FormBindingData
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -19,33 +19,39 @@ createFormBindingData(obj?: Object | string): FormBindingData ...@@ -19,33 +19,39 @@ createFormBindingData(obj?: Object | string): FormBindingData
Creates a **FormBindingData** object. Creates a **FormBindingData** object.
- Parameters **System capability**: SystemCapability.Ability.Form
| Name| Type| Mandatory| Description| **Parameters**
| ------ | -------------- | ---- | ------------------------------------------------------------ |
| obj | Object or string| No| Data to be displayed on the JS service widget. The value can be an object containing multiple key-value pairs or a string in JSON format.|
| Name| Type | Mandatory| Description |
| ------ | -------------- | ---- | ------------------------------------------------------------ |
| obj | Object or string| No | Data to be displayed on the JS service widget. The value can be an object containing multiple key-value pairs or a string in JSON format.|
- Return value **Return value**
| Type| Description| | Type | Description |
| ----------------------------------- | --------------------------------------- | | ----------------------------------- | --------------------------------------- |
| [FormBindingData](#formbindingdata) | **FormBindingData** object created based on the passed data.| | [FormBindingData](#formbindingdata) | **FormBindingData** object created based on the passed data.|
**Example**
- Example ```js
```
let obj = {"temperature": "21°"}; let obj = {"temperature": "21°"};
let formBindingDataObj = formBindingData.createFormBindingData(obj); let formBindingDataObj = formBindingData.createFormBindingData(obj);
``` ```
## FormBindingData ## formBindingData.FormBindingData
data: Object
Describes a **FormBindingData** object. Describes a **FormBindingData** object.
| Name| Type| Description| **System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type | Description |
| ---- | -------------- | ------------------------------------------------------------ | | ---- | -------------- | ------------------------------------------------------------ |
| obj | Object or string| Data to be displayed on the JS service widget. The value can be an object containing multiple key-value pairs or a string in JSON format.| | data | Object or string| Data to be displayed on the JS service widget. The value can be an object containing multiple key-value pairs or a string in JSON format.|
# FormExtension # FormExtension
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Provides **FormExtension** APIs. Provides **FormExtension** APIs.
...@@ -17,9 +17,9 @@ None ...@@ -17,9 +17,9 @@ None
## Attributes ## Attributes
| Name| Type| Readable| Writable| Description| | Name | Type | Readable| Writable| Description |
| ------- | ------------------------------------------------------- | ---- | ---- | --------------------------------------------------- | | ------- | ------------------------------------------------------- | ---- | ---- | --------------------------------------------------- |
| context | [FormExtensionContext](js-apis-formextensioncontext.md) | Yes| No| Context of the **FormExtension**. This class is inherited from **ExtensionContext**.| | context | [FormExtensionContext](js-apis-formextensioncontext.md) | Yes | No | Context of the **FormExtension**. This class is inherited from **ExtensionContext**.<br>**System capability**: SystemCapability.Ability.Form|
## onCreate ## onCreate
...@@ -27,21 +27,23 @@ onCreate(want: Want): formBindingData.FormBindingData ...@@ -27,21 +27,23 @@ onCreate(want: Want): formBindingData.FormBindingData
Called to notify the widget provider that a **Form** instance (widget) has been created. Called to notify the widget provider that a **Form** instance (widget) has been created.
- Parameters **System capability**: SystemCapability.Ability.Form
| Name| Type| Mandatory| Description| **Parameters**
| Name| Type | Mandatory| Description |
| ------ | -------------------------------------- | ---- | ------------------------------------------------------------ | | ------ | -------------------------------------- | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-featureAbility.md#want) | Yes| Information related to the extension, including the widget ID, name, and style. The information must be managed as persistent data to facilitate subsequent widget update and deletion.| | want | [Want](js-apis-featureAbility.md#want) | Yes | Information related to the extension, including the widget ID, name, and style. The information must be managed as persistent data to facilitate subsequent widget update and deletion.|
- Return value **Return value**
| Type| Description| | Type | Description |
| ------------------------------------------------------------ | ----------------------------------------------------------- | | ------------------------------------------------------------ | ----------------------------------------------------------- |
| [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | A **formBindingData.FormBindingData** object containing the data to be displayed on the widget.| | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | A **formBindingData.FormBindingData** object containing the data to be displayed on the widget.|
- Example **Example**
``` ```js
export default class MyFormExtension extends FormExtension { export default class MyFormExtension extends FormExtension {
onCreate(want) { onCreate(want) {
console.log('FormExtension onCreate, want:' + want.abilityName); console.log('FormExtension onCreate, want:' + want.abilityName);
...@@ -55,19 +57,21 @@ Called to notify the widget provider that a **Form** instance (widget) has been ...@@ -55,19 +57,21 @@ Called to notify the widget provider that a **Form** instance (widget) has been
} }
``` ```
## onCastToNormal ## FormExtension.onCastToNormal
onCastToNormal(formId: string): void onCastToNormal(formId: string): void
Called to notify the widget provider that a temporary widget has been converted to a normal one. Called to notify the widget provider that a temporary widget has been converted to a normal one.
- Parameters **System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type| Mandatory| Description| | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------ | | ------ | ------ | ---- | ------------------------ |
| formId | string | Yes| ID of the widget that requests to be converted to a normal one.| | formId | string | Yes | ID of the widget that requests to be converted to a normal one.|
- Example **Example**
``` ```
export default class MyFormExtension extends FormExtension { export default class MyFormExtension extends FormExtension {
...@@ -77,21 +81,23 @@ Called to notify the widget provider that a temporary widget has been converted ...@@ -77,21 +81,23 @@ Called to notify the widget provider that a temporary widget has been converted
} }
``` ```
## onUpdate ## FormExtension.onUpdate
onUpdate(formId: string): void onUpdate(formId: string): void
Called to notify the widget provider that a widget has been updated. After obtaining the latest data, the caller invokes **updateForm** of the [FormExtensionContext](js-apis-formextensioncontext.md) class to update the widget data. Called to notify the widget provider that a widget has been updated. After obtaining the latest data, the caller invokes **updateForm** of the [FormExtensionContext](js-apis-formextensioncontext.md) class to update the widget data.
- Parameters **System capability**: SystemCapability.Ability.Form
| Name| Type| Mandatory| Description| **Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ | | ------ | ------ | ---- | ------------------ |
| formId | string | Yes| ID of the widget that requests to be updated.| | formId | string | Yes | ID of the widget that requests to be updated.|
- Example **Example**
``` ```js
export default class MyFormExtension extends FormExtension { export default class MyFormExtension extends FormExtension {
onUpdate(formId) { onUpdate(formId) {
console.log('FormExtension onUpdate, formId:' + formId); console.log('FormExtension onUpdate, formId:' + formId);
...@@ -105,21 +111,23 @@ Called to notify the widget provider that a widget has been updated. After obtai ...@@ -105,21 +111,23 @@ Called to notify the widget provider that a widget has been updated. After obtai
} }
``` ```
## onVisibilityChange ## FormExtension.onVisibilityChange
onVisibilityChange(newStatus: { [key: string]: number }): void onVisibilityChange(newStatus: { [key: string]: number }): void
Called to notify the widget provider of the change of visibility. Called to notify the widget provider of the change of visibility.
- Parameters **System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ---------------------------- | | --------- | ------------------------- | ---- | ---------------------------- |
| newStatus | { [key: string]: number } | Yes| ID and visibility status of the widget to be changed.| | newStatus | { [key: string]: number } | Yes | ID and visibility status of the widget to be changed.|
- Example **Example**
``` ```js
export default class MyFormExtension extends FormExtension { export default class MyFormExtension extends FormExtension {
onVisibilityChange(newStatus) { onVisibilityChange(newStatus) {
console.log('FormExtension onVisibilityChange, newStatus:' + newStatus); console.log('FormExtension onVisibilityChange, newStatus:' + newStatus);
...@@ -137,22 +145,24 @@ Called to notify the widget provider of the change of visibility. ...@@ -137,22 +145,24 @@ Called to notify the widget provider of the change of visibility.
} }
``` ```
## onEvent ## FormExtension.onEvent
onEvent(formId: string, message: string): void onEvent(formId: string, message: string): void
Called to instruct the widget provider to receive and process the widget event. Called to instruct the widget provider to receive and process the widget event.
- Parameters **System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------- | | ------- | ------ | ---- | ---------------------- |
| formId | string | Yes| ID of the widget that requests the event.| | formId | string | Yes | ID of the widget that requests the event.|
| message | string | Yes| Event message.| | message | string | Yes | Event message. |
- Example **Example**
``` ```js
export default class MyFormExtension extends FormExtension { export default class MyFormExtension extends FormExtension {
onEvent(formId, message) { onEvent(formId, message) {
console.log('FormExtension onEvent, formId:' + formId + ", message:" + message); console.log('FormExtension onEvent, formId:' + formId + ", message:" + message);
...@@ -160,24 +170,50 @@ Called to instruct the widget provider to receive and process the widget event. ...@@ -160,24 +170,50 @@ Called to instruct the widget provider to receive and process the widget event.
} }
``` ```
## onDestroy ## FormExtension.onDestroy
onDestroy(formId: string): void onDestroy(formId: string): void
Called to notify the widget provider that a **Form** instance (widget) has been destroyed. Called to notify the widget provider that a **Form** instance (widget) has been destroyed.
- Parameters **System capability**: SystemCapability.Ability.Form
| Name| Type| Mandatory| Description| **Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ | | ------ | ------ | ---- | ------------------ |
| formId | string | Yes| ID of the widget to be destroyed.| | formId | string | Yes | ID of the widget to be destroyed.|
- Example **Example**
``` ```js
export default class MyFormExtension extends FormExtension { export default class MyFormExtension extends FormExtension {
onDestroy(formId) { onDestroy(formId) {
console.log('FormExtension onDestroy, formId:' + formId); console.log('FormExtension onDestroy, formId:' + formId);
} }
} }
``` ```
## FormExtension.onConfigurationUpdated
onConfigurationUpdated(config: Configuration): void;
Called when the configuration of the environment where the ability is running is updated.
**System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | [Configuration](#section188911144124715) | Yes| New configuration.|
**Example**
```js
class MyFormExtension extends MyFormExtension {
onConfigurationUpdated(config) {
console.log('onConfigurationUpdated, config:' + JSON.stringify(config));
}
}
```
# FormExtensionContext # FormExtensionContext
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
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**.
## updateForm ## FormExtensionContext.updateForm
updateForm(formId: string, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback\<void>): void updateForm(formId: string, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback\<void>): void
Updates a widget. This method uses a callback to return the result. Updates a widget. This method uses a callback to return the result.
- Parameters **System capability**: SystemCapability.Ability.Form
| Name| Type| Mandatory| Description| **Parameters**
| Name | Type | Mandatory| Description |
| --------------- | ------------------------------------------------------------ | ---- | -------------------------------------- | | --------------- | ------------------------------------------------------------ | ---- | -------------------------------------- |
| formId | string | Yes| ID of the widget that requests to be updated.| | formId | string | Yes | ID of the widget that requests to be updated. |
| formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes| New data of the widget.| | formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes | New data of the widget. |
| callback | AsyncCallback\<void> | Yes| Callback used to return the result indicating whether the method is successfully called.| | callback | AsyncCallback\<void> | Yes | Callback used to return the result indicating whether the method is successfully called.|
- Example **Example**
``` ```js
let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"}); let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
this.context.updateForm(formId, obj2, (data)=>{ this.context.updateForm(formId, obj2, (data)=>{
console.log('FormExtension context updateForm, data:' + data); console.log('FormExtension context updateForm, data:' + data);
}); });
``` ```
## updateForm ## FormExtensionContext.updateForm
updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Promise\<void> updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Promise\<void>
Updates a widget. This method uses a promise to return the result. Updates a widget. This method uses a promise to return the result.
- Parameters **System capability**: SystemCapability.Ability.Form
**Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| --------------- | ------------------------------------------------------------ | ---- | ------------------ | | --------------- | ------------------------------------------------------------ | ---- | ------------------ |
| formId | string | Yes| ID of the widget that requests to be updated.| | formId | string | Yes | ID of the widget that requests to be updated.|
| formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes| New data of the widget.| | formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes | New data of the widget. |
- Return value **Return value**
| Type| Description| | Type | Description |
| -------------- | --------------------------------- | | -------------- | --------------------------------- |
| Promise\<void> | Promise returned with the result indicating whether the method is successfully called.| | Promise\<void> | Promise returned with the result indicating whether the method is successfully called.|
- Example **Example**
``` ```
let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"}); let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
......
# ParticleAbility Module # ParticleAbility Module
> ![icon-note.gif](public_sys-resources/icon-note.gif) **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.
## Constraints ## Constraints
The ParticleAbility module is used to perform operations on abilities of the Data and Service types. The ParticleAbility module is used to perform operations on abilities of the Data and Service types.
...@@ -12,13 +15,11 @@ import particleAbility from '@ohos.ability.particleAbility' ...@@ -12,13 +15,11 @@ import particleAbility from '@ohos.ability.particleAbility'
## particleAbility.startAbility ## particleAbility.startAbility
startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<void>: void startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<void>): void
Starts a particle ability. This method uses a callback to return the result.
**System capabilities** Starts a particle ability. This API uses an asynchronous callback to return the result.
SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -57,16 +58,11 @@ particleAbility.startAbility( ...@@ -57,16 +58,11 @@ particleAbility.startAbility(
## particleAbility.startAbility ## particleAbility.startAbility
**System capabilities** startAbility(parameter: StartAbilityParameter): Promise<void>;
SystemCapability.Ability.AbilityRuntime.FAModel
startAbility(parameter: StartAbilityParameter): Promise\<number> Starts a particle ability. This API uses a promise to return the result.
Starts a particle ability. This method uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -74,7 +70,9 @@ SystemCapability.Ability.AbilityRuntime.FAModel ...@@ -74,7 +70,9 @@ SystemCapability.Ability.AbilityRuntime.FAModel
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ----------------------------------------------- | ---- | ----------------- | | --------- | ----------------------------------------------- | ---- | ----------------- |
| parameter | [StartAbilityParameter](#startabilityparameter) | Yes | Ability to start.| | parameter | [StartAbilityParameter](#startabilityparameter) | Yes | Ability to start.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ------------------------- | | -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result.|
...@@ -109,11 +107,9 @@ particleAbility.startAbility( ...@@ -109,11 +107,9 @@ particleAbility.startAbility(
terminateSelf(callback: AsyncCallback\<void>): void terminateSelf(callback: AsyncCallback\<void>): void
Terminates this particle ability. This method uses a callback to return the result. Terminates this particle ability. This API uses an asynchronous callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -138,13 +134,12 @@ particleAbility.terminateSelf( ...@@ -138,13 +134,12 @@ particleAbility.terminateSelf(
terminateSelf(): Promise\<void> terminateSelf(): Promise\<void>
Terminates this particle ability. This method uses a promise to return the result. Terminates this particle ability. This API uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.FAModel **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ------------------------- | | -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result.|
...@@ -166,9 +161,7 @@ acquireDataAbilityHelper(uri: string): DataAbilityHelper ...@@ -166,9 +161,7 @@ acquireDataAbilityHelper(uri: string): DataAbilityHelper
Obtains a **dataAbilityHelper** object. Obtains a **dataAbilityHelper** object.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters** **Parameters**
...@@ -190,91 +183,25 @@ var uri = ""; ...@@ -190,91 +183,25 @@ var uri = "";
particleAbility.acquireDataAbilityHelper(uri) particleAbility.acquireDataAbilityHelper(uri)
``` ```
## StartAbilityParameter
| Name | Readable/Writable| Type | Mandatory| Description |
| ------------------- | -------- | --------------------- | ---- | ------------------------------------------------------------ |
| 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.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.FAModel|
## Want
| Name | Readable/Writable| Type | Mandatory| Description |
| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
| 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.<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.<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**.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase|
| 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).<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase|
| action | Read-only | string | No | Action option.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| 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.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
## flags
| Name | Value | Description |
| ------------------------------------ | ---------- | ------------------------------------------------------------ |
| 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.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| 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.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| 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.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| 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.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| 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.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase |
| 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.<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.<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**.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase|
| 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.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityBase|
## AbilityStartSetting
The **AbilityStartSetting** attribute is an object defined as [key: string]: any. The key is a type of **AbilityStartSetting**, and the value is a type of **AbilityWindowConfiguration**.
Defines special attributes of an ability, for example, **featureAbility.AbilityStartSetting.BOUNDS_KEY**.
| Name | Value | Description |
| --------------- | --------------- | -------------------------- |
| BOUNDS_KEY | "abilityBounds" | Ability window size.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.FAModel |
| WINDOW_MODE_KEY | "windowMode" | Ability window display mode.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.FAModel |
| DISPLAY_ID_KEY | "displayId" | Display device ID.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.FAModel|
## AbilityWindowConfiguration
Defines the window display modes of a Page ability, for example, **featureAbility.AbilityWindowConfiguration.WINDOW_MODE_UNDEFINED**.
| Name | Value| Description |
| --------------------------- | ---- | ---------- |
| 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.<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.<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.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.FAModel|
| WINDOW_MODE_FLOATING | 102 | The Page ability is displayed in floating window mode.<br><b>System capabilities:</b> SystemCapability.Ability.AbilityRuntime.FAModel |
## particleAbility.startBackgroundRunning ## particleAbility.startBackgroundRunning
startBackgroundRunning(id: number, request: NotificationRequest, callback: AsyncCallback&lt;void&gt;): void; startBackgroundRunning(id: number, request: NotificationRequest, callback: AsyncCallback&lt;void&gt;): void;
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 API uses an asynchronous callback to return the result. (This method is of API 7 and will be deprecated. Use the counterpart in API 8.)
**System capabilities** **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask **Parameters**
- **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| id | number | Yes| Notification ID of a continuous task.| | id | number | Yes| Notification ID of a continuous task.|
| request | NotificationRequest | Yes| Notification parameter, which is used to display information in the notification bar.| | request | NotificationRequest | Yes| Notification parameter, which is used to display information in the notification bar.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the execution result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example**
- **Example**
```js ```js
import notification from '@ohos.notification'; import notification from '@ohos.notification';
import particleAbility from '@ohos.ability.particleAbility'; import particleAbility from '@ohos.ability.particleAbility';
...@@ -323,24 +250,25 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { ...@@ -323,24 +250,25 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
startBackgroundRunning(id: number, request: NotificationRequest): Promise&lt;void&gt; startBackgroundRunning(id: number, request: NotificationRequest): Promise&lt;void&gt;
**System capabilities** **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
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 API 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**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| id | number | Yes| Notification ID of a continuous task.| | id | number | Yes| Notification ID of a continuous task.|
| request | NotificationRequest | Yes| Notification parameter, which is used to display information in the notification bar.| | request | NotificationRequest | Yes| Notification parameter, which is used to display information in the notification bar.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ------------------------- | | -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result.|
- **Example** **Example**
```js ```js
import notification from '@ohos.notification'; import notification from '@ohos.notification';
import particleAbility from '@ohos.ability.particleAbility'; import particleAbility from '@ohos.ability.particleAbility';
...@@ -385,18 +313,18 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { ...@@ -385,18 +313,18 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
cancelBackgroundRunning(callback: AsyncCallback&lt;void&gt;): void; cancelBackgroundRunning(callback: AsyncCallback&lt;void&gt;): void;
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 API uses an asynchronous callback to return the result. (This method is of API 7 and will be deprecated. Use the counterpart in API 8.)
**System capabilities** **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask **Parameters**
- **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the execution result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example**
- **Example**
```js ```js
import particleAbility from '@ohos.ability.particleAbility'; import particleAbility from '@ohos.ability.particleAbility';
...@@ -416,18 +344,18 @@ particleAbility.cancelBackgroundRunning(callback); ...@@ -416,18 +344,18 @@ particleAbility.cancelBackgroundRunning(callback);
cancelBackgroundRunning(): Promise&lt;void&gt;; cancelBackgroundRunning(): Promise&lt;void&gt;;
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 API uses a promise to return the result. (This method is of API 7 and will be deprecated. Use the counterpart in API 8.)
**System capabilities**
SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ------------------------- | | -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result.|
- **Example** **Example**
```js ```js
import particleAbility from '@ohos.ability.particleAbility'; import particleAbility from '@ohos.ability.particleAbility';
...@@ -438,3 +366,154 @@ particleAbility.cancelBackgroundRunning().then(() => { ...@@ -438,3 +366,154 @@ particleAbility.cancelBackgroundRunning().then(() => {
}); });
``` ```
## particleAbility.connectAbility
connectAbility(request: Want, options:ConnectOptions): number
Connects this ability to a specific Service ability. This API uses a callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | -------------- | ---- | ---------------------------- |
| request | [Want](#want) | Yes | Service ability to connect.|
| options | ConnectOptions | Yes | Callback used to return the result. |
**Example**
```js
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
function onDisconnectCallback(element){
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
}
function onFailedCallback(code){
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
);
particleAbility.disconnectAbility(connId).then((error,data)=>{
console.log('particleAbilityTest result errCode : ' + error.code + " data: " + data);
});
```
## particleAbility.disconnectAbility
disconnectAbility(connection: number, callback:AsyncCallback<void>): void;
Disconnects this ability from the Service ability. This API uses a callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example**
```js
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
function onDisconnectCallback(element){
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
}
function onFailedCallback(code){
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
);
var result = particleAbility.disconnectAbility(connId,
(error,data) => {
console.log('particleAbilityTest DisConnectJsSameBundleName result errCode : ' + error.code + " data: " + data)
},
);
```
## particleAbility.disconnectAbility
disconnectAbility(connection: number): Promise<void>;
Disconnects this ability from the Service ability. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
**Return value**
| Type | Description |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
function onDisconnectCallback(element){
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
}
function onFailedCallback(code){
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
);
particleAbility.disconnectAbility(connId).then((error,data)=>{
console.log('particleAbilityTest result errCode : ' + error.code + " data: " + data);
});
```
## ErrorCode
Enumerates error codes.
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| INVALID_PARAMETER | -1 | Invalid parameter.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel|
...@@ -9,7 +9,9 @@ Provides the permission request result. ...@@ -9,7 +9,9 @@ Provides the permission request result.
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| No| Permissions requested. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core| | permissions | Array&lt;string&gt; | Yes| No| Permissions requested.|
| authResults | Array&lt;number&gt; | Yes| No| Whether the requested permissions are granted or denied. The value **0** means that the requests permissions are granted, and **-1** means the opposite. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core| | authResults | Array&lt;number&gt; | Yes| No| Whether the requested permissions are granted or denied. The value **0** means that the requests permissions are granted, and **-1** means the opposite. |
...@@ -14,7 +14,7 @@ The process running information is obtained through an **appManager** instance. ...@@ -14,7 +14,7 @@ The process running information is obtained through an **appManager** instance.
``` ```js
import appManager from '@ohos.application.appManager'; import appManager from '@ohos.application.appManager';
appManager.getProcessRunningInfos((error,data) => { appManager.getProcessRunningInfos((error,data) => {
console.log("getProcessRunningInfos error: " + error.code + " data: " + JSON.stringify(data)); console.log("getProcessRunningInfos error: " + error.code + " data: " + JSON.stringify(data));
...@@ -24,9 +24,11 @@ appManager.getProcessRunningInfos((error,data) => { ...@@ -24,9 +24,11 @@ appManager.getProcessRunningInfos((error,data) => {
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| pid | number | Yes| No| Process ID. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core| | pid | number | Yes| No| Process ID.|
| uid | number | Yes| No| User ID. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core| | uid | number | Yes| No| User ID.|
| processName | string | Yes| No| Process name. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core| | processName | string | Yes| No| Process name.|
| bundleNames | Array&lt;string&gt; | Yes| No| Names of all bundles running in the process. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core| | bundleNames | Array&lt;string&gt; | Yes| No| Names of all bundles running in the process.|
...@@ -9,25 +9,22 @@ Implements the context that provides the capabilities and APIs of **ServiceExten ...@@ -9,25 +9,22 @@ Implements the context that provides the capabilities and APIs of **ServiceExten
## startAbility ## startAbility
startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void; 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 method uses a callback to return the result. **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the ability to start, such as the ability name and bundle name.| | want | [Want](js-apis-featureAbility.md#Want) | 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 method is successfully called.| | callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the API is successfully called.|
- Example **Example**
```
```js
let want = { let want = {
"bundleName": "com.example.myapp", "bundleName": "com.example.myapp",
"abilityName": "com.example.myapp.MyAbility" "abilityName": "com.example.myapp.MyAbility"
...@@ -38,28 +35,29 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -38,28 +35,29 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## startAbility ## ServiceExtensionContext.startAbility
startAbility(want: Want): Promise&lt;void&gt;; startAbility(want: Want): Promise&lt;void&gt;;
Starts an ability. This method uses a promise to return the result. Starts an ability. This API uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the ability to start, such as the ability name and bundle name.| | want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the ability to start, such as the ability name and bundle name.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the method is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
- Example **Example**
```
```js
let want = { let want = {
"bundleName": "com.example.myapp", "bundleName": "com.example.myapp",
"abilityName": "com.example.myapp.MyAbility" "abilityName": "com.example.myapp.MyAbility"
...@@ -72,46 +70,46 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -72,46 +70,46 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## terminateSelf ## ServiceExtensionContext.terminateSelf
terminateSelf(callback: AsyncCallback&lt;void&gt;): void; terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
Terminates this ability. This method uses a callback to return the result. Terminates this ability. This API uses a callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the method is successfully called.| | callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the API is successfully called.|
- Example **Example**
```
```js
this.context.terminateSelf((err) => { this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringfy(err)); console.log('terminateSelf result:' + JSON.stringfy(err));
}); });
``` ```
## terminateSelf ## ServiceExtensionContext.terminateSelf
terminateSelf(): Promise&lt;void&gt;; terminateSelf(): Promise&lt;void&gt;;
Terminates this ability. This method uses a promise to return the result. Terminates this ability. This API uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Return value**
- Return value
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the method is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
- Example **Example**
```
```js
this.context.terminateSelf(want).then((data) => { this.context.terminateSelf(want).then((data) => {
console.log('success:' + JSON.stringfy(data)); console.log('success:' + JSON.stringfy(data));
}).catch((error) => { }).catch((error) => {
...@@ -120,29 +118,30 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -120,29 +118,30 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## connectAbility ## ServiceExtensionContext.connectAbility
connectAbility(want: Want, options: ConnectOptions): number; connectAbility(want: Want, options: ConnectOptions): number;
Connects this ability to a Service ability. Connects this ability to a Service ability.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| 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.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | A number, based on which the connection will be interrupted.| | number | A number, based on which the connection will be interrupted.|
- Example **Example**
```
```js
let want = { let want = {
"bundleName": "com.example.myapp", "bundleName": "com.example.myapp",
"abilityName": "com.example.myapp.MyAbility" "abilityName": "com.example.myapp.MyAbility"
...@@ -156,52 +155,53 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -156,52 +155,53 @@ SystemCapability.Ability.AbilityRuntime.Core
``` ```
## disconnectAbility ## ServiceExtensionContext.disconnectAbility
disconnectAbility(connection: number, callback:AsyncCallback&lt;void&gt;): void; disconnectAbility(connection: number, callback:AsyncCallback&lt;void&gt;): void;
Disconnects this ability from the Service ability. This method uses a callback to return the result. Disconnects this ability from the Service ability. This API uses a callback to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| connection | number | Yes| Number returned after **connectAbility** is called.| | connection | number | Yes| Number returned after **connectAbility** is called.|
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the method is successfully called.| | callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the API is successfully called.|
- Example **Example**
```
```js
this.context.disconnectAbility(connection, (err) => { // connection is the return value of connectAbility. this.context.disconnectAbility(connection, (err) => { // connection is the return value of connectAbility.
console.log('terminateSelf result:' + JSON.stringfy(err)); console.log('terminateSelf result:' + JSON.stringfy(err));
}); });
``` ```
## disconnectAbility ## ServiceExtensionContext.disconnectAbility
disconnectAbility(connection: number): Promise&lt;void&gt;; disconnectAbility(connection: number): Promise&lt;void&gt;;
Disconnects this ability from the Service ability. This method uses a promise to return the result. Disconnects this ability from the Service ability. This API uses a promise to return the result.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| connection | number | Yes| Number returned after **connectAbility** is called.| | connection | number | Yes| Number returned after **connectAbility** is called.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the method is successfully called.| | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
- Example **Example**
```
```js
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.
console.log('success:' + JSON.stringfy(data)); console.log('success:' + JSON.stringfy(data));
}).catch((error) => { }).catch((error) => {
...@@ -214,8 +214,10 @@ SystemCapability.Ability.AbilityRuntime.Core ...@@ -214,8 +214,10 @@ SystemCapability.Ability.AbilityRuntime.Core
Defines the **ConnectOptions** data structure. Defines the **ConnectOptions** data structure.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| onConnect(elementName:ElementName,&nbsp;remote:IRemoteObject) | Called when this ability is connected to a Service ability.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core| | 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.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core| | onDisconnect(elementName:ElementName) | Called when the peer service is abnormal or killed.|
| onFailed(code:&nbsp;number) | Called when the connection fails.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core| | onFailed(code:&nbsp;number) | Called when the connection fails.|
...@@ -23,7 +23,7 @@ None ...@@ -23,7 +23,7 @@ None
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| context | [ServiceExtensionContext](js-apis-service-extension-context.md) | Yes| No| Service extension context, which is inherited from **ExtensionContext**.| | context | [ServiceExtensionContext](js-apis-service-extension-context.md) | Yes| No| Service extension context, which is inherited from **ExtensionContext**.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
## onCreate ## onCreate
...@@ -32,17 +32,17 @@ onCreate(want: Want): void; ...@@ -32,17 +32,17 @@ onCreate(want: Want): void;
Called when an extension is created to initialize the service logic. Called when an extension is created to initialize the service logic.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information related to this extension, including the ability name and bundle name.| | want | [Want](js-apis-featureAbility.md#Want)| Yes| Information related to this extension, including the ability name and bundle name.|
- Example **Example**
```
```js
class ServiceExt extends ServiceExtension { class ServiceExt extends ServiceExtension {
onCreate(want) { onCreate(want) {
console.log('onCreate, want:' + want.abilityName); console.log('onCreate, want:' + want.abilityName);
...@@ -57,12 +57,11 @@ onDestroy(): void; ...@@ -57,12 +57,11 @@ onDestroy(): void;
Called when this extension is destroyed to clear resources. Called when this extension is destroyed to clear resources.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Example**
- Example ```js
```
class ServiceExt extends ServiceExtension { class ServiceExt extends ServiceExtension {
onDestroy() { onDestroy() {
console.log('onDestroy'); console.log('onDestroy');
...@@ -77,18 +76,18 @@ onRequest(want: Want, startId: number): void; ...@@ -77,18 +76,18 @@ onRequest(want: Want, startId: number): void;
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.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information related to this extension, including the ability name and bundle name.| | want | [Want](js-apis-featureAbility.md#Want)| Yes| Information related to this extension, including the ability name and bundle name.|
| startId | number | Yes| Number of ability start times. The initial value is **1**, and the value is automatically incremented for each ability started.| | startId | number | Yes| Number of ability start times. The initial value is **1**, and the value is automatically incremented for each ability started.|
- Example **Example**
```
```js
class ServiceExt extends ServiceExtension { class ServiceExt extends ServiceExtension {
onRequest(want, startId) { onRequest(want, startId) {
console.log('onRequest, want:' + want.abilityName); console.log('onRequest, want:' + want.abilityName);
...@@ -103,22 +102,23 @@ onConnect(want: Want): rpc.RemoteObject; ...@@ -103,22 +102,23 @@ onConnect(want: Want): rpc.RemoteObject;
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.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information related to this extension, including the ability name and bundle name.| | want | [Want](js-apis-featureAbility.md#Want)| Yes| Information related to this extension, including the ability name and bundle name.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| rpc.RemoteObject | A **RemoteObject** object used for communication with the client.| | rpc.RemoteObject | A **RemoteObject** object used for communication with the client.|
- Example **Example**
```
```js
import rpc from '@ohos.rpc' import rpc from '@ohos.rpc'
class StubTest extends rpc.RemoteObject{ class StubTest extends rpc.RemoteObject{
constructor(des) { constructor(des) {
...@@ -142,17 +142,17 @@ onDisconnect(want: Want): void; ...@@ -142,17 +142,17 @@ onDisconnect(want: Want): void;
Called when the ability is disconnected. Called when the ability is disconnected.
**System capabilities** **System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core **Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want |[Want](js-apis-featureAbility.md#Want)| Yes| Information related to this extension, including the ability name and bundle name.| | want |[Want](js-apis-featureAbility.md#Want)| Yes| Information related to this extension, including the ability name and bundle name.|
- Example **Example**
```
```js
class ServiceExt extends ServiceExtension { class ServiceExt extends ServiceExtension {
onDisconnect(want) { onDisconnect(want) {
console.log('onDisconnect, want:' + want.abilityName); console.log('onDisconnect, want:' + want.abilityName);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册