diff --git a/en/application-dev/reference/apis/js-apis-Context.md b/en/application-dev/reference/apis/js-apis-Context.md index ea7efb523f253f83fec2133b7a9acb37ddd5727d..4b2526ce8336f5ae3391f0652cbf17dacb7c6f54 100644 --- a/en/application-dev/reference/apis/js-apis-Context.md +++ b/en/application-dev/reference/apis/js-apis-Context.md @@ -7,7 +7,7 @@ import featureAbility from '@ohos.ability.featureAbility' 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 import featureAbility from '@ohos.ability.featureAbility' @@ -15,26 +15,21 @@ var context = featureAbility.getContext(); context.getOrCreateLocalDir() ``` -## Context - -### getOrCreateLocalDir +## Context.getOrCreateLocalDir getOrCreateLocalDir(callback: AsyncCallback\): void -Obtains the local root directory of the application. This method uses a callback to return the result. - -If this method is called for the first time, a root directory is created. +Obtains the local root directory of the application. This API uses an asynchronous callback to return the result. -**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** - | Name | Type | Mandatory| Description | | -------- | ---------------------- | ---- | -------------------------- | -| callback | AsyncCallback\ | Yes | Callback used to return the local root directory of the application.| +| callback | AsyncCallback\ | Yes | Callback used to return the local root directory.| **Example** @@ -48,23 +43,21 @@ context.getOrCreateLocalDir((err, data)=>{ -### getOrCreateLocalDir +## Context.getOrCreateLocalDir getOrCreateLocalDir(): Promise\ -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** - -SystemCapability.Ability.AbilityRuntime.Core +**System capability**: SystemCapability.Ability.AbilityRuntime.Core **Return value** | Type | Description | | ---------------- | ---------------------- | -| Promise\ | Promise used to return the local root directory of the application.| +| Promise\ | Promise used to return the local root directory.| **Example** @@ -78,19 +71,16 @@ context.getOrCreateLocalDir().then((data) => { -### verifyPermission +## Context.verifyPermission verifyPermission(permission: string, options: PermissionOptions, callback: AsyncCallback\): void -Verifies whether a specific PID and UID have the given permission. This method uses a callback to return the result. - -**System capabilities** +Verifies whether a specific PID and UID have the given permission. This API uses an asynchronous callback to return the result. -SystemCapability.Ability.AbilityRuntime.Core +**System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** - | Name | Type | Mandatory| Description | | ---------- | --------------------------------------- | ---- | ------------------------------------- | | permission | string | Yes | Name of the permission to verify. | @@ -110,14 +100,15 @@ bundle.getBundleInfo('com.context.test', 1, (datainfo) =>{ -### verifyPermission +## Context.verifyPermission verifyPermission(permission: string, callback: AsyncCallback\): 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 | | ---------- | ---------------------- | ---- | ------------------------------------- | @@ -132,19 +123,16 @@ var context = featureAbility.getContext(); context.verifyPermission("com.example.permission") ``` -### verifyPermission +## Context.verifyPermission verifyPermission(permission: string, options?: PermissionOptions): Promise\ -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** - -SystemCapability.Ability.AbilityRuntime.Core +**System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** - | Name | Type | Mandatory| Description | | ---------- | --------------------------------------- | ---- | ---------------- | | permission | string | Yes | Name of the permission to verify.| @@ -170,24 +158,22 @@ context.verifyPermission('com.context.permission',Permission).then((data) => { -### requestPermissionsFromUser +## Context.requestPermissionsFromUser -requestPermissionsFromUser(permissions: Array\, requestCode: number, resultCallback: AsyncCallback<[PermissionRequestResult](#permissionrequestresult)>) +requestPermissionsFromUser(permissions: Array\, 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** - -SystemCapability.Ability.AbilityRuntime.Core +**System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** - | Name | Type | Mandatory| Description | | -------------- | ------------------------------------------------------------ | ---- | ----------------------------------------------- | | permissions | Array\ | Yes | Permissions to request. This parameter cannot be **null**. | | requestCode | number | Yes | Request code to be passed to **PermissionRequestResult**.| | resultCallback | AsyncCallback<[PermissionRequestResult](#permissionrequestresult)> | Yes | Permission request result. | + **Example** ```js @@ -208,15 +194,13 @@ context.requestPermissionsFromUser( -### getApplicationInfo +## Context.getApplicationInfo -getApplicationInfo(callback: AsyncCallback\) +getApplicationInfo(callback: AsyncCallback\): 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** - -SystemCapability.Ability.AbilityRuntime.Core +**System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** @@ -234,15 +218,13 @@ context.getApplicationInfo() -### getApplicationInfo +## Context.getApplicationInfo getApplicationInfo(): Promise\ -Obtains information about the current application. This method uses a promise to return the result. - -**System capabilities** +Obtains information about the current application. This API uses a promise to return the result. -SystemCapability.Ability.AbilityRuntime.Core +**System capability**: SystemCapability.Ability.AbilityRuntime.Core **Return value** @@ -263,15 +245,13 @@ context.getApplicationInfo().then((data) => { -### getBundleName +## Context.getBundleName getBundleName(callback: AsyncCallback\): 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** - -SystemCapability.Ability.AbilityRuntime.Core +**System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** @@ -289,15 +269,13 @@ context.getBundleName() -### getBundleName +## Context.getBundleName getBundleName(): Promise\ -Obtains the bundle name of the current ability. This method uses a promise to return the result. - -**System capabilities** +Obtains the bundle name of the current ability. This API uses a promise to return the result. -SystemCapability.Ability.AbilityRuntime.Core +**System capability**: SystemCapability.Ability.AbilityRuntime.Core **Return value** @@ -318,15 +296,13 @@ context.getBundleName().then((data) => { -### getProcessInfo +## Context.getProcessInfo -getProcessInfo(callback: AsyncCallback\) +getProcessInfo(callback: AsyncCallback\): 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** - -SystemCapability.Ability.AbilityRuntime.Core +**System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** @@ -344,15 +320,13 @@ context.getProcessInfo() -### getProcessInfo +## Context.getProcessInfo getProcessInfo(): Promise\ -Obtains information about the current process, including the PID and process name. This method uses a promise to return the result. - -**System capabilities** +Obtains information about the current process, including the PID and process name. This API uses a promise to return the result. -SystemCapability.Ability.AbilityRuntime.Core +**System capability**: SystemCapability.Ability.AbilityRuntime.Core **Return value** @@ -373,17 +347,15 @@ context.getProcessInfo().then((data) => { -### getElementName +## Context.getElementName getElementName(callback: AsyncCallback\): 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** - -SystemCapability.Ability.AbilityRuntime.Core +**System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** @@ -401,17 +373,15 @@ context.getElementName() -### getElementName +## Context.getElementName getElementName(): Promise\ -Obtains the **ohos.bundle.ElementName** object of the current ability. This method uses a promise to return the result. - -This method is available only to Page abilities. +Obtains the **ohos.bundle.ElementName** object of the current ability. This API uses a promise to return the result. -**System capabilities** +This API is available only to Page abilities. -SystemCapability.Ability.AbilityRuntime.Core +**System capability**: SystemCapability.Ability.AbilityRuntime.Core **Return value** @@ -430,15 +400,15 @@ context.getElementName().then((data) => { }); ``` -### getProcessName +## Context.getProcessName getProcessName(callback: AsyncCallback\): 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 | | -------- | ---------------------- | ---- | -------------------- | @@ -454,15 +424,13 @@ context.getProcessName() -### getProcessName +## Context.getProcessName getProcessName(): Promise\ -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** - -SystemCapability.Ability.AbilityRuntime.Core +**System capability**: SystemCapability.Ability.AbilityRuntime.Core **Return value** @@ -483,15 +451,13 @@ context.getProcessName().then((data) => { -### getCallingBundle +## Context.getCallingBundle getCallingBundle(callback: AsyncCallback\): void -Obtains the bundle name of the calling ability. This method uses a callback to return the result. - -**System capabilities** +Obtains the bundle name of the calling ability. This API uses an asynchronous callback to return the result. -SystemCapability.Ability.AbilityRuntime.Core +**System capability**: SystemCapability.Ability.AbilityRuntime.Core **Parameters** @@ -509,15 +475,13 @@ context.getCallingBundle() -### getCallingBundle +## Context.getCallingBundle getCallingBundle(): Promise\ -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** - -SystemCapability.Ability.AbilityRuntime.Core +**System capability**: SystemCapability.Ability.AbilityRuntime.Core **Return value** @@ -536,17 +500,443 @@ context.getCallingBundle().then((data) => { }); ``` +## Context.getCacheDir + +getCacheDir(callback: AsyncCallback\): 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\ | 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\ + +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\ | 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\): 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\ | 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\ + +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\ | 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\): 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\ | 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\ + +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\ | 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\): 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\ | 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\ + +Obtains the application type. This API uses a promise to return the result. + +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + +**Return value** + +| Type | Description | +| --------------- | ------------------------- | +| Promise\ | 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\): 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\ + +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\): 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\ + +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\): 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\ + +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 +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + | Name| Readable/Writable| Type | Mandatory| Description | | ---- | -------- | ------ | ---- | ------ | -| pid | Read-only | number | No | PID.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| -| uid | Read-only | number | No | UID.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| +| pid | Read-only | number | No | Process ID.| +| uid | Read-only | number | No | User ID.| ## PermissionRequestResult +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + | Name | Readable/Writable| Type | Mandatory| Description | | ----------- | -------- | -------------- | ---- | ------------------ | -| requestCode | Read-only | number | Yes | Request code passed.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| -| permissions | Read-only | Array\ | Yes | Permissions passed.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core | -| authResults | Read-only | Array\ | Yes | Permission request result.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core | +| requestCode | Read-only | number | Yes | Request code passed.| +| permissions | Read-only | Array\ | Yes | Permissions requested. | +| authResults | Read-only | Array\ | 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 | Yes | No | Capabilities required for module running.| +| deviceTypes | Array | Yes | No | An array of supported device types.| +| abilityInfo | Array | 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. | diff --git a/en/application-dev/reference/apis/js-apis-DataUriUtils.md b/en/application-dev/reference/apis/js-apis-DataUriUtils.md index b45c839bc405c3cd65bbebe2f029e9930d8074ee..267ba0d27b3fbf9e3b35a8dbb884da04286f5729 100644 --- a/en/application-dev/reference/apis/js-apis-DataUriUtils.md +++ b/en/application-dev/reference/apis/js-apis-DataUriUtils.md @@ -1,5 +1,8 @@ # 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 ```js @@ -12,15 +15,17 @@ getId(uri: string): number 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** -| Type| Description| + +| Type | Description | | ------ | ------------------------ | | number | ID obtained from the URI object.| @@ -38,16 +43,18 @@ attachId(uri: string, id: number): string 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.| -| id | number | Yes| ID to be attached.| +| uri | string | Yes | URI object to which an ID is to be attached.| +| id | number | Yes | ID to be attached. | **Return value** -| Type| Description| + +| Type | Description | | ------ | --------------------- | | string | URI object with the ID attached.| @@ -69,14 +76,17 @@ deleteId(uri: string): string Deletes the ID from the end of a given URI. +**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 deleted.| +| uri | string | Yes | URI object from which the ID is to be deleted.| **Return value** -| Type| Description| + +| Type | Description | | ------ | ------------------- | | string | URI object with the ID deleted.| @@ -94,15 +104,18 @@ updateId(uri: string, id: number): string Updates the ID in a given URI. +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + **Parameters** -| Name| Type| Mandatory| Description| +| Name| Type | Mandatory| Description | | ---- | ------ | ---- | ------------------- | -| uri | string | Yes| URI object to be updated.| -| id | number | Yes| New ID.| +| uri | string | Yes | URI object to be updated.| +| id | number | Yes | New ID. | **Return value** -| Type| Description| + +| Type | Description | | ------ | --------------- | | string | URI object with the new ID.| diff --git a/en/application-dev/reference/apis/js-apis-ability-context.md b/en/application-dev/reference/apis/js-apis-ability-context.md index 7652774178a2357e7a8cb5928545f80348d1c2d2..6e5f9e4b36e1df88f85f2b9a91434b700f508673 100644 --- a/en/application-dev/reference/apis/js-apis-ability-context.md +++ b/en/application-dev/reference/apis/js-apis-ability-context.md @@ -14,7 +14,7 @@ Before using the **AbilityContext** module, you must define a child class that i -``` +```js import Ability from '@ohos.application.Ability' class MainAbility extends Ability { onWindowStageCreate(windowStage) { @@ -28,28 +28,28 @@ class MainAbility extends Ability { | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| abilityInfo | AbilityInfo | Yes| No| Ability information.| -| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.| +| abilityInfo | AbilityInfo | Yes| No| Ability information.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core| +| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core| -## startAbility +## AbilityContext.startAbility startAbility(want: Want, callback: AsyncCallback<void>): 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| | -------- | -------- | -------- | -------- | | want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.| | callback | AsyncCallback<void> | Yes| Callback used to return the result.| -- Example - ``` +**Example** + + ```js var want = { "deviceId": "", "bundleName": "com.extreme.test", @@ -61,26 +61,25 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## startAbility +## AbilityContext.startAbility startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): 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.| | options | StartOptions | Yes| Parameters used for starting the ability.| | callback | AsyncCallback<void> | Yes| Callback used to return the result.| -- Example +**Example** - ``` + ```js var want = { "deviceId": "", "bundleName": "com.extreme.test", @@ -95,29 +94,30 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## startAbility +## AbilityContext.startAbility -startAbility(want: Want, options: StartOptions): Promise<void>; +startAbility(want: Want, options?: StartOptions): Promise<void>; -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| | -------- | -------- | -------- | -------- | | 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| | -------- | -------- | | Promise<void> | Promise used to return the result.| -- Example - ``` +**Example** + + ```js var want = { "deviceId": "", "bundleName": "com.extreme.test", @@ -135,25 +135,25 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## startAbilityForResult +## AbilityContext.startAbilityForResult startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>): 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| | -------- | -------- | -------- | -------- | | want |[Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.| | callback | AsyncCallback<[AbilityResult](js-apis-featureAbility.md#abilityresult)> | Yes| Callback used to return the result.| -- Example - ``` +**Example** + + ```js this.context.startAbilityForResult( {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, (error, result) => { @@ -163,17 +163,16 @@ SystemCapability.Ability.AbilityRuntime.Core ); ``` -## startAbilityForResult +## AbilityContext.startAbilityForResult startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback<AbilityResult>): 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| | -------- | -------- | -------- | -------- | | 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 | callback | AsyncCallback<[AbilityResult](js-apis-featureAbility.md#abilityresult)> | Yes| Callback used to return the result.| -- Example - ``` +**Example** + + ```js var options = { windowMode: 0, }; @@ -196,30 +196,31 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## startAbilityForResult +## AbilityContext.startAbilityForResult -startAbilityForResult(want: Want, options: StartOptions): Promise<AbilityResult>; +startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityResult>; -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| | -------- | -------- | -------- | -------- | | 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| | -------- | -------- | | Promise<[AbilityResult](js-apis-featureAbility.md#abilityresult)> | Promise used to return the result.| -- Example - ``` +**Example** + + ```js var options = { windowMode: 0, }; @@ -231,46 +232,46 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## terminateSelf +## AbilityContext.terminateSelf terminateSelf(callback: AsyncCallback<void>): 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| | -------- | -------- | -------- | -------- | - | 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 API is successfully called.| -- Example - ``` +**Example** + + ```js this.context.terminateSelf((err) => { console.log('terminateSelf result:' + JSON.stringfy(err)); }); ``` -## terminateSelf +## AbilityContext.terminateSelf terminateSelf(): Promise<void>; -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| | -------- | -------- | - | Promise<void> | Promise used to return the result indicating whether the method is successfully called.| + | Promise<void> | Promise used to return the result indicating whether the API is successfully called.| -- Example - ``` +**Example** + + ```js this.context.terminateSelf(want).then((data) => { console.log('success:' + JSON.stringfy(data)); }).catch((error) => { @@ -279,24 +280,24 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## terminateSelfWithResult +## AbilityContext.terminateSelfWithResult terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<void>): 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| | -------- | -------- | -------- | -------- | | parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.| | callback | AsyncCallback<void> | Yes| Callback used to return the result.| -- Example - ``` +**Example** + + ```js this.context.terminateSelfWithResult( { want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"}, @@ -308,28 +309,29 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## terminateSelfWithResult +## AbilityContext.terminateSelfWithResult terminateSelfWithResult(parameter: AbilityResult): Promise<void>; -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| | -------- | -------- | -------- | -------- | | parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.| -- Return value +**Return value** + | Type| Description| | -------- | -------- | | Promise<void> | Promise used to return the result.| -- Example - ``` +**Example** + + ```js this.context.terminateSelfWithResult( { want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"}, @@ -341,29 +343,29 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## startAbilityByCall +## AbilityContext.startAbilityByCall startAbilityByCall(want: Want): Promise<Caller>; 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.| -- Return value - | Type| Description| +**Return value** + + | Type| Description| | -------- | -------- | - | Promise<> | Promise used to return the caller object to communicate with.| + | Promise<Caller> | Promise used to return the caller object to communicate with.| -- Example +**Example** - ``` + ```js import Ability from '@ohos.application.Ability'; var caller; export default class MainAbility extends Ability { @@ -383,23 +385,22 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## requestPermissionsFromUser +## AbilityContext.requestPermissionsFromUser requestPermissionsFromUser(permissions: Array<string>, requestCallback: AsyncCallback<PermissionRequestResult>) : 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<string> | Yes| Permissions to request.| - | callback | AsyncCallback<[PermissionRequestResult](js-apis-permissionrequestresult.md)> | Yes| Callback used to return the result indicating whether the method is successfully called.| + | callback | AsyncCallback<[PermissionRequestResult](js-apis-permissionrequestresult.md)> | Yes| Callback used to return the result indicating whether the API is successfully called.| -- Example +**Example** ``` this.context.requestPermissionsFromUser(permissions,(result) => { @@ -408,27 +409,27 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## requestPermissionsFromUser +## AbilityContext.requestPermissionsFromUser requestPermissionsFromUser(permissions: Array<string>) : Promise<PermissionRequestResult>; -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<string> | Yes| Permissions to request.| + | permissions | Array<string> | Yes| Permissions to request.| + +**Return value** -- Return value - | Type| Description| + | Type| Description| | -------- | -------- | - | Promise<[PermissionRequestResult](js-apis-permissionrequestresult.md)> | Promise used to return the result indicating whether the method is successfully called.| + | Promise<[PermissionRequestResult](js-apis-permissionrequestresult.md)> | Promise used to return the result indicating whether the API is successfully called.| -- Example +**Example** ``` this.context.requestPermissionsFromUser(permissions).then((data) => { @@ -439,54 +440,53 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## setMissionLabel +## AbilityContext.setMissionLabel setMissionLabel(label: string, callback:AsyncCallback<void>): 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.| - | 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 API is successfully called.| -- Example +**Example** - ``` + ```js this.context.setMissionLabel("test",(result) => { console.log('requestPermissionsFromUserresult:' + JSON.stringfy(result)); }); ``` -## setMissionLabel +## AbilityContext.setMissionLabel setMissionLabel(label: string): Promise<void> -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.| -- Return value - | Type| Description| +**Return value** + + | Type| Description| | -------- | -------- | - | Promise<void> | Promise used to return the result indicating whether the method is successfully called.| + | Promise<void> | Promise used to return the result indicating whether the API is successfully called.| -- Example +**Example** - ``` + ```js this.context.setMissionLabel("test").then((data) => { console.log('success:' + JSON.stringfy(data)); }).catch((error) => { diff --git a/en/application-dev/reference/apis/js-apis-abilityrunninginfo.md b/en/application-dev/reference/apis/js-apis-abilityrunninginfo.md index 58673b2285ee51d3c952af4b14e9ede1137b909d..0ed9eb40d2cfe73bcc98bfb394d894809f6700dc 100644 --- a/en/application-dev/reference/apis/js-apis-abilityrunninginfo.md +++ b/en/application-dev/reference/apis/js-apis-abilityrunninginfo.md @@ -10,38 +10,39 @@ Provides ability running information. ## 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'; abilitymanager.getAbilityRunningInfos((err,data) => { console.log("getAbilityRunningInfos err: " + err + " data: " + JSON.stringify(data)); }); ``` - ## 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.| -| uid | number | Yes| No| User ID.| -| processName | string | Yes| No| Process name.| -| startTime | number | Yes| No| Ability start time.| -| abilityState | [abilityManager.AbilityState](#abilitymanager-abilitystate) | Yes| No| Ability state.| +| uid | number | Yes| No| User ID. | +| processName | string | Yes| No| Process name. | +| startTime | number | Yes| No| Ability start time. | +| abilityState | [abilityManager.AbilityState](#abilitymanager-abilitystate) | Yes| No| Ability state. | ## abilityManager.AbilityState - 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.| -| FOREGROUND | 9 | The ability is in the foreground state.| -| BACKGROUND | 10 | The ability is in the background state.| -| FOREGROUNDING | 11 | The ability is in the foregrounding state.| -| BACKGROUNDING | 12 | The ability is in the backgrounding state.| +| FOREGROUND | 9 | The ability is in the foreground state. | +| BACKGROUND | 10 | The ability is in the background state. | +| FOREGROUNDING | 11 | The ability is in the foregrounding state. | +| BACKGROUNDING | 12 | The ability is in the backgrounding state. | diff --git a/en/application-dev/reference/apis/js-apis-abilitystagecontext.md b/en/application-dev/reference/apis/js-apis-abilitystagecontext.md index c41326589ba67c9297b8326ab10085f18863f48e..91e8a7513e8c68f06105d14d4a96fc0cec9e2fac 100644 --- a/en/application-dev/reference/apis/js-apis-abilitystagecontext.md +++ b/en/application-dev/reference/apis/js-apis-abilitystagecontext.md @@ -14,7 +14,7 @@ The ability stage context is obtained through an **AbilityStage** instance. -``` +```js import AbilityStage from '@ohos.application.AbilityStage'; class MyAbilityStage extends AbilityStage { onCreate() { @@ -25,8 +25,9 @@ class MyAbilityStage extends AbilityStage { ## 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**.| | config | [Configuration](js-apis-configuration.md) | Yes| No| Configuration for the environment where the application is running.| diff --git a/en/application-dev/reference/apis/js-apis-application-ability.md b/en/application-dev/reference/apis/js-apis-application-ability.md index 230d2a73f61aa324c547ec0819a234a6603d4b24..e775138da3d761cc425df00d59e58e2f6fbbc3bc 100644 --- a/en/application-dev/reference/apis/js-apis-application-ability.md +++ b/en/application-dev/reference/apis/js-apis-application-ability.md @@ -1,7 +1,7 @@ # Ability > ![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. @@ -14,31 +14,33 @@ Manages the ability lifecycle and context. import Ability from '@ohos.application.Ability'; ``` - ## Attributes - | Name| Type| Readable| Writable| Description| +| Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| context | [AbilityContext](js-apis-ability-context.md) | Yes| No| Context of an ability.| -| launchWant | [Want](js-apis-featureAbility.md#Want)| Yes| No| Parameters for starting the ability.| -| lastRequestWant | [Want](js-apis-featureAbility.md#Want)| Yes| No| Parameters used when the ability was started last time.| +| context | [AbilityContext](js-apis-ability-context.md) | Yes| No| Context of an ability.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore| +| launchWant | [Want](js-apis-featureAbility.md#Want)| Yes| No| Parameters for starting the ability.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore| +| lastRequestWant | [Want](js-apis-featureAbility.md#Want)| Yes| No| Parameters used when the ability was started last time.
**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. -- Parameters - | Name| Type| Mandatory| Description| +**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore + +**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.| - | 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 { onCreate(want, param) { console.log('onCreate, want:' + want.abilityName); @@ -47,20 +49,23 @@ Called to initialize the service logic when an ability is created. ``` -## onWindowStageCreate +## Ability.onWindowStageCreate onWindowStageCreate(windowStage: window.WindowStage): void Called when a **WindowStage** is created for this ability. -- Parameters - | Name| Type| Mandatory| Description| +**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore + +**Parameters** + + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | windowStage | window.WindowStage | Yes| **WindowStage** information.| -- Example +**Example** - ``` + ```js class myAbility extends Ability { onWindowStageCreate(windowStage) { console.log('onWindowStageCreate'); @@ -69,15 +74,17 @@ Called when a **WindowStage** is created for this ability. ``` -## onWindowStageDestroy +## Ability.onWindowStageDestroy onWindowStageDestroy(): void Called when the **WindowStage** is destroyed for this ability. -- Example +**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore + +**Example** - ``` + ```js class myAbility extends Ability { onWindowStageDestroy() { console.log('onWindowStageDestroy'); @@ -86,20 +93,23 @@ Called when the **WindowStage** is destroyed for this ability. ``` -## onWindowStageRestore +## Ability.onWindowStageRestore onWindowStageRestore(windowStage: window.WindowStage): void Called when the **WindowStage** is restored during the migration of this ability, which is a multi-instance ability. -- Parameters - | Name| Type| Mandatory| Description| +**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore + +**Parameters** + + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | windowStage | window.WindowStage | Yes| **WindowStage** information.| -- Example +**Example** - ``` + ```js class myAbility extends Ability { onWindowStageRestore(windowStage) { console.log('onWindowStageRestore'); @@ -108,15 +118,17 @@ Called when the **WindowStage** is restored during the migration of this ability ``` -## onDestroy +## Ability.onDestroy onDestroy(): void; Called when this ability is destroyed to clear resources. -- Example +**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore + +**Example** - ``` + ```js class myAbility extends Ability { onDestroy() { console.log('onDestroy'); @@ -125,15 +137,17 @@ Called when this ability is destroyed to clear resources. ``` -## onForeground +## Ability.onForeground onForeground(): void; Called when this ability is running in the foreground. -- Example +**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore + +**Example** - ``` + ```js class myAbility extends Ability { onForeground() { console.log('onForeground'); @@ -142,15 +156,17 @@ Called when this ability is running in the foreground. ``` -## onBackground +## Ability.onBackground onBackground(): void; Callback when this ability is switched to the background. -- Example +**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore + +**Example** - ``` + ```js class myAbility extends Ability { onBackground() { console.log('onBackground'); @@ -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. -- Parameters - | Name| Type| Mandatory| Description| +**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore + +**Parameters** + + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | wantParam | {[key: string]: any} | Yes| **want** parameter.| -- Return value - | Type| Description| +**Return value** + + | Type| Description| | -------- | -------- | - | boolean | Returns **true** if the migration is accepted; returns **false** otherwise.| + | AbilityConstant.OnContinueResult | Continuation result.| -- Example +**Example** - ``` + ```js class myAbility extends Ability { onContinue(wantParams) { console.log('onContinue'); @@ -188,20 +208,23 @@ Called to save data during the ability migration preparation process. ``` -## onNewWant +## Ability.onNewWant onNewWant(want: Want): void; Called when the ability startup mode is set to singleton. -- Parameters - | Name| Type| Mandatory| Description| +**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore + +**Parameters** + + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | 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 { onNewWant(want) { console.log('onNewWant, want:' + want.abilityName); @@ -210,20 +233,23 @@ Called when the ability startup mode is set to singleton. ``` -## onConfigurationUpdated +## Ability.onConfigurationUpdated onConfigurationUpdated(config: Configuration): void; Called when the configuration of the environment where the ability is running is updated. -- Parameters - | Name| Type| Mandatory| Description| +**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore + +**Parameters** + + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | config | [Configuration](#section188911144124715) | Yes| New configuration.| -- Example +**Example** - ``` + ```js class myAbility extends Ability { onConfigurationUpdated(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 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<void>; +call(method: string, data: rpc.Sequenceable): Promise<void>; Sends sequenceable data to the target ability. -- Parameters - | Name| Type| Mandatory| Description| +**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore + +**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.| | data | rpc.Sequenceable | Yes| Sequenceable data. You need to customize the data.| -- Return value - | Type| Description| +**Return value** + + | Type| Description| | -------- | -------- | | Promise<void> | Promise used to return a response.| -- Example +**Example** - ``` + ```js import Ability from '@ohos.application.Ability'; class MyMessageAble{ // Custom sequenceable data structure - num: 0 - str: '' - constructor() {} + constructor(name, str) { + this.name = name; + this.str = str; + } marshalling(messageParcel) { messageParcel.writeInt(this.num); messageParcel.writeString(this.str); @@ -279,47 +310,59 @@ Sends sequenceable data to the target ability. var caller; export default class MainAbility extends Ability { onWindowStageCreate(windowStage) { - caller = await this.context.startAbilityByCall({ - bundleName: "com.example.myservice", - abilityName: "com.example.myservice.MainAbility", - deviceId: "" - }); - let msg = new MyMessageAble(1, "world"); // See the definition of Sequenceable. - caller.call(method, msg) - .then(() => { - console.log('Caller call() called'); - }).catch((e) => { - console.log('Caller call() catch error ' + e); - }); + this.context.startAbilityByCall({ + bundleName: "com.example.myservice", + abilityName: "com.example.myservice.MainAbility", + deviceId: "" + }).then((obj) => { + caller = obj; + let msg = new MyMessageAble(1, "world"); // See the definition of Sequenceable. + caller.call(method, msg) + .then(() => { + console.log('Caller call() called'); + }).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<rpc.MessageParcel>; +callWithResult(method: string, data: rpc.Sequenceable): Promise<rpc.MessageParcel>; Sends sequenceable data to the target ability and obtains the sequenceable data returned by the target ability. -- Parameters - | Name| Type| Mandatory| Description| +**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore + +**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.| | data | rpc.Sequenceable | Yes| Sequenceable data. You need to customize the data.| -- Return value - | Type| Description| +**Return value** + + | Type| Description| | -------- | -------- | | Promise<rpc.MessageParcel> | Promise used to return the sequenceable data from the target ability.| -- Example +**Example** - ``` + ```js import Ability from '@ohos.application.Ability'; class MyMessageAble{ - num: 0 - str: '' + constructor(name, str) { + this.name = name; + this.str = str; + } constructor() {} marshalling(messageParcel) { messageParcel.writeInt(this.num); @@ -338,83 +381,104 @@ Sends sequenceable data to the target ability and obtains the sequenceable data var caller; export default class MainAbility extends Ability { onWindowStageCreate(windowStage) { - caller = await this.context.startAbilityByCall({ - bundleName: "com.example.myservice", - abilityName: "com.example.myservice.MainAbility", - deviceId: "" - }); - let msg = new MyMessageAble(1, "world"); - caller.callWithResult(method, msg) - .then((data) => { - console.log('Caller call() called'); - let retmsg = new MyMessageAble(0, ""); - data.readSequenceable(retmsg); - }).catch((e) => { - console.log('Caller call() catch error ' + e); - }); + onWindowStageCreate(windowStage) { + this.context.startAbilityByCall({ + bundleName: "com.example.myservice", + abilityName: "com.example.myservice.MainAbility", + deviceId: "" + }).then((obj) => { + caller = obj; + let msg = new MyMessageAble(1, "world"); + caller.callWithResult(method, msg) + .then((data) => { + console.log('Caller callWithResult() called'); + let retmsg = new MyMessageAble(0, ""); + 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; Releases the caller interface of the target ability. -- Example +**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore + +**Example** - ``` + ```js import Ability from '@ohos.application.Ability'; var caller; export default class MainAbility extends Ability { onWindowStageCreate(windowStage) { - caller = await this.context.startAbilityByCall({ - bundleName: "com.example.myservice", - abilityName: "com.example.myservice.MainAbility", - deviceId: "" - }); - try { - caller.release(); - } catch (e) { - console.log('Caller Release error ' + e); - } + this.context.startAbilityByCall({ + bundleName: "com.example.myservice", + abilityName: "com.example.myservice.MainAbility", + deviceId: "" + }).then((obj) => { + caller = obj; + try { + caller.release(); + } 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. -- Parameters - | Name| Type| Mandatory| Description| +**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore + +**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'; var caller; export default class MainAbility extends Ability { onWindowStageCreate(windowStage) { - caller = await this.context.startAbilityByCall({ - bundleName: "com.example.myservice", - abilityName: "com.example.myservice.MainAbility", - deviceId: "" - }); - try { - caller.onRelease((str) => { - console.log(' Caller OnRelease CallBack is called ' + str); - }); - } catch (e) { - console.log('Caller Release error ' + e); - } + this.context.startAbilityByCall({ + bundleName: "com.example.myservice", + abilityName: "com.example.myservice.MainAbility", + deviceId: "" + }).then((obj) => { + caller = obj; + try { + caller.onRelease((str) => { + console.log(' Caller OnRelease CallBack is called ' + str); + }); + } 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 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. -- Parameters - | Name| Type| Mandatory| Description| +**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore + +**Parameters** + + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | 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'; class MyMessageAble{ - num: 0 - str: '' - constructor() {} + constructor(name, str) { + this.name = name; + this.str = str; + } marshalling(messageParcel) { messageParcel.writeInt(this.num); messageParcel.writeString(this.str); @@ -474,20 +542,23 @@ Registers a caller notification callback, which is invoked when the target abili ``` -### off +## Callee.off off(method: string): void; Unregisters a caller notification callback, which is invoked when the target ability registers a function. -- Parameters - | Name| Type| Mandatory| Description| +**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore + +**Parameters** + + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | method | string | Yes| Registered notification message string.| -- Example +**Example** - ``` + ```js import Ability from '@ohos.application.Ability'; var method = 'call_Function'; export default class MainAbility extends Ability { @@ -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.
**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.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore | diff --git a/en/application-dev/reference/apis/js-apis-application-abilitystage.md b/en/application-dev/reference/apis/js-apis-application-abilitystage.md index 15b3acce30aed572a1deaf316c042739c5ec63ed..4f04fa0a109852d619697b1d4cab23382d086477 100644 --- a/en/application-dev/reference/apis/js-apis-application-abilitystage.md +++ b/en/application-dev/reference/apis/js-apis-application-abilitystage.md @@ -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. -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 -``` +```js import AbilityStage from '@ohos.application.AbilityStage'; ``` - -## onCreate +## AbilityStage.onCreate onCreate(): void Called when the application is created. -- Example +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + + + +**Example** - ``` + ```js class MyAbilityStage extends AbilityStage { onCreate() { console.log("MyAbilityStage.onCreate is called") @@ -32,25 +35,29 @@ Called when the application is created. ``` -## onAcceptWant +## AbilityStage.onAcceptWant onAcceptWant(want: Want): string; Called when a specified ability is started. -- Parameters - | Name| Type| Mandatory| Description| +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + +**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.| -- Return value - | Type| Description| +**Return value** + + | 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.| -- Example +**Example** - ``` + ```js class MyAbilityStage extends AbilityStage { onAcceptWant(want) { console.log("MyAbilityStage.onAcceptWant called"); @@ -60,23 +67,33 @@ Called when a specified ability is started. ``` -## onConfigurationUpdated +## AbilityStage.onConfigurationUpdated onConfigurationUpdated(config: Configuration): void; Called when the global configuration is updated. -- Parameters - | Name| Type| Mandatory| Description| +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + +**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.| -- Example +**Example** - ``` + ```js class MyAbilityStage extends AbilityStage { onConfigurationUpdated(config) { 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.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core| diff --git a/en/application-dev/reference/apis/js-apis-application-context.md b/en/application-dev/reference/apis/js-apis-application-context.md index 8c4ac18f623f3266933ffab172c6d05647d86b28..eaf0b4ceca53a65a4f8bb70ff4d181284271ea76 100644 --- a/en/application-dev/reference/apis/js-apis-application-context.md +++ b/en/application-dev/reference/apis/js-apis-application-context.md @@ -14,6 +14,7 @@ You must extend **AbilityContext** to implement this module. ## Attributes +**System capability**: SystemCapability.Ability.AbilityRuntime.Core | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | @@ -29,44 +30,51 @@ You must extend **AbilityContext** to implement this module. | eventHub | [EventHub](js-apis-eventhub.md) | Yes| No| Event hub information.| -## createBundleContext +## Context.createBundleContext createBundleContext(bundleName: string): Context; Creates an application context. -- **Parameters** - | Name| Type| Mandatory| Description| +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + +**Parameters** + + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | bundleName | string | Yes| Application bundle name.| -- Return value - | Type| Description| +**Return value** + + | Type| Description| | -------- | -------- | | Context | Context of the application created.| -- Example +**Example** - ``` + ```js let test = "com.example.test"; let context = this.context.createBundleContext(test); ``` -## getApplicationContext +## Context.getApplicationContext getApplicationContext(): Context; Obtains the context of this application. -- Return value - | Type| Description| +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + +**Return value** + + | Type| Description| | -------- | -------- | | Context | Context obtained.| -- Example +**Example** - ``` + ```js // This part is mandatory. let context = this.context.getApplicationContext(); ``` diff --git a/en/application-dev/reference/apis/js-apis-appmanager.md b/en/application-dev/reference/apis/js-apis-appmanager.md index 45ae9509e03e8bfec6fe71568e8a1fffb680dc67..a803daded9f58c1e1e53d4e464807d478a76bcc5 100644 --- a/en/application-dev/reference/apis/js-apis-appmanager.md +++ b/en/application-dev/reference/apis/js-apis-appmanager.md @@ -1,7 +1,7 @@ # appManager > ![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. @@ -10,50 +10,159 @@ Implements application management. ## Modules to Import -``` +```js import app from '@ohos.application.appManager'; ``` -## isRunningInStabilityTest +## appManager.isRunningInStabilityTest8+ static isRunningInStabilityTest(callback: AsyncCallback<boolean>): 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<boolean> | No| Callback used to return the result.| + | callback | AsyncCallback<boolean> | 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'; app.isRunningInStabilityTest((err, flag) => { - console.log('startAbility result:' + JSON.stringfy(err); - } + console.log('startAbility result:' + JSON.stringfy(err)); + }) ``` -## isRunningInStabilityTest +## appManager.isRunningInStabilityTest8+ static isRunningInStabilityTest(): Promise<boolean> -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<boolean> | Promise used to return the result.| + | Promise<boolean> | 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'; app.isRunningInStabilityTest().then((flag) => { console.log('success:' + JSON.stringfy(flag)); - )).catch((error) => { + }).catch((error) => { console.log('failed:' + JSON.stringfy(error)); }); ``` + + +## appManager.isRamConstrainedDevice + +isRamConstrainedDevice(): Promise\; + +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<boolean> | 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\): 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<boolean> | 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\; + +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<number> | 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\): 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<number> | 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)); + }) + } + ``` diff --git a/en/application-dev/reference/apis/js-apis-configuration.md b/en/application-dev/reference/apis/js-apis-configuration.md index e4199544636c77103197529f72de34145756ae5c..50803fb4587f9e8ec8e31f447a90eeccdd44780c 100644 --- a/en/application-dev/reference/apis/js-apis-configuration.md +++ b/en/application-dev/reference/apis/js-apis-configuration.md @@ -10,17 +10,19 @@ Provides the configuration for the environment where the ability is running. ## Modules to Import -``` +```js import Configuration from '@ohos.application.Configuration'; ``` ## Attributes +**System capability**: SystemCapability.Ability.AbilityBase + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | | 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**.| -| direction | 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).| -| displayId | number | Yes| No| ID of the display where the application is located.| +| direction9+ | Direction | Yes| No| Screen orientation, which can be **DIRECTION_HORIZONTAL** or **DIRECTION_VERTICAL**.| +| screenDensity9+ | 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).| +| displayId9+ | number | Yes| No| ID of the display where the application is located.| diff --git a/en/application-dev/reference/apis/js-apis-configurationconstant.md b/en/application-dev/reference/apis/js-apis-configurationconstant.md index 0e480eafe47e691044f6eb5095285962322e4a51..55f42b926d4bfcbb4b07a48185611b22a92cbc32 100644 --- a/en/application-dev/reference/apis/js-apis-configurationconstant.md +++ b/en/application-dev/reference/apis/js-apis-configurationconstant.md @@ -10,46 +10,67 @@ Defines enumerated values of the configuration for the environment where the abi ## Modules to Import -``` +```js 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_DARK | 0 | Dark 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_VERTICAL | 0 | Vertical direction.| -| DIRECTION_HORIZONTAL | 1 | Horizontal direction.| +| DIRECTION_NOT_SET9+ | -1 | Unspecified direction.| +| DIRECTION_VERTICAL9+ | 0 | Vertical direction.| +| DIRECTION_HORIZONTAL9+ | 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_SDPI | 120 | The screen resolution is sdpi.| -| SCREEN_DENSITY_MDPI | 160 | The screen resolution is mdpi.| -| SCREEN_DENSITY_LDPI | 240 | The screen resolution is ldpi.| -| SCREEN_DENSITY_XLDPI | 320 | The screen resolution is xldpi.| -| SCREEN_DENSITY_XXLDPI | 480 | The screen resolution is xxldpi.| -| SCREEN_DENSITY_XXXLDPI | 640 | The screen resolution is xxxldpi.| +| SCREEN_DENSITY_NOT_SET9+ | 0 | Unspecified screen resolution.| +| SCREEN_DENSITY_SDPI9+ | 120 | The screen resolution is sdpi.| +| SCREEN_DENSITY_MDPI9+ | 160 | The screen resolution is mdpi.| +| SCREEN_DENSITY_LDPI9+ | 240 | The screen resolution is ldpi.| +| SCREEN_DENSITY_XLDPI9+ | 320 | The screen resolution is xldpi.| +| SCREEN_DENSITY_XXLDPI9+ | 480 | The screen resolution is xxldpi.| +| SCREEN_DENSITY_XXXLDPI9+ | 640 | The screen resolution is xxxldpi.| diff --git a/en/application-dev/reference/apis/js-apis-dataAbilityHelper.md b/en/application-dev/reference/apis/js-apis-dataAbilityHelper.md index 49e61156a499d926620ecd0aa7bb6455c4aec9c7..fb34371c004c08cfc346a81cc13b8d3387f3ca94 100644 --- a/en/application-dev/reference/apis/js-apis-dataAbilityHelper.md +++ b/en/application-dev/reference/apis/js-apis-dataAbilityHelper.md @@ -8,17 +8,13 @@ import ohos_data_ability from '@ohos.data.dataability' import ohos_data_rdb from '@ohos.data.rdb' ``` -## DataAbilityHelper - -### openFile +## DataAbilityHelper.openFile openFile(uri: string, mode: string, callback: AsyncCallback\): void -Opens a file with a specified URI. This method uses a callback to return the result. - -**System capabilities** +Opens a file with a specified URI. This API uses an asynchronous callback to return the result. -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -44,15 +40,13 @@ DAHelper.openFile( }); ``` -### openFile +## DataAbilityHelper.openFile openFile(uri: string, mode: string): Promise\ -Opens a file with a specified URI. This method uses a promise to return the result. - -**System capabilities** +Opens a file with a specified URI. This API uses a promise to return the result. -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -62,6 +56,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel | mode | string | Yes | Mode for opening the file. The value can be **rwt**. | **Return value** + | Type | Description | | ---------------- | ---------------- | | Promise\ | Promise used to return the file descriptor.| @@ -81,15 +76,13 @@ DAHelper.openFile( }); ``` -### on('dataChange') +## DataAbilityHelper.on on(type: 'dataChange', uri: string, callback: AsyncCallback\): void -Registers an observer to observe data specified by a given URI. This method uses a callback to return the result. - -**System capabilities** +Registers an observer to observe data specified by a given URI. This API uses an asynchronous callback to return the result. -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -116,15 +109,13 @@ helper.on( ) ``` -### off('dataChange') +## DataAbilityHelper.off off(type: 'dataChange', uri: string, callback?: AsyncCallback\): 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** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -155,15 +146,13 @@ helper.off( ) ``` -### getType +## DataAbilityHelper.getType getType(uri: string, callback: AsyncCallback\): void -Obtains the MIME type of the data specified by a given URI. This method uses a callback to return the result. - -**System capabilities** +Obtains the MIME type of the data specified by a given URI. This API uses an asynchronous callback to return the result. -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -186,15 +175,13 @@ DAHelper.getType( }); ``` -### getType +## DataAbilityHelper.getType getType(uri: string): Promise\ -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** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -203,6 +190,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel | uri | string | Yes | URI of the data.| **Return value** + | Type | Description | | ---------------- | ----------------------------------- | | Promise\ | Promise used to return the MIME type.| @@ -221,15 +209,13 @@ DAHelper.getType( }); ``` -### getFileTypes +## DataAbilityHelper.getFileTypes getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback>): 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** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -256,15 +242,13 @@ DAHelper.getFileTypes( -### getFileTypes +## DataAbilityHelper.getFileTypes getFileTypes(uri: string, mimeTypeFilter: string): Promise\> -Obtains the supported MIME types of a specified file. This method uses a promise to return the result. - -**System capabilities** +Obtains the supported MIME types of a specified file. This API uses a promise to return the result. -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -274,6 +258,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel | mimeTypeFilter | string | Yes | MIME type of the file.| **Return value** + | Type | Description | | ------------------------ | ------------------------ | | Promise\> | Promise used to return the supported MIME types.| @@ -293,15 +278,13 @@ DAHelper.getFileTypes( }); ``` -### normalizeUri +## DataAbilityHelper.normalizeUri normalizeUri(uri: string, callback: AsyncCallback\): 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** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -324,15 +307,13 @@ DAHelper.normalizeUri( }); ``` -### normalizeUri +## DataAbilityHelper.normalizeUri normalizeUri(uri: string): Promise\ -Converts the URI that refers to a Data ability into a normalized URI. This method uses a promise to return the result. - -**System capabilities** +Converts the URI that refers to a Data ability into a normalized URI. This API uses a promise to return the result. -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -341,6 +322,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel | uri | string | Yes | URI object to normalize.| **Return value** + | Type | Description | | ---------------- | ------------------------------------------------------ | | Promise\ | 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( }); ``` -### denormalizeUri +## DataAbilityHelper.denormalizeUri denormalizeUri(uri: string, callback: AsyncCallback\): void -Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: string, callback: AsyncCallback\)** to a denormalized one. This method uses a callback to return the result. - -**System capabilities** +Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: string, callback: AsyncCallback\)** to a denormalized one. This API uses an asynchronous callback to return the result. -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -392,15 +372,13 @@ DAHelper.denormalizeUri( -### denormalizeUri +## DataAbilityHelper.denormalizeUri denormalizeUri(uri: string): Promise\ -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** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -409,6 +387,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel | uri | string | Yes | URI object to normalize.| **Return value** + | Type | Description | | ---------------- | ----------------------------------------- | | Promise\ | Promise used to return the denormalized URI object.| @@ -427,15 +406,13 @@ DAHelper.denormalizeUri( }); ``` -### notifyChange +## DataAbilityHelper.notifyChange notifyChange(uri: string, callback: AsyncCallback\): 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** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -458,15 +435,13 @@ helper.notifyChange( }); ``` -### notifyChange +## DataAbilityHelper.notifyChange notifyChange(uri: string): Promise\ -Notifies the registered observer of a change to the data specified by the URI. This method uses a promise to return the result. - -**System capabilities** +Notifies the registered observer of a change to the data specified by the URI. This API uses a promise to return the result. -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -475,6 +450,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel | uri | string | Yes | URI of the data.| **Return value** + | Type | Description | | -------------- | --------------------- | | Promise\ | Promise used to return the result.| @@ -493,15 +469,13 @@ DAHelper.notifyChange( }); ``` -### insert +## DataAbilityHelper.insert insert(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback\): 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** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -532,15 +506,13 @@ DAHelper.insert( }); ``` -### insert +## DataAbilityHelper.insert insert(uri: string, valuesBucket: rdb.ValuesBucket): Promise\ -Inserts a single data record into the database. This method uses a promise to return the result. - -**System capabilities** +Inserts a single data record into the database. This API uses a promise to return the result. -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -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.| **Return value** + | Type | Description | | ---------------- | ------------------------ | | Promise\ | Promise used to return the index of the inserted data record.| @@ -575,15 +548,13 @@ DAHelper.insert( }); ``` -### batchInsert +## DataAbilityHelper.batchInsert batchInsert(uri: string, valuesBuckets: Array, callback: AsyncCallback\): void -Inserts multiple data records into the database. This method uses a callback to return the result. - -**System capabilities** +Inserts multiple data records into the database. This API uses an asynchronous callback to return the result. -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -611,15 +582,13 @@ DAHelper.batchInsert( }); ``` -### batchInsert +## DataAbilityHelper.batchInsert batchInsert(uri: string, valuesBuckets: Array): Promise\ -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** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -629,6 +598,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel | valuesBucket | Array | Yes | Data record to insert. | **Return value** + | Type | Description | | ---------------- | ---------------------- | | Promise\ | Promise used to return the number of inserted data records.| @@ -651,15 +621,13 @@ DAHelper.batchInsert( }); ``` -### delete +## DataAbilityHelper.delete delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\): 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** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -686,15 +654,13 @@ DAHelper.delete( }); ``` -### delete +## DataAbilityHelper.delete delete(uri: string, predicates: dataAbility.DataAbilityPredicates): Promise\ -Deletes one or more data records from the database. This method uses a promise to return the result. - -**System capabilities** +Deletes one or more data records from the database. This API uses a promise to return the result. -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -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**.| **Return value** + | Type | Description | | ---------------- | ------------------------ | | Promise\ | Promise used to return the number of deleted data records.| @@ -724,15 +691,13 @@ DAHelper.delete( }); ``` -### update +## DataAbilityHelper.update update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\): 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** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -767,15 +732,13 @@ DAHelper.update( }); ``` -### update +## DataAbilityHelper.update update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates): Promise\ -Updates data records in the database. This method uses a promise to return the result. - -**System capabilities** +Updates data records in the database. This API uses a promise to return the result. -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -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**.| **Return value** + | Type | Description | | ---------------- | -------------------------------------------- | -| Promise\ | Promise used to return the number of updated data records.| +| Promise\ | Promise used to return the number of updated data records. | **Example** @@ -814,15 +778,13 @@ DAHelper.update( }); ``` -### query +## DataAbilityHelper.query query(uri: string, columns: Array\, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\): void -Queries data in the database. This method uses a callback to return the result. - -**System capabilities** +Queries data in the database. This API uses an asynchronous callback to return the result. -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -854,15 +816,13 @@ DAHelper.query( -### query +## DataAbilityHelper.query query(uri: string, columns: Array\, predicates: dataAbility.DataAbilityPredicates): Promise\ -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** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -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**.| **Return value** + | Type | Description | | ------------------- | -------------- | | Promise\ | Promise used to return the data queried.| @@ -895,3 +856,77 @@ DAHelper.query( console.info("==========================>queryCallback=======================>"); }); ``` + +## DataAbilityHelper.call + +call(uri: string, method: string, arg: string, extras: PacMap): Promise + +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): 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\ \| null | Yes| Data stored in key-value pairs.| diff --git a/en/application-dev/reference/apis/js-apis-eventhub.md b/en/application-dev/reference/apis/js-apis-eventhub.md index 40f4b05797aa03b575743df830ef3ff9115bc50f..cee0f8f7bbfe663d548939e11193b18b1a55b6c2 100644 --- a/en/application-dev/reference/apis/js-apis-eventhub.md +++ b/en/application-dev/reference/apis/js-apis-eventhub.md @@ -10,11 +10,11 @@ Implements event subscription, unsubscription, and triggering. ## 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' export default class MainAbility extends Ability { onForeground() { @@ -24,25 +24,24 @@ export default class MainAbility extends Ability { ``` -## on +## EventHub.on on(event: string, callback: Function): void; 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.| | callback | Function | Yes| Callback invoked when the event is triggered.| -- Example +**Example** - ``` + ```js import Ability from '@ohos.application.Ability' export default class MainAbility extends Ability { @@ -63,25 +62,24 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## off +## EventHub.off 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.| | 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' export default class MainAbility extends Ability { @@ -102,25 +100,24 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## emit +## EventHub.emit emit(event: string, ...args: Object[]): void; 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.| | ...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' export default class MainAbility extends Ability { diff --git a/en/application-dev/reference/apis/js-apis-extension-context.md b/en/application-dev/reference/apis/js-apis-extension-context.md index 08f53266f7a09ada42632df73fb0f58e6966a070..5a9466444cd91cc39805c69028cd083fae8e4843 100644 --- a/en/application-dev/reference/apis/js-apis-extension-context.md +++ b/en/application-dev/reference/apis/js-apis-extension-context.md @@ -1,6 +1,6 @@ # 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. @@ -11,4 +11,4 @@ Implements the extension context. This module is inherited from **Context**. | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| +| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core | diff --git a/en/application-dev/reference/apis/js-apis-featureAbility.md b/en/application-dev/reference/apis/js-apis-featureAbility.md index b8097b7a49bff4ad39312a5b4f257e035d4e2649..9e4324677acf9b4643b8980c65f3a20796dc0930 100644 --- a/en/application-dev/reference/apis/js-apis-featureAbility.md +++ b/en/application-dev/reference/apis/js-apis-featureAbility.md @@ -1,5 +1,8 @@ # 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 APIs of the **FeatureAbility** module can be called only by Page abilities. @@ -16,9 +19,7 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\) Starts an ability. This method uses a callback to return the result. -**System capabilities** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -57,9 +58,7 @@ startAbility(parameter: StartAbilityParameter): Promise\ Starts an ability. This method uses a promise to return the result. -**System capabilities** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -91,15 +90,13 @@ featureAbility.startAbility( }); ``` -## featureAbility.acquireDataAbilityHelper +## featureAbility.acquireDataAbilityHelper7+ acquireDataAbilityHelper(uri: string): DataAbilityHelper Obtains a **dataAbilityHelper** object. -**System capabilities** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -122,15 +119,13 @@ featureAbility.acquireDataAbilityHelper( ) ``` -## featureAbility.startAbilityForResult +## featureAbility.startAbilityForResult7+ startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\): void Starts an ability. This method uses a callback to return the execution result when the ability is destroyed. -**System capabilities** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -161,15 +156,13 @@ featureAbility.startAbilityForResult( ) ``` -## featureAbility.startAbilityForResult +## featureAbility.startAbilityForResult7+ startAbilityForResult(parameter: StartAbilityParameter): Promise\ Starts an ability. This method uses a promise to return the execution result when the ability is destroyed. -**System capabilities** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -178,6 +171,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel | parameter | [StartAbilityParameter](#startabilityparameter) | Yes | Ability to start.| **Return value** + | Type | Description | | ----------------------------------------- | -------------- | | Promise\<[AbilityResult](#abilityresult)> | Promised returned with the execution result.| @@ -218,15 +212,13 @@ featureAbility.startAbilityForResult( }); ``` -## featureAbility.terminateSelfWithResult +## featureAbility.terminateSelfWithResult7+ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\): void 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** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -268,15 +260,13 @@ featureAbility.terminateSelfWithResult( ); ``` -## featureAbility.terminateSelfWithResult +## featureAbility.terminateSelfWithResult7+ terminateSelfWithResult(parameter: AbilityResult): Promise\ 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** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -285,6 +275,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel | parameter | [AbilityResult](#abilityresult) | Yes | Ability to start.| **Return value** + | Type | Description | | -------------- | ----------------------- | | Promise\ | Promise used to return the result.| @@ -326,15 +317,13 @@ featureAbility.terminateSelfWithResult( -## featureAbility.hasWindowFocus +## featureAbility.hasWindowFocus7+ hasWindowFocus(callback: AsyncCallback\): void Checks whether the main window of this ability has the focus. This method uses a callback to return the result. -**System capabilities** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -351,15 +340,13 @@ featureAbility.hasWindowFocus() -## featureAbility.hasWindowFocus +## featureAbility.hasWindowFocus7+ hasWindowFocus(): Promise\ Checks whether the main window of this ability has the focus. This method uses a promise to return the result. -**System capabilities** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Return value** @@ -384,9 +371,7 @@ getWant(callback: AsyncCallback\): void Obtains the **Want** object sent from this ability. This method uses a callback to return the result. -**System capabilities** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -409,11 +394,10 @@ getWant(): Promise\ Obtains the **Want** object sent from this ability. This method uses a promise to return the result. -**System capabilities** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Return value** + | Type | Description | | ----------------------- | ------------------------- | | Promise\<[Want](#want)> | Promise used to return the result.| @@ -433,11 +417,10 @@ getContext(): Context Obtains the application context. -**System capabilities** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Return value** + | Type | Description | | ------- | -------------------- | | Context | Application context returned.| @@ -452,15 +435,13 @@ context.getBundleName() -## featureAbility.terminateSelf +## featureAbility.terminateSelf7+ terminateSelf(callback: AsyncCallback\): void 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** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -477,17 +458,16 @@ featureAbility.terminateSelf() -## featureAbility.terminateSelf +## featureAbility.terminateSelf7+ terminateSelf(): Promise\ 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** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Return value** + | Type | Description | | -------------- | ------------------------- | | Promise\ | Promise used to return the result.| @@ -500,15 +480,13 @@ featureAbility.terminateSelf().then((data) => { console.info("============= }); ``` -## featureAbility.connectAbility +## featureAbility.connectAbility7+ connectAbility(request: Want, options:ConnectOptions): number Connects this ability to a specific Service ability. This method uses a callback to return the result. -**System capabilities** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -519,21 +497,26 @@ SystemCapability.Ability.AbilityRuntime.FAModel Want +**System capability**: SystemCapability.Ability.AbilityBase + | 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.
System capabilities: SystemCapability.Ability.AbilityBase| -| bundleName | Read-only | string | Yes | Bundle name of the Service ability to connect.
System capabilities: SystemCapability.Ability.AbilityBase | -| abilityName | Read-only | string | Yes | Class name of the Service ability to connect.
System capabilities: 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. | +| abilityName | Read-only | string | Yes | Class name of the Service ability to connect. | ConnectOptions +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + | Name | Readable/Writable| Type | Mandatory| Description | | ------------ | -------- | -------- | ---- | ---------------------------------- | -| onConnect | Read-only | function | Yes | Callback invoked when the connection is successful.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core | -| onDisconnect | Read-only | function | Yes | Callback invoked when the connection fails.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core | -| onFailed | Read-only | function | Yes | Callback invoked when **connectAbility** fails to be called.
System capabilities: 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. | +| onFailed | Read-only | function | Yes | Callback invoked when **connectAbility** fails to be called.| **Return value** + | Type | Description | | ------ | ------------------------ | | number | Returns the ID of the Service ability connected.| @@ -566,15 +549,13 @@ var connId = featureAbility.connectAbility( ); ``` -## featureAbility.disconnectAbility +## featureAbility.disconnectAbility7+ disconnectAbility(connection: number, callback:AsyncCallback\): void Disconnects this ability from a specific Service ability. This method uses a callback to return the result. -**System capabilities** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -615,15 +596,13 @@ var result = featureAbility.disconnectAbility(connId, ); ``` -## featureAbility.disconnectAbility +## featureAbility.disconnectAbility7+ disconnectAbility(connection: number): Promise\ Disconnects this ability from a specific Service ability. This method uses a promise to return the result. -**System capabilities** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -632,6 +611,7 @@ SystemCapability.Ability.AbilityRuntime.FAModel | connection | number | Yes | ID of the Service ability to disconnect.| **Return value** + | Type | Description | | -------------- | ----------------------- | | Promise\ | Promise used to return the result.| @@ -661,54 +641,176 @@ var connId = featureAbility.connectAbility( onFailed: onFailedCallback, }, ); -var result = await featureAbility.disconnectAbility(connId); + +featureAbility.disconnectAbility(connId).then((error,data)=>{ + console.log('featureAbilityTest result errCode : ' + error.code + " data: " + data); +}); ``` + +## featureAbility.getWindow7+ + +getWindow(callback: AsyncCallback\): 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\ | Yes | Callback used to return the window.| + +**Example** + +```javascript +GetWindow(){ + featureAbility.getWindow() + } +``` + +## featureAbility.getWindow7+ + +getWindow(): Promise\; + +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\ | 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_UNDEFINED7+ | 0 | The Page ability is in an undefined window display mode.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel | +| WINDOW_MODE_FULLSCREEN7+ | 1 | The Page ability is in full screen mode.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel | +| WINDOW_MODE_SPLIT_PRIMARY7+ | 100 | The Page ability is displayed in the primary window when it is in split-screen mode.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel| +| WINDOW_MODE_SPLIT_SECONDARY7+ | 101 | The Page ability is displayed in the secondary window when it is in split-screen mode.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel| +| WINDOW_MODE_FLOATING7+ | 102 | The Page ability is displayed in floating window mode.
**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_KEY7+ | "abilityBounds" | Ability window size.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel | +| WINDOW_MODE_KEY7+ | "windowMode" | Ability window display mode.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel | +| DISPLAY_ID_KEY7+ | "displayId" | Display device ID.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel| + +## ErrorCode + +Enumerates error codes. + +| Variable | Value | Description | +| ----------------------------- | ---- | ------------------------------------------------------------ | +| NO_ERROR7+ | 0 | No error occurs.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel| +| INVALID_PARAMETER7+ | -1 | Invalid parameter.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel| +| ABILITY_NOT_FOUND7+ | -2 | The ability is not found.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel| +| PERMISSION_DENY7+ | -3 | The request is denied.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel| + + +## DataAbilityOperationType + +Enumerates operation types of the Data ability. + +| Variable | Value | Description | +| ----------------------------- | ---- | ------------------------------------------------------------ | +| TYPE_INSERT7+ | 1 | Insert operation.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel| +| TYPE_UPDATE7+ | 2 | Update operation.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel| +| TYPE_DELETE7+ | 3 | Deletion operation.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel| +| TYPE_ASSERT7+ | 4 | Assert operation.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel| + + + ## AbilityResult +**System capability**: SystemCapability.Ability.AbilityBase + | 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.
System capabilities: SystemCapability.Ability.AbilityBase| -| 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**.
System capabilities: SystemCapability.Ability.AbilityBase | +| resultCode7+ | Read-only | number | Yes | Result code returned after the ability is destroyed. The feature for defining error-specific result codes is coming soon.| +| want7+ | 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 +**System capability**: SystemCapability.AbilityRuntime.FAModel + | Name | Readable/Writable| Type | Mandatory| Description | | ------------------- | -------- | -------------------- | ---- | ------------------------------------------------------------ | -| want | Read-only | [Want](#want) | Yes | Information about the ability to start.
System capabilities: 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.
System capabilities: 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.| + ## Want +**System capability**: SystemCapability.Ability.AbilityBase + | Name | Readable/Writable| Type | Mandatory| Description | | ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ | -| deviceId | Read-only | string | No | ID of the device that runs the ability.
System capabilities: 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.
System capabilities: 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.
System capabilities: 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**.
System capabilities: SystemCapability.Ability.AbilityBase| -| type | Read-only | string | No | MIME type, for example, text/plain or image/*.
System capabilities: SystemCapability.Ability.AbilityBase | -| flags | Read-only | number | No | How the **Want** object will be handled. By default, a number is passed. For details, see [flags](#flags).
System capabilities: SystemCapability.Ability.AbilityBase| -| action | Read-only | string | No | Action option.
System capabilities: SystemCapability.Ability.AbilityBase | -| parameters | Read-only | {[key: string]: any} | No | List of parameters in a **Want** object.
System capabilities: SystemCapability.Ability.AbilityBase | -| entities | Read-only | Array\ | No | List of entities.
System capabilities: SystemCapability.Ability.AbilityBase | +| deviceId8+ | Read-only | string | No | ID of the device that runs the ability. | +| bundleName8+ | 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.| +| abilityName8+ | 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.| +| uri8+ | 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**.| +| type8+ | Read-only | string | No | MIME type, for example, text/plain or image/*. | +| flags8+ | Read-only | number | No | How the **Want** object will be handled. By default, a number is passed. For details, see [flags](#flags).| +| action8+ | Read-only | string | No | Action option. | +| parameters8+ | Read-only | {[key: string]: any} | No | List of parameters in a **Want** object. | +| entities8+ | Read-only | Array\ | No | List of entities. | ## flags +**System capability**: SystemCapability.Ability.AbilityBase + | Name | Name | Description | | ------------------------------------ | ---------- | ------------------------------------------------------------ | -| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Indicates the permission to read the URI.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Indicates the permission to write the URI.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | Returns the result to the ability.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_ABILITY_CONTINUATION | 0x00000008 | Indicates whether the ability on the local device can be migrated to a remote device.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_NOT_OHOS_COMPONENT | 0x00000010 | Indicates that a component does not belong to OHOS.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | Indicates whether to enable an ability.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Indicates the permission to make the URI persistent.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | Indicates the permission to verify URIs by prefix matching.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | Supports cross-device startup in a distributed scheduler.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | Indicates that the Service ability is started regardless of whether the host application has been started.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that the migration is reversible.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_INSTALL_ON_DEMAND | 0x00000800 | Indicates that the specific ability will be installed if it has not been installed.
System capabilities: 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.
System capabilities: 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**.
System capabilities: SystemCapability.Ability.AbilityBase| -| FLAG_ABILITY_NEW_MISSION | 0x10000000 | Creates a mission on the historical mission stack.
System capabilities: 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.
System capabilities: 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. | +| 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. | +| 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. | +| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Indicates the permission to make the URI persistent. | +| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | Indicates the permission to verify URIs by prefix matching. | +| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | Supports cross-device startup in a distributed scheduler. | +| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | Indicates that the Service ability is started regardless of whether the host application has been started. | +| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that the migration is reversible. | +| FLAG_INSTALL_ON_DEMAND | 0x00000800 | Indicates that the specific ability will be installed if it has not been installed. | +| FLAG_INSTALL_WITH_BACKGROUND_MODE | 0x80000000 | Indicates that the specific ability will be installed in the background if it has not been installed. | +| FLAG_ABILITY_CLEAR_MISSION | 0x00008000 | Clears other operation missions. This flag can be set for the **Want** object 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. | +| FLAG_ABILITY_MISSION_TOP | 0x20000000 | Starts the mission on the top of the existing mission stack; creates an ability instance if no mission exists.| diff --git a/en/application-dev/reference/apis/js-apis-formbindingdata.md b/en/application-dev/reference/apis/js-apis-formbindingdata.md index cf59cffd6eaf7cdd36176d0a8426627a7dd3620c..54470f52311e717a64d6ce1a98f5f427d557913c 100644 --- a/en/application-dev/reference/apis/js-apis-formbindingdata.md +++ b/en/application-dev/reference/apis/js-apis-formbindingdata.md @@ -1,6 +1,6 @@ # 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. ## Modules to Import @@ -19,33 +19,39 @@ createFormBindingData(obj?: Object | string): FormBindingData Creates a **FormBindingData** object. -- Parameters +**System capability**: SystemCapability.Ability.Form - | 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.| +**Parameters** +| 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| - | ----------------------------------- | --------------------------------------- | - | [FormBindingData](#formbindingdata) | **FormBindingData** object created based on the passed data.| +| Type | Description | +| ----------------------------------- | --------------------------------------- | +| [FormBindingData](#formbindingdata) | **FormBindingData** object created based on the passed data.| +**Example** -- Example - - ``` + ```js let obj = {"temperature": "21°"}; let formBindingDataObj = formBindingData.createFormBindingData(obj); ``` -## FormBindingData +## formBindingData.FormBindingData + +data: 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.| diff --git a/en/application-dev/reference/apis/js-apis-formextension.md b/en/application-dev/reference/apis/js-apis-formextension.md index ee3e0f92b41b9edc4d28eab38dc63c4722119230..a96feb9ef29393127bc1916a9a4a13ea7eba1817 100644 --- a/en/application-dev/reference/apis/js-apis-formextension.md +++ b/en/application-dev/reference/apis/js-apis-formextension.md @@ -1,7 +1,7 @@ # FormExtension > ![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. @@ -17,9 +17,9 @@ None ## 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**.
**System capability**: SystemCapability.Ability.Form| ## onCreate @@ -27,21 +27,23 @@ onCreate(want: Want): formBindingData.FormBindingData 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.| -- Example +**Example** - ``` + ```js export default class MyFormExtension extends FormExtension { onCreate(want) { console.log('FormExtension onCreate, want:' + want.abilityName); @@ -55,19 +57,21 @@ Called to notify the widget provider that a **Form** instance (widget) has been } ``` -## onCastToNormal +## FormExtension.onCastToNormal onCastToNormal(formId: string): void 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 { @@ -77,21 +81,23 @@ Called to notify the widget provider that a temporary widget has been converted } ``` -## onUpdate +## FormExtension.onUpdate 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. -- 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 { onUpdate(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 } ``` -## onVisibilityChange +## FormExtension.onVisibilityChange onVisibilityChange(newStatus: { [key: string]: number }): void 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 { onVisibilityChange(newStatus) { console.log('FormExtension onVisibilityChange, newStatus:' + newStatus); @@ -137,22 +145,24 @@ Called to notify the widget provider of the change of visibility. } ``` -## onEvent +## FormExtension.onEvent onEvent(formId: string, message: string): void 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.| - | message | string | Yes| Event message.| + | formId | string | Yes | ID of the widget that requests the event.| + | message | string | Yes | Event message. | -- Example +**Example** - ``` + ```js export default class MyFormExtension extends FormExtension { onEvent(formId, 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. } ``` -## onDestroy +## FormExtension.onDestroy onDestroy(formId: string): void 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 { onDestroy(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)); + } + } + ``` diff --git a/en/application-dev/reference/apis/js-apis-formextensioncontext.md b/en/application-dev/reference/apis/js-apis-formextensioncontext.md index b4cf3bca0a580270658be8d19ce0fd4a7cf3b403..faa3bd6c6f82018ca61c9ba1f008dbc1e72dae9f 100644 --- a/en/application-dev/reference/apis/js-apis-formextensioncontext.md +++ b/en/application-dev/reference/apis/js-apis-formextensioncontext.md @@ -1,53 +1,57 @@ # 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. 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 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.| - | formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes| New data of the widget.| - | callback | AsyncCallback\ | Yes| Callback used to return the result indicating whether the method is successfully called.| + | formId | string | Yes | ID of the widget that requests to be updated. | + | formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes | New data of the widget. | + | callback | AsyncCallback\ | 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"}); this.context.updateForm(formId, obj2, (data)=>{ console.log('FormExtension context updateForm, data:' + data); }); ``` -## updateForm +## FormExtensionContext.updateForm updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Promise\ 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.| - | formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes| New data of the widget.| + | 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. | -- Return value +**Return value** - | Type| Description| + | Type | Description | | -------------- | --------------------------------- | | Promise\ | Promise returned with the result indicating whether the method is successfully called.| -- Example +**Example** ``` let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"}); diff --git a/en/application-dev/reference/apis/js-apis-particleAbility.md b/en/application-dev/reference/apis/js-apis-particleAbility.md index 84d4281dd8e8c1faa843cd92856f75c54d5d5d50..6fd96f25e11de096e58c69c98706febbbde9af95 100644 --- a/en/application-dev/reference/apis/js-apis-particleAbility.md +++ b/en/application-dev/reference/apis/js-apis-particleAbility.md @@ -1,5 +1,8 @@ # 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 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' ## particleAbility.startAbility -startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\: void - -Starts a particle ability. This method uses a callback to return the result. +startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\): void -**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** @@ -57,16 +58,11 @@ particleAbility.startAbility( ## particleAbility.startAbility -**System capabilities** - -SystemCapability.Ability.AbilityRuntime.FAModel +startAbility(parameter: StartAbilityParameter): Promise; -startAbility(parameter: StartAbilityParameter): Promise\ -Starts a particle ability. This method uses a promise to return the result. +Starts a particle ability. This API uses a promise to return the result. -**System capabilities** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -74,7 +70,9 @@ SystemCapability.Ability.AbilityRuntime.FAModel | Name | Type | Mandatory| Description | | --------- | ----------------------------------------------- | ---- | ----------------- | | parameter | [StartAbilityParameter](#startabilityparameter) | Yes | Ability to start.| + **Return value** + | Type | Description | | -------------- | ------------------------- | | Promise\ | Promise used to return the result.| @@ -109,11 +107,9 @@ particleAbility.startAbility( terminateSelf(callback: AsyncCallback\): 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** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -138,13 +134,12 @@ particleAbility.terminateSelf( terminateSelf(): Promise\ -Terminates this particle ability. This method uses a promise to return the result. - -**System capabilities** +Terminates this particle ability. This API uses a promise to return the result. -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Return value** + | Type | Description | | -------------- | ------------------------- | | Promise\ | Promise used to return the result.| @@ -166,9 +161,7 @@ acquireDataAbilityHelper(uri: string): DataAbilityHelper Obtains a **dataAbilityHelper** object. -**System capabilities** - -SystemCapability.Ability.AbilityRuntime.FAModel +**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel **Parameters** @@ -190,91 +183,25 @@ var uri = ""; particleAbility.acquireDataAbilityHelper(uri) ``` -## StartAbilityParameter - -| Name | Readable/Writable| Type | Mandatory| Description | -| ------------------- | -------- | --------------------- | ---- | ------------------------------------------------------------ | -| want | Read-only | [Want](#want) | Yes | Information about the ability to start.
System capabilities: 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.
System capabilities: 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.
System capabilities: 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.
System capabilities: 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.
System capabilities: 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**.
System capabilities: SystemCapability.Ability.AbilityBase| -| type | Read-only | string | No | MIME type, for example, **text/plain** or **image/***.
System capabilities: 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).
System capabilities: SystemCapability.Ability.AbilityBase| -| action | Read-only | string | No | Action option.
System capabilities: SystemCapability.Ability.AbilityBase | -| parameters | Read-only | {[key: string]: any} | No | List of parameters in the **Want** object.
System capabilities: SystemCapability.Ability.AbilityBase | -| entities | Read-only | Array\ | No | List of entities.
System capabilities: SystemCapability.Ability.AbilityBase | - -## flags - -| Name | Value | Description | -| ------------------------------------ | ---------- | ------------------------------------------------------------ | -| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Indicates the permission to read the URI.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Indicates the permission to write the URI.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | Returns the result to the ability.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_ABILITY_CONTINUATION | 0x00000008 | Indicates whether the ability on the local device can be migrated to a remote device.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_NOT_OHOS_COMPONENT | 0x00000010 | Indicates that a component does not belong to OHOS.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | Indicates whether to enable an ability.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Indicates the permission to make the URI persistent.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | Indicates the permission to verify URIs by prefix matching.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | Supports cross-device startup in a distributed scheduler.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | Indicates that the Service ability is started regardless of whether the host application has been started.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that the migration is reversible.
System capabilities: SystemCapability.Ability.AbilityBase | -| FLAG_INSTALL_ON_DEMAND | 0x00000800 | Indicates that the specific ability will be installed if it has not been installed.
System capabilities: 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.
System capabilities: 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**.
System capabilities: SystemCapability.Ability.AbilityBase| -| FLAG_ABILITY_NEW_MISSION | 0x10000000 | Creates a mission on the historical mission stack.
System capabilities: 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.
System capabilities: 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.
System capabilities: SystemCapability.Ability.AbilityRuntime.FAModel | -| WINDOW_MODE_KEY | "windowMode" | Ability window display mode.
System capabilities: SystemCapability.Ability.AbilityRuntime.FAModel | -| DISPLAY_ID_KEY | "displayId" | Display device ID.
System capabilities: 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.
System capabilities: SystemCapability.Ability.AbilityRuntime.FAModel | -| WINDOW_MODE_FULLSCREEN | 1 | The Page ability is in full screen mode.
System capabilities: 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.
System capabilities: 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.
System capabilities: SystemCapability.Ability.AbilityRuntime.FAModel| -| WINDOW_MODE_FLOATING | 102 | The Page ability is displayed in floating window mode.
System capabilities: SystemCapability.Ability.AbilityRuntime.FAModel | - ## particleAbility.startBackgroundRunning startBackgroundRunning(id: number, request: NotificationRequest, callback: AsyncCallback<void>): 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| | -------- | -------- | -------- | -------- | | id | number | Yes| Notification ID of a continuous task.| | request | NotificationRequest | Yes| Notification parameter, which is used to display information in the notification bar.| - | callback | AsyncCallback<void> | Yes| Callback used to return the execution result.| + | callback | AsyncCallback<void> | Yes| Callback used to return the result.| + + **Example** -- **Example** ```js import notification from '@ohos.notification'; import particleAbility from '@ohos.ability.particleAbility'; @@ -323,24 +250,25 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { startBackgroundRunning(id: number, request: NotificationRequest): Promise<void> -**System capabilities** - -SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask +**System capability**: 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** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | id | number | Yes| Notification ID of a continuous task.| | request | NotificationRequest | Yes| Notification parameter, which is used to display information in the notification bar.| **Return value** + | Type | Description | | -------------- | ------------------------- | | Promise\ | Promise used to return the result.| -- **Example** +**Example** + ```js import notification from '@ohos.notification'; import particleAbility from '@ohos.ability.particleAbility'; @@ -385,18 +313,18 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { cancelBackgroundRunning(callback: AsyncCallback<void>): 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| | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | Yes| Callback used to return the execution result.| + | callback | AsyncCallback<void> | Yes| Callback used to return the result.| + + **Example** -- **Example** ```js import particleAbility from '@ohos.ability.particleAbility'; @@ -416,18 +344,18 @@ particleAbility.cancelBackgroundRunning(callback); cancelBackgroundRunning(): Promise<void>; -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.) - -**System capabilities** +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.) -SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask +**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask **Return value** + | Type | Description | | -------------- | ------------------------- | | Promise\ | Promise used to return the result.| -- **Example** + **Example** + ```js import particleAbility from '@ohos.ability.particleAbility'; @@ -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; + +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<void> | 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; + +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\ | 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.
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel| + + + + + diff --git a/en/application-dev/reference/apis/js-apis-permissionrequestresult.md b/en/application-dev/reference/apis/js-apis-permissionrequestresult.md index 413bd6246b8ada2a2a0d64d66e5897090ec6d80c..20f6b7859945481356f504b2bc8b64b41cdd58ff 100644 --- a/en/application-dev/reference/apis/js-apis-permissionrequestresult.md +++ b/en/application-dev/reference/apis/js-apis-permissionrequestresult.md @@ -9,7 +9,9 @@ Provides the permission request result. ## Attributes +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| permissions | Array<string> | Yes| No| Permissions requested.
System capability: SystemCapability.Ability.AbilityRuntime.Core| -| authResults | Array<number> | 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.
System capability: SystemCapability.Ability.AbilityRuntime.Core| +| permissions | Array<string> | Yes| No| Permissions requested.| +| authResults | Array<number> | 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. | diff --git a/en/application-dev/reference/apis/js-apis-processrunninginfo.md b/en/application-dev/reference/apis/js-apis-processrunninginfo.md index 5f1e7c420e7402bbc6c8b631c16c05b527710edf..5306bc6697e98fd3f749953a795077dd5d02a2ec 100644 --- a/en/application-dev/reference/apis/js-apis-processrunninginfo.md +++ b/en/application-dev/reference/apis/js-apis-processrunninginfo.md @@ -14,7 +14,7 @@ The process running information is obtained through an **appManager** instance. -``` +```js import appManager from '@ohos.application.appManager'; appManager.getProcessRunningInfos((error,data) => { console.log("getProcessRunningInfos error: " + error.code + " data: " + JSON.stringify(data)); @@ -24,9 +24,11 @@ appManager.getProcessRunningInfos((error,data) => { ## Attributes +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| pid | number | Yes| No| Process ID.
System capability: SystemCapability.Ability.AbilityRuntime.Core| -| uid | number | Yes| No| User ID.
System capability: SystemCapability.Ability.AbilityRuntime.Core| -| processName | string | Yes| No| Process name.
System capability: SystemCapability.Ability.AbilityRuntime.Core| -| bundleNames | Array<string> | Yes| No| Names of all bundles running in the process.
System capability: SystemCapability.Ability.AbilityRuntime.Core| +| pid | number | Yes| No| Process ID.| +| uid | number | Yes| No| User ID.| +| processName | string | Yes| No| Process name.| +| bundleNames | Array<string> | Yes| No| Names of all bundles running in the process.| diff --git a/en/application-dev/reference/apis/js-apis-service-extension-context.md b/en/application-dev/reference/apis/js-apis-service-extension-context.md index 1c1d2b615a5b9344fab4247aa3b3e84b963c3a0b..ce5ab6b95a4e75fc5a5aa65ae37f75cdd0e0587c 100644 --- a/en/application-dev/reference/apis/js-apis-service-extension-context.md +++ b/en/application-dev/reference/apis/js-apis-service-extension-context.md @@ -9,25 +9,22 @@ Implements the context that provides the capabilities and APIs of **ServiceExten ## startAbility - startAbility(want: Want, callback: AsyncCallback<void>): 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 capabilities** +**System capability**: SystemCapability.Ability.AbilityRuntime.Core -SystemCapability.Ability.AbilityRuntime.Core +**Parameters** -- 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.| - | callback | AsyncCallback<void> | No| Callback used to return the result indicating whether the method is successfully called.| + | callback | AsyncCallback<void> | No| Callback used to return the result indicating whether the API is successfully called.| -- Example - ``` +**Example** + + ```js let want = { "bundleName": "com.example.myapp", "abilityName": "com.example.myapp.MyAbility" @@ -38,28 +35,29 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## startAbility +## ServiceExtensionContext.startAbility startAbility(want: Want): Promise<void>; -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| | -------- | -------- | -------- | -------- | | 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| | -------- | -------- | - | Promise<void> | Promise used to return the result indicating whether the method is successfully called.| + | Promise<void> | Promise used to return the result indicating whether the API is successfully called.| -- Example - ``` +**Example** + + ```js let want = { "bundleName": "com.example.myapp", "abilityName": "com.example.myapp.MyAbility" @@ -72,46 +70,46 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## terminateSelf +## ServiceExtensionContext.terminateSelf terminateSelf(callback: AsyncCallback<void>): 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| | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | No| Callback used to return the result indicating whether the method is successfully called.| + | callback | AsyncCallback<void> | No| Callback used to return the result indicating whether the API is successfully called.| -- Example - ``` +**Example** + + ```js this.context.terminateSelf((err) => { console.log('terminateSelf result:' + JSON.stringfy(err)); }); ``` -## terminateSelf +## ServiceExtensionContext.terminateSelf terminateSelf(): Promise<void>; -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| | -------- | -------- | - | Promise<void> | Promise used to return the result indicating whether the method is successfully called.| + | Promise<void> | Promise used to return the result indicating whether the API is successfully called.| -- Example - ``` +**Example** + + ```js this.context.terminateSelf(want).then((data) => { console.log('success:' + JSON.stringfy(data)); }).catch((error) => { @@ -120,29 +118,30 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## connectAbility +## ServiceExtensionContext.connectAbility connectAbility(want: Want, options: ConnectOptions): number; 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| | -------- | -------- | -------- | -------- | | 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.| -- Return value +**Return value** + | Type| Description| | -------- | -------- | | number | A number, based on which the connection will be interrupted.| -- Example - ``` +**Example** + + ```js let want = { "bundleName": "com.example.myapp", "abilityName": "com.example.myapp.MyAbility" @@ -156,52 +155,53 @@ SystemCapability.Ability.AbilityRuntime.Core ``` -## disconnectAbility +## ServiceExtensionContext.disconnectAbility disconnectAbility(connection: number, callback:AsyncCallback<void>): 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| | -------- | -------- | -------- | -------- | | connection | number | Yes| Number returned after **connectAbility** is called.| - | callback | AsyncCallback<void> | No| Callback used to return the result indicating whether the method is successfully called.| + | callback | AsyncCallback<void> | 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. console.log('terminateSelf result:' + JSON.stringfy(err)); }); ``` -## disconnectAbility +## ServiceExtensionContext.disconnectAbility disconnectAbility(connection: number): Promise<void>; -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| | -------- | -------- | -------- | -------- | | connection | number | Yes| Number returned after **connectAbility** is called.| -- Return value +**Return value** + | Type| Description| | -------- | -------- | - | Promise<void> | Promise used to return the result indicating whether the method is successfully called.| + | Promise<void> | Promise used to return the result indicating whether the API is successfully called.| -- Example - ``` +**Example** + + ```js this.context.disconnectAbility(connection).then((data) => { // connection is the return value of connectAbility. console.log('success:' + JSON.stringfy(data)); }).catch((error) => { @@ -214,8 +214,10 @@ SystemCapability.Ability.AbilityRuntime.Core Defines the **ConnectOptions** data structure. +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + | Name| Description| | -------- | -------- | -| onConnect(elementName:ElementName, remote:IRemoteObject) | Called when this ability is connected to a Service ability.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| -| onDisconnect(elementName:ElementName) | Called when the peer service is abnormal or killed.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| -| onFailed(code: number) | Called when the connection fails.
System capabilities: SystemCapability.Ability.AbilityRuntime.Core| +| onConnect(elementName:ElementName, remote:IRemoteObject) | Called when this ability is connected to a Service ability.| +| onDisconnect(elementName:ElementName) | Called when the peer service is abnormal or killed.| +| onFailed(code: number) | Called when the connection fails.| diff --git a/en/application-dev/reference/apis/js-apis-service-extension.md b/en/application-dev/reference/apis/js-apis-service-extension.md index 0a6b357e97fad6ee1474e6925067361d78e0c6a1..76b55db35209bcf3b6bcbfc97f3d7d974dc05db2 100644 --- a/en/application-dev/reference/apis/js-apis-service-extension.md +++ b/en/application-dev/reference/apis/js-apis-service-extension.md @@ -23,7 +23,7 @@ None | 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**.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core| ## onCreate @@ -32,17 +32,17 @@ onCreate(want: Want): void; 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| | -------- | -------- | -------- | -------- | | 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 { onCreate(want) { console.log('onCreate, want:' + want.abilityName); @@ -57,12 +57,11 @@ onDestroy(): void; 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 { onDestroy() { console.log('onDestroy'); @@ -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. -**System capabilities** +**System capability**: SystemCapability.Ability.AbilityRuntime.Core -SystemCapability.Ability.AbilityRuntime.Core +**Parameters** -- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | 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.| -- Example - ``` +**Example** + + ```js class ServiceExt extends ServiceExtension { onRequest(want, startId) { console.log('onRequest, want:' + want.abilityName); @@ -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. -**System capabilities** +**System capability**: SystemCapability.Ability.AbilityRuntime.Core -SystemCapability.Ability.AbilityRuntime.Core +**Parameters** -- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | 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| | -------- | -------- | | rpc.RemoteObject | A **RemoteObject** object used for communication with the client.| -- Example - ``` +**Example** + + ```js import rpc from '@ohos.rpc' class StubTest extends rpc.RemoteObject{ constructor(des) { @@ -142,17 +142,17 @@ onDisconnect(want: Want): void; Called when the ability is disconnected. -**System capabilities** +**System capability**: SystemCapability.Ability.AbilityRuntime.Core -SystemCapability.Ability.AbilityRuntime.Core +**Parameters** -- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | 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 { onDisconnect(want) { console.log('onDisconnect, want:' + want.abilityName);