From ea72980dda1975700e3b8278f721031bd4781d40 Mon Sep 17 00:00:00 2001 From: wusongqing Date: Mon, 14 Feb 2022 10:41:20 +0800 Subject: [PATCH] updated docs Signed-off-by: wusongqing --- .../reference/apis/js-apis-Context.md | 408 ++++----- .../reference/apis/js-apis-DataUriUtils.md | 96 +-- .../reference/apis/js-apis-commonEvent.md | 780 +++++++++--------- .../reference/apis/js-apis-display.md | 519 +++--------- .../reference/apis/js-apis-faultLogger.md | 16 +- .../reference/apis/js-apis-featureAbility.md | 378 ++++----- .../reference/apis/js-apis-particleAbility.md | 176 ++-- .../reference/apis/js-apis-featureAbility.md | 6 +- .../reference/apis/js-apis-particleAbility.md | 4 +- 9 files changed, 1003 insertions(+), 1380 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-Context.md b/en/application-dev/reference/apis/js-apis-Context.md index ad42e566a0..c17e88f3d9 100644 --- a/en/application-dev/reference/apis/js-apis-Context.md +++ b/en/application-dev/reference/apis/js-apis-Context.md @@ -15,24 +15,24 @@ var context = featureAbility.getContext(); context.getOrCreateLocalDir() ``` -## Context.getOrCreateLocalDir(callback: AsyncCallback) +## Context -- Functionality +### getOrCreateLocalDir - Obtains the local root directory of the application. If this method is called for the first time, a root directory is created. This method uses a callback to return the result. +getOrCreateLocalDir(callback: AsyncCallback\): void -- Parameters +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. -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | ---------------------- | ---- | ------------------------ | -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the local root directory of the application.| +**Parameters** -- Return values - void +| Name| Type| Mandatory| Description| +| -------- | ---------------------- | ---- | -------------------------- | +| callback | AsyncCallback\ | Yes| Callback used to return the local root directory of the application.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -44,23 +44,21 @@ context.getOrCreateLocalDir((err, data)=>{ -## Context.getOrCreateLocalDir() - -- Functionality +### getOrCreateLocalDir - Obtains the local root directory of the application. If this method is called for the first time, a root directory is created. This method uses a promise to return the result. +getOrCreateLocalDir(): Promise\ -- Parameters +Obtains the local root directory of the application. This method uses a promise to return the result. - None +If this method is called for the first time, a root directory is created. -- Return values +**Return value** - | Type| Description| - | --------------- | -------------------- | - | Promise | Promise used to return the local root directory of the application.| +| Type| Description| +| ---------------- | ---------------------- | +| Promise\ | Promise returned with the local root directory of the application.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -70,33 +68,24 @@ context.getOrCreateLocalDir().then((void) => { }); ``` -## PermissionOptions -| Name| Readable/Writable| Type| Mandatory| Description| -| ---- | -------- | ------ | ---- | ------ | -| pid | Read-only| number | No| PID.| -| uid | Read-only| number | No| UID.| -## Context.verifyPermission(permission: string, options: PermissionOptions, callback: AsyncCallback) +### verifyPermission -- Functionality +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. +Verifies whether a specific PID and UID have the given permission. This method uses a callback to return the result. -- Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| ---------- | -------- | ----------------------------------------------- | ---- | ----------------------------------- | -| permission | Read-only| string | Yes| Name of the permission to verify.| -| options | Read-only| [PermissionOptions](#PermissionOptions)| Yes| Permission options.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.| - -- Return values +| Name| Type| Mandatory| Description| +| ---------- | --------------------------------------- | ---- | ------------------------------------- | +| permission | string | Yes| Name of the permission to verify.| +| options | [PermissionOptions](#permissionoptions) | Yes| Permission options.| +| callback | AsyncCallback\ | Yes| Callback used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.| - void - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -109,25 +98,21 @@ context.verifyPermission("com.example.permission",datainfo.uid) -## Context.verifyPermission(permission: string, callback: AsyncCallback) - -- Functionality +### verifyPermission - Verifies whether the current PID and UID have the given permission. This method uses a callback to return the result. +verifyPermission(permission: string, callback: AsyncCallback\): void -- Parameters +Verifies whether the current PID and UID have the given permission. This method uses a callback to return the result. +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| ---------- | -------- | ---------------------- | ---- | ----------------------------------- | -| permission | Read-only| string | Yes| Name of the permission to verify.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.| - -- Return values - void +| Name| Type| Mandatory| Description| +| ---------- | ---------------------- | ---- | ------------------------------------- | +| permission | string | Yes| Name of the permission to verify.| +| callback | AsyncCallback\ | Yes| Callback used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -135,29 +120,27 @@ var context = featureAbility.getContext(); context.verifyPermission("com.example.permission") ``` +### verifyPermission +verifyPermission(permission: string, options?: PermissionOptions): Promise\ -## Context.verifyPermission(permission: string, options?: PermissionOptions) +Verifies whether a specific PID and UID have the given permission. This method uses a promise to return the result. -- Functionality +**Parameters** - Verifies whether a specific PID and UID have the given permission. This method uses a promise to return the result. -- Parameters +| Name| Type| Mandatory| Description| +| ---------- | --------------------------------------- | ---- | ---------------- | +| permission | string | Yes| Name of the permission to verify.| +| options | [PermissionOptions](#permissionoptions) | No| Permission options.| +**Return value** -| Name| Readable/Writable| Type| Mandatory| Description| -| ---------- | -------- | ----------------------------------------------- | ---- | -------------- | -| permission | Read-only| string | Yes| Name of the permission to verify.| -| options | Read-only| [PermissionOptions](#PermissionOptions)| No| Permission options.| - -- Return values +| Type| Description| +| ---------------- | ----------------------------------------------------------- | +| Promise\ | Promise used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.| - | Type| Description| - | --------------- | ------------------------------------------------------------ | - | Promise | Promise used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.| - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -168,35 +151,23 @@ context.getOrCreateLocalDir('com.context.permission',Permission).then((void) => }); ``` -## PermissionRequestResult -| Name| Readable/Writable| Type| Mandatory| Description| -| ----------- | -------- | -------------- | ---- | ------------------ | -| requestCode | Read-only| number | Yes| Request code passed.| -| permissions | Read-only| Array\ | Yes| Permissions passed.| -| authResults | Read-only| Array\ | Yes| Permission request result.| - - - -## Context.requestPermissionsFromUser(permissions: Array, requestCode: number, resultCallback: AsyncCallback<[PermissionRequestResult](#PermissionRequestResult)>) -- Functionality +### requestPermissionsFromUser - Requests certain permissions from the system. This method uses a callback to return the result. +requestPermissionsFromUser(permissions: Array\, requestCode: number, resultCallback: AsyncCallback<[PermissionRequestResult](#permissionrequestresult)>) -- Parameters +Requests certain permissions from the system. This method uses a callback to return the result. +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| -------------- | -------- | ------------------------------------------------------------ | ---- | --------------------------------------------- | -| permissions | Read-only| Array\ | Yes| Permissions to request. This parameter cannot be **null**.| -| requestCode | Read-only| number | Yes| Request code to be passed to **PermissionRequestResult**.| -| resultCallback | Read-only| AsyncCallback\<[PermissionRequestResult](#PermissionRequestResult)> | Yes| Permission request result.| -- Return values - - void -- Example +| 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 import featureAbility from '@ohos.ability.featureAbility' @@ -213,23 +184,19 @@ context.getOrCreateLocalDir( -## Context.getApplicationInfo(callback: AsyncCallback) - -- Functionality - - Obtains information about the current application. This method uses a callback to return the result. +### getApplicationInfo -- Parameters +getApplicationInfo(callback: AsyncCallback\) - | Name| Readable/Writable| Type| Mandatory| Description| - | -------- | -------- | ------------------------------- | ---- | ---------------------- | - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the application information.| +Obtains information about the current application. This method uses a callback to return the result. -- Return values +**Parameters** - void +| Name| Type| Mandatory| Description| +| -------- | ------------------------------- | ---- | ------------------------ | +| callback | AsyncCallback\ | Yes| Callback used to return the application information.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -239,23 +206,19 @@ context.getApplicationInfo() -## Context.getApplicationInfo +### getApplicationInfo -- Functionality +getApplicationInfo(): Promise\ - Obtains information about the current application. This method uses a promise to return the result. +Obtains information about the current application. This method uses a promise to return the result. -- Parameters +**Return value** - None +| Type| Description| +| ------------------------- | ------------------ | +| Promise\ | Promise used to return the application information.| -- Return values - - | Type| Description| - | ------------------------ | ------------------ | - | Promise | Promise used to return the application information.| - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -267,23 +230,19 @@ context.getApplicationInfo().then((void) => { -## Context.getBundleName(callback: AsyncCallback) - -- Functionality - - Obtains the bundle name of the current ability. This method uses a callback to return the result. +### getBundleName -- Parameters +getBundleName(callback: AsyncCallback\): void - | Name| Readable/Writable| Type| Mandatory| Description| - | -------- | -------- | ---------------------- | ---- | --------------------------- | - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the bundle name.| +Obtains the bundle name of the current ability. This method uses a callback to return the result. -- Return values +**Parameters** - void +| Name| Type| Mandatory| Description| +| -------- | ---------------------- | ---- | ----------------------------- | +| callback | AsyncCallback\ | Yes| Callback used to return the bundle name.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -293,23 +252,19 @@ context.getBundleName() -## Context.getBundleName +### getBundleName -- Functionality +getBundleName(): Promise\ - Obtains the bundle name of the current ability. This method uses a promise to return the result. +Obtains the bundle name of the current ability. This method uses a promise to return the result. -- Parameters +**Return value** - None +| Type| Description| +| ---------------- | ------------------------- | +| Promise\ | Promise used to return the bundle name.| -- Return values - - | Type| Description| - | --------------- | ----------------------- | - | Promise | Promise used to return the bundle name.| - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -321,23 +276,19 @@ context.getBundleName().then((void) => { -## Context.getProcessInfo(callback: AsyncCallback) - -- Functionality +### getProcessInfo - Obtains information about the current process, including the PID and process name. This method uses a callback to return the result. +getProcessInfo(callback: AsyncCallback\) -- Parameters +Obtains information about the current process, including the PID and process name. This method uses a callback to return the result. - | Name| Readable/Writable| Type| Mandatory| Description| - | -------- | -------- | --------------------------- | ---- | ------------------ | - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the process information.| +**Parameters** -- Return values +| Name| Type| Mandatory| Description| +| -------- | --------------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes| Callback used to return the process information.| - void - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -347,23 +298,19 @@ context.getProcessInfo() -## Context.getProcessInfo - -- Functionality +### getProcessInfo - Obtains information about the current process, including the PID and process name. This method uses a promise to return the result. +getProcessInfo(): Promise\ -- Parameters +Obtains information about the current process, including the PID and process name. This method uses a promise to return the result. - None +**Return value** -- Return values +| Type| Description| +| --------------------- | -------------- | +| Promise\ | Promise used to return the process information.| - | Type| Description| - | -------------------- | -------------- | - | Promise | Promise used to return the process information.| - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -375,23 +322,21 @@ context.getProcessInfo().then((void) => { -## Context.getElementName(callback: AsyncCallback) - -- Functionality +### getElementName - Obtains the **ohos.bundle.ElementName** object of the current ability. This method is available only to Page abilities. It uses a callback to return the result. +getElementName(callback: AsyncCallback\): void -- Parameters +Obtains the **ohos.bundle.ElementName** object of the current ability. This method uses a callback to return the result. - | Name| Readable/Writable| Type| Mandatory| Description| - | -------- | -------- | --------------------------- | ---- | -------------------------------------------- | - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the **ohos.bundle.ElementName** object.| +This method is available only to Page abilities. -- Return values +**Parameters** - void +| Name| Type| Mandatory| Description| +| -------- | --------------------------- | ---- | ---------------------------------------------- | +| callback | AsyncCallback\ | Yes| Callback used to return the **ohos.bundle.ElementName** object.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -401,23 +346,21 @@ context.getElementName() -## Context.getElementName +### getElementName -- Functionality +getElementName(): Promise\ - Obtains the **ohos.bundle.ElementName** object of the current ability. This method is available only to Page abilities. It uses a promise to return the result. +Obtains the **ohos.bundle.ElementName** object of the current ability. This method uses a promise to return the result. -- Parameters +This method is available only to Page abilities. - None +**Return value** -- Return values +| Type| Description| +| --------------------- | ------------------------------------------ | +| Promise\ | Promise returned with the **ohos.bundle.ElementName** object.| - | Type| Description| - | -------------------- | ---------------------------------------- | - | Promise | Promise used to return the **ohos.bundle.ElementName** object.| - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -427,23 +370,17 @@ context.getElementName().then((void) => { }); ``` -## **Context.getProcessName(callback: AsyncCallback)** - -- Functionality +### getProcessName - Obtains the name of the current process. This method uses a callback to return the result. +getProcessName(callback: AsyncCallback\): void -- Parameters +Obtains the name of the current process. This method uses a callback to return the result. - | Name| Readable/Writable| Type| Mandatory| Description| - | -------- | -------- | ---------------------- | ---- | ------------------ | - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the process name.| +| Name| Type| Mandatory| Description| +| -------- | ---------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes| Callback used to return the process name.| -- Return values - - void - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -453,23 +390,19 @@ context.getProcessName() -## Context.getProcessName - -- Functionality - - Obtains the name of the current process. This method uses a promise to return the result. +### getProcessName -- Parameters +getProcessName(): Promise\ - None +Obtains the name of the current process. This method uses a promise to return the result. -- Return values +**Return value** - | Type| Description| - | --------------- | -------------- | - | Promise | Promise used to return the process name.| +| Type| Description| +| ---------------- | -------------------- | +| Promise\ | Promise returned with the process name.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -481,23 +414,19 @@ context.getProcessName().then((void) => { -## Context.getCallingBundle(callback: AsyncCallback) +### getCallingBundle -- Functionality +getCallingBundle(callback: AsyncCallback\): void - Obtains the bundle name of the calling ability. This method uses a callback to return the result. +Obtains the bundle name of the calling ability. This method uses a callback to return the result. -- Parameters +**Parameters** - | Name| Readable/Writable| Type| Mandatory| Description| - | -------- | -------- | ---------------------- | ---- | ------------------------- | - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the bundle name.| +| Name| Type| Mandatory| Description| +| -------- | ---------------------- | ---- | ------------------------- | +| callback | AsyncCallback\ | Yes| Callback used to return the bundle name.| -- Return values - - void - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -507,25 +436,19 @@ context.getCallingBundle() -## Context.getCallingBundle - -- Functionality - - Obtains the bundle name of the calling ability. This method uses a promise to return the result. +### getCallingBundle -- Parameters +getCallingBundle(): Promise\ - None +Obtains the bundle name of the calling ability. This method uses a promise to return the result. -- Return values +**Return value** - | Type| Description| - | --------------- | ------------------------- | - | Promise | Promise used to return the bundle name.| +| Type| Description| +| --------------- | ------------------------- | +| Promise\ | Promise used to return the bundle name.| - - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -534,3 +457,18 @@ context.getCallingBundle().then((void) => { console.info("==========================>getCallingBundleCallback=======================>"); }); ``` + +## PermissionOptions + +| Name| Readable/Writable| Type| Mandatory| Description| +| ---- | -------- | ------ | ---- | ------ | +| pid | Read-only| number | No| PID.| +| uid | Read-only| number | No| UID.| + +## PermissionRequestResult + +| Name| Readable/Writable| Type| Mandatory| Description| +| ----------- | -------- | -------------- | ---- | ------------------ | +| requestCode | Read-only| number | Yes| Request code passed.| +| permissions | Read-only| Array\ | Yes| Permissions passed.| +| authResults | Read-only| Array\ | Yes| Permission request result.| diff --git a/en/application-dev/reference/apis/js-apis-DataUriUtils.md b/en/application-dev/reference/apis/js-apis-DataUriUtils.md index 494c24532e..4aa00cd0b3 100644 --- a/en/application-dev/reference/apis/js-apis-DataUriUtils.md +++ b/en/application-dev/reference/apis/js-apis-DataUriUtils.md @@ -6,24 +6,25 @@ import dataUriUtils from '@ohos.ability.dataUriUtils'; ``` -## DataUriUtils.getId +## dataUriUtils.getId -- Functionality +getId(uri: string): number - Obtains the ID attached to the end of a given URI. +Obtains the ID attached to the end of a given URI. -- Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| ---- | -------- | ------ | ---- | ------------------------- | -| uri | Read-only| string | Yes| URI object from which the ID is to be obtained.| +| Name| Type| Mandatory| Description| +| ---- | ------ | ---- | --------------------------- | +| uri | string | Yes| URI object from which the ID is to be obtained.| -- Return values +**Return value** +| Type| Description| +| ------ | ------------------------ | +| number | ID obtained from the URI object.| - Returns the ID obtained from the URI object. - -- Example +**Example** ```js import dataUriUtils from '@ohos.ability.datauriutils' @@ -32,25 +33,26 @@ dataUriUtils.getIdSync("com.example.dataUriUtils/1221") -## DataUriUtils.attachId - -- Functionality +## dataUriUtils.attachId - Attaches an ID to the end of a given URI. +attachId(uri: string, id: number): string -- Parameters +Attaches an ID to the end of a given URI. +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| ---- | -------- | ------ | ---- | ------------------------- | -| uri | Read-only| string | Yes| URI object to which an ID is to be attached.| -| id | Read-only| number | Yes| ID to be attached.| -- Return values +| Name| Type| Mandatory| Description| +| ---- | ------ | ---- | --------------------------- | +| uri | string | Yes| URI object to which an ID is to be attached.| +| id | number | Yes| ID to be attached.| - Returns the URI object with the ID attached. +**Return value** +| Type| Description| +| ------ | --------------------- | +| string | URI object with the ID attached.| -- Example +**Example** ```js import dataUriUtils from '@ohos.ability.datauriutils' @@ -63,23 +65,24 @@ dataUriUtils.attachId( -## DataUriUtils.deleteId +## dataUriUtils.deleteId -- Functionality +deleteId(uri: string): string - Deletes the ID from the end of a given URI. +Deletes the ID from the end of a given URI. -- Parameters +**Parameters** - | Name| Readable/Writable| Type| Mandatory| Description| - | ---- | -------- | ------ | ---- | ------------------------- | - | uri | Read-only| string | Yes| URI object from which the ID is to be deleted.| +| Name| Type| Mandatory| Description| +| ---- | ------ | ---- | --------------------------- | +| uri | string | Yes| URI object from which the ID is to be deleted.| -- Return values +**Return value** +| Type| Description| +| ------ | ------------------- | +| string | URI object with the ID deleted.| - Returns the URI object with the ID deleted. - -- Example +**Example** ```js import dataUriUtils from '@ohos.ability.datauriutils' @@ -88,24 +91,25 @@ dataUriUtils.deleteId("com.example.dataUriUtils/1221") -## DataUriUtils.updateId - -- Functionality +## dataUriUtils.updateId - Updates the ID in a given URI. +updateId(uri: string, id: number): string -- Parameters +Updates the ID in a given URI. - | Name| Readable/Writable| Type| Mandatory| Description| - | ---- | -------- | ------ | ---- | ------------------- | - | uri | Read-only| string | Yes| URI object to be updated.| - | id | Read-only| number | Yes| New ID.| +**Parameters** -- Return values +| Name| Type| Mandatory| Description| +| ---- | ------ | ---- | ------------------- | +| uri | string | Yes| URI object to be updated.| +| id | number | Yes| New ID.| - Returns the URI object with the new ID. +**Return value** +| Type| Description| +| ------ | --------------- | +| string | URI object with the new ID.| -- Example +**Example** ```js import dataUriUtils from '@ohos.ability.datauriutils' diff --git a/en/application-dev/reference/apis/js-apis-commonEvent.md b/en/application-dev/reference/apis/js-apis-commonEvent.md index 9ef873e163..6a40ef7c65 100644 --- a/en/application-dev/reference/apis/js-apis-commonEvent.md +++ b/en/application-dev/reference/apis/js-apis-commonEvent.md @@ -1,12 +1,12 @@ # CommonEvent Module -**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. +> **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. ## Required Permissions | Common Event Macro| Common Event Name| Subscriber Permissions| -| ------------------------------------------------------------ | ----------------------------------------------------------- | ------------------------------------------------------------ | +| ------------ | ------------------ | ---------------------- | | COMMON_EVENT_BOOT_COMPLETED | usual.event.BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED | | COMMON_EVENT_SHUTDOWN | usual.event.SHUTDOWN | N/A| | COMMON_EVENT_BATTERY_CHANGED | usual.event.BATTERY_CHANGED | N/A| @@ -103,11 +103,11 @@ The initial APIs of this module are supported since API version 7. Newly added A | COMMON_EVENT_USB_DEVICE_DETACHED | usual.event.hardware.usb.action.USB_DEVICE_DETACHED | N/A| | COMMON_EVENT_USB_ACCESSORY_ATTACHED | usual.event.hardware.usb.action.USB_ACCESSORY_ATTACHED | N/A| | COMMON_EVENT_USB_ACCESSORY_DETACHED | usual.event.hardware.usb.action.USB_ACCESSORY_DETACHED | N/A| -| COMMON_EVENT_DISK_REMOVED | usual.event.data.DISK_REMOVED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE | -| COMMON_EVENT_DISK_UNMOUNTED | usual.event.data.DISK_UNMOUNTED | ohos.permission.WRITE_USER_STORAGEor ohos.permission.READ_USER_STORAGE | -| COMMON_EVENT_DISK_MOUNTED | usual.event.data.DISK_MOUNTED | ohos.permission.WRITE_USER_STORAGEor ohos.permission.READ_USER_STORAGE | -| COMMON_EVENT_DISK_BAD_REMOVAL | usual.event.data.DISK_BAD_REMOVAL | ohos.permission.WRITE_USER_STORAGEor ohos.permission.READ_USER_STORAGE | -| COMMON_EVENT_DISK_EJECT | usual.event.data.DISK_EJECT | ohos.permission.WRITE_USER_STORAGEor ohos.permission.READ_USER_STORAGE | +| COMMON_EVENT_DISK_REMOVED | usual.event.data.DISK_REMOVED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| +| COMMON_EVENT_DISK_UNMOUNTED | usual.event.data.DISK_UNMOUNTED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| +| COMMON_EVENT_DISK_MOUNTED | usual.event.data.DISK_MOUNTED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| +| COMMON_EVENT_DISK_BAD_REMOVAL | usual.event.data.DISK_BAD_REMOVAL | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| +| COMMON_EVENT_DISK_EJECT | usual.event.data.DISK_EJECT | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| | COMMON_EVENT_AIRPLANE_MODE_CHANGED | usual.event.AIRPLANE_MODE | N/A| ## Modules to Import @@ -118,20 +118,20 @@ import CommonEvent from '@ohos.commonevent'; -## CommonEvent.publish(event: string, callback: AsyncCallback\): void +## CommonEvent.publish -- Functionality +publish(event: string, callback: AsyncCallback\): void - Publishes a common event. This method uses a callback to return the result. +Publishes a common event. This method uses a callback to return the result. -* Parameters +**Parameters** - | Name| Readable/Writable| Type| Mandatory| Description| - | -------- | -------- | -------------------- | ---- | -------------------- | - | event | Read-only| string | Yes| Name of the common event to publish.| - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | -------------------- | ---- | ---------------------- | +| event | Read-only| string | Yes| Name of the common event to publish.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| -* Example +**Example** ```js // Callback for common event publication @@ -145,21 +145,21 @@ CommonEvent.publish("publish_event", PublishCallBack); -## CommonEvent.publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\): void +## CommonEvent.publish -- Functionality +publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\): void - Publishes a common event with given attributes. This method uses a callback to return the result. +Publishes a common event with given attributes. This method uses a callback to return the result. -- Parameters +**Parameters** - | Name| Readable/Writable| Type| Mandatory| Description| - | -------- | -------- | ---------------------- | ---- | ---------------------- | - | event | Read-only| string | Yes| Name of the common event to publish.| - | options | Read-only| [CommonEventPublishData](#publishData) | Yes| Attributes of the common event to publish.| - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | ---------------------- | ---- | ---------------------- | +| event | Read-only| string | Yes| Name of the common event to publish.| +| options | Read-only| [CommonEventPublishData](#commoneventpublishdata) | Yes| Attributes of the common event to publish.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| -- Example +**Example** ```js @@ -179,20 +179,20 @@ CommonEvent.publish("publish_event", options, PublishCallBack); -## CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback\): void +## CommonEvent.createSubscriber -- Functionality +createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback\): void - Creates a subscriber. This method uses a callback to return the result. +Creates a subscriber. This method uses a callback to return the result. -- Parameters +**Parameters** - | Name| Readable/Writable| Type| Mandatory| Description| - | ------------- | -------- | ---------------------------------------------------- | ---- | ------------------------ | - | subscribeInfo | Read-only| [CommonEventSubscribeInfo](#SubscribeInfo) | Yes| Subscriber information.| - | callback | Read-only| AsyncCallback\<[CommonEventSubscriber](#Subscriber)> | Yes| Callback used to return the result.| +| Name| Readable/Writable| Type| Mandatory| Description| +| ------------- | -------- | ------------------------------------------------------------ | ---- | -------------------------- | +| subscribeInfo | Read-only| [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | Yes| Subscriber information.| +| callback | Read-only| AsyncCallback\<[CommonEventSubscriber](#commoneventsubscriber)> | Yes| Callback used to return the result.| -- Example +**Example** ```js @@ -212,25 +212,24 @@ CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); -## CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\ +## CommonEvent.createSubscriber -- Functionality +createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\ - Creates a subscriber. This method uses a promise to return the result. +Creates a subscriber. This method uses a promise to return the result. -- Parameters +**Parameters** - | Name| Readable/Writable| Type| Mandatory| Description| - | ------------- | -------- | ------------------------------------------ | ---- | ------------ | - | subscribeInfo | Read-only| [CommonEventSubscribeInfo](#SubscribeInfo) | Yes| Subscriber information.| +| Name| Readable/Writable| Type| Mandatory| Description| +| ------------- | -------- | ----------------------------------------------------- | ---- | -------------- | +| subscribeInfo | Read-only| [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | Yes| Subscriber information.| -- Return values +**Return value** +| Type| Description| +| --------------------------------------------------------- | ---------------- | +| Promise\<[CommonEventSubscriber](#commoneventsubscriber)> | Promise returned with the subscriber object.| - Promise\<[CommonEventSubscriber](#Subscriber)> - - Returns a subscriber object. - -- Example +**Example** ```js var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. @@ -247,23 +246,22 @@ CommonEvent.createSubscriber(subscribeInfo).then((data) => { -## CommonEvent.subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\): void +## CommonEvent.subscribe -- Functionality +subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\): void - Subscribes to common events. This method uses a callback to return the result. +Subscribes to common events. This method uses a callback to return the result. -- Parameters +**Parameters** - | Name| Readable/Writable| Type| Mandatory| Description| - | ---------- | -------- | --------------------------------------------------- | ---- | ------------------------------ | - | subscriber | Read-only| [CommonEventSubscriber](#Subscriber) | Yes| Subscriber object.| - | callback | Read-only| AsyncCallback\<[CommonEventData](#CommonEventData)> | Yes| Callback used to return the result.| +| Name| Readable/Writable| Type| Mandatory| Description| +| ---------- | -------- | --------------------------------------------------- | ---- | -------------------------------- | +| subscriber | Read-only| [CommonEventSubscriber](#commoneventsubscriber) | Yes| Subscriber object.| +| callback | Read-only| AsyncCallback\<[CommonEventData](#commoneventdata)> | Yes| Callback used to return the result.| -- Example +**Example** - Unordered common event: - +Unordered common event: ```js var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. @@ -286,7 +284,7 @@ function CreateSubscriberCallBack(err, data) { CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); ``` -​ Ordered common event: + Ordered common event: ```js var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. @@ -330,22 +328,22 @@ function CreateSubscriberCallBack(err, data) { CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); ``` -​ + -## CommonEvent.unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\): void +## CommonEvent.unsubscribe -- Functionality +unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\): void - Unsubscribes from common events. This method uses a callback to return the result. +Unsubscribes from common events. This method uses a callback to return the result. -- Parameters +**Parameters** - | Name| Readable/Writable| Type| Mandatory| Description| - | ---------- | -------- | --------------------- | ---- | ---------------------- | - | subscriber | Read-only| CommonEventSubscriber | Yes| Subscriber object.| - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +| Name| Readable/Writable| Type| Mandatory| Description| +| ---------- | -------- | --------------------- | ---- | ------------------------ | +| subscriber | Read-only| CommonEventSubscriber | Yes| Subscriber object.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| -- Example +**Example** ```js var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. @@ -374,7 +372,7 @@ CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack); ``` -## CommonEventPublishData +## CommonEventPublishData | Name| Readable/Writable| Type| Mandatory| Description| | --------------------- | -------- | -------------------- | ---- | ---------------------------- | @@ -385,7 +383,7 @@ CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack); | isOrdered | Read-only| boolean | No| Whether the common event is an ordered one.| | parameters | Read-only| {[key: string]: any} | No| Additional information about the common event.| -## CommonEventSubscribeInfo +## CommonEventSubscribeInfo | Name| Readable/Writable| Type| Mandatory| Description| | ------------------- | -------- | -------------- | ---- | ------------------------------------------------------------ | @@ -395,7 +393,7 @@ CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack); | userId | Read-only| number | No| User ID. The default value is the ID of the current user. If this parameter is specified, the value must be an existing user ID in the system.| | priority | Read-only| number | No| Subscriber priority. The value ranges from -100 to 1000.| -## CommonEventData +## CommonEventData | Name| Readable/Writable| Type| Mandatory| Description| | ---------- | -------- | -------------------- | ---- | ------------------------------------------------------ | @@ -405,456 +403,456 @@ CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack); | data | Read-only| string | No| Custom result data of the common event, which is used to transfer data of the string type.| | parameters | Read-only| {[key: string]: any} | No| Additional information about the common event.| -## CommonEventSubscriber +## CommonEventSubscriber -### getCode (callback) +### getCode -- Functionality +getCode(callback: AsyncCallback\): void - Obtains the result code of this common event. This method uses a callback to return the result. +Obtains the result code of this common event. This method uses a callback to return the result. -- Parameters +**Parameters** - | Name| Type| Mandatory| Description| - | -------- | ---------------------- | ---- | ------------------ | - | callback | AsyncCallback\ | Yes| Callback used to return the result code.| +| Name| Type| Mandatory| Description| +| -------- | ---------------------- | ---- | ------------------ | +| callback | AsyncCallback\ | Yes| Callback used to return the result code.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - // Callback for result data setting of an ordered common event - function getCodeCallback(err, data) { - console.info("==========================>getCodeCallback=======================>"); - console.info("==========================>err:=======================>", err.code); - console.info("==========================>code:=======================>", data); - } - subscriber.getCode(getCodeCallback); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +// Callback for result data setting of an ordered common event +function getCodeCallback(err, data) { + console.info("==========================>getCodeCallback=======================>"); + console.info("==========================>err:=======================>", err.code); + console.info("==========================>code:=======================>", data); +} +subscriber.getCode(getCodeCallback); +``` -### getCode (promise) +### getCode -- Functionality +getCode(): Promise\ - Obtains the result code of this common event. This method uses a promise to return the result. +Obtains the result code of this common event. This method uses a promise to return the result. -- Return values +**Return value** - | Type| Description| - | ---------------- | ------------------ | - | Promise\ | A promise used to return the result code.| +| Type| Description| +| ---------------- | -------------------- | +| Promise\ | Promise returned with the result code.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - subscriber.getCode().then((data) => { - console.info("==========================>getCodePromise=======================>"); - console.info("==========================>code:=======================>", data); - }); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +subscriber.getCode().then((data) => { + console.info("==========================>getCodePromise=======================>"); + console.info("==========================>code:=======================>", data); +}); +``` -### setCode (callback) +### setCode -- Functionality +setCode(code: number, callback: AsyncCallback\): void - Sets the result code for this common event. This method uses a callback to return the result. +Sets the result code for this common event. This method uses a callback to return the result. -- Parameters +**Parameters** - | Name| Type| Mandatory| Description| - | -------- | -------------------- | ---- | -------------------- | - | code | number | Yes| Result code of the common event.| - | callback | AsyncCallback\ | Yes| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| -------- | -------------------- | ---- | ---------------------- | +| code | number | Yes| Result code of the common event.| +| callback | AsyncCallback\ | Yes| Callback used to return the result.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - // Callback for result data setting of an ordered common event - function setCodeCallback(err) { - console.info("==========================>setCodeCallback=======================>"); - console.info("==========================>err:=======================>", err.code); - } - subscriber.setCode(1, setCodeCallback); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +// Callback for result data setting of an ordered common event +function setCodeCallback(err) { + console.info("==========================>setCodeCallback=======================>"); + console.info("==========================>err:=======================>", err.code); +} +subscriber.setCode(1, setCodeCallback); +``` -### setCode (promise) +### setCode -- Functionality +setCode(code: number): Promise\ - Sets the result code for this common event. This method uses a promise to return the result. +Sets the result code for this common event. This method uses a promise to return the result. -- Parameters +**Parameters** - | Name| Type| Mandatory| Description| - | ------ | ------ | ---- | ------------------ | - | code | number | Yes| Result code of the common event.| +| Name| Type| Mandatory| Description| +| ------ | ------ | ---- | ------------------ | +| code | number | Yes| Result code of the common event.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - subscriber.setCode(1).then(() => { - console.info("==========================>setCodePromise=======================>"); - }); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +subscriber.setCode(1).then(() => { + console.info("==========================>setCodePromise=======================>"); +}); +``` -### getData (callback) +### getData -- Functionality +getData(callback: AsyncCallback\): void - Obtains the result data of this common event. This method uses a callback to return the result. +Obtains the result data of this common event. This method uses a callback to return the result. -- Parameters +**Parameters** - | Name| Type| Mandatory| Description| - | -------- | ---------------------- | ---- | ------------------ | - | callback | AsyncCallback\ | Yes| Callback used to return the result data.| +| Name| Type| Mandatory| Description| +| -------- | ---------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes| Callback used to return the result data.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - // Callback for result data setting of an ordered common event - function getDataCallback(err, data) { - console.info("==========================>getDataCallback=======================>"); - console.info("==========================>err:=======================>", err.code); - console.info("==========================>data:=======================>", data); - } - subscriber.getData(getDataCallback); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +// Callback for result data setting of an ordered common event +function getDataCallback(err, data) { + console.info("==========================>getDataCallback=======================>"); + console.info("==========================>err:=======================>", err.code); + console.info("==========================>data:=======================>", data); +} +subscriber.getData(getDataCallback); +``` -### getData (promise) +### getData -- Functionality +getData(): Promise\ - Obtains the result data of this common event. This method uses a promise to return the result. +Obtains the result data of this common event. This method uses a promise to return the result. -- Return values +**Return value** - | Type| Description| - | ---------------- | ------------------ | - | Promise\ | A promise used to return the result data.| +| Type| Description| +| ---------------- | ------------------ | +| Promise\ | Promise returned with the result data.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - subscriber.getData().then((data) => { - console.info("==========================>getDataPromise=======================>"); - console.info("==========================>data:=======================>", data); - }); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +subscriber.getData().then((data) => { + console.info("==========================>getDataPromise=======================>"); + console.info("==========================>data:=======================>", data); +}); +``` -### setData (callback) +### setData -- Functionality +setData(data: string, callback: AsyncCallback\): void - Sets the result data for this common event. This method uses a callback to return the result. +Sets the result data for this common event. This method uses a callback to return the result. -- Parameters +**Parameters** - | Name| Type| Mandatory| Description| - | -------- | -------------------- | ---- | -------------------- | - | data | string | Yes| Result data of the common event.| - | callback | AsyncCallback\ | Yes| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| -------- | -------------------- | ---- | -------------------- | +| data | string | Yes| Result data of the common event.| +| callback | AsyncCallback\ | Yes| Callback used to return the result.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - // Callback for result data setting of an ordered common event - function setDataCallback(err) { - console.info("==========================>setDataCallback=======================>"); - console.info("==========================>err:=======================>", err.code); - } - subscriber.setData("publish_data_changed", setDataCallback); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +// Callback for result data setting of an ordered common event +function setDataCallback(err) { + console.info("==========================>setDataCallback=======================>"); + console.info("==========================>err:=======================>", err.code); +} +subscriber.setData("publish_data_changed", setDataCallback); +``` -### setData (promise) +### setData -- Functionality +setData(data: string): Promise\ - Sets the result data for this common event. This method uses a promise to return the result. +Sets the result data for this common event. This method uses a promise to return the result. -- Parameters +**Parameters** - | Name| Type| Mandatory| Description| - | ------ | ------ | ---- | ------------------ | - | data | string | Yes| Result data of the common event.| +| Name| Type| Mandatory| Description| +| ------ | ------ | ---- | -------------------- | +| data | string | Yes| Result data of the common event.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - subscriber.setData("publish_data_changed").then(() => { - console.info("==========================>setDataPromise=======================>"); - }); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +subscriber.setData("publish_data_changed").then(() => { + console.info("==========================>setDataPromise=======================>"); +}); +``` -### setCodeAndData (callback) +### setCodeAndData -- Functionality +setCodeAndData(code: number, data: string, callback:AsyncCallback\): void - Sets the result code and result data for this common event. This method uses a callback to return the result. +Sets the result code and result data for this common event. This method uses a callback to return the result. -- Parameters +**Parameters** - | Name| Type| Mandatory| Description| - | -------- | -------------------- | ---- | -------------------- | - | code | number | Yes| Result code of the common event.| - | data | string | Yes| Result data of the common event.| - | callback | AsyncCallback\ | Yes| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| -------- | -------------------- | ---- | ---------------------- | +| code | number | Yes| Result code of the common event.| +| data | string | Yes| Result data of the common event.| +| callback | AsyncCallback\ | Yes| Callback used to return the result.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - // Callback for result data setting of an ordered common event - function setCodeDataCallback(err) { - console.info("==========================>setCodeDataCallback=======================>"); - console.info("==========================>err:=======================>", err.code); - } - subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCallback); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +// Callback for result data setting of an ordered common event +function setCodeDataCallback(err) { + console.info("==========================>setCodeDataCallback=======================>"); + console.info("==========================>err:=======================>", err.code); +} +subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCallback); +``` -### setCodeAndData (promise) +### setCodeAndData -- Functionality +setCodeAndData(code: number, data: string): Promise\ - Sets the result code and result data for this common event. This method uses a promise to return the result. +Sets the result code and result data for this common event. This method uses a promise to return the result. -- Parameters +**Parameters** - | Name| Type| Mandatory| Description| - | ------ | ------ | ---- | ------------------ | - | code | number | Yes| Result code of the common event.| - | data | string | Yes| Result data of the common event.| +| Name| Type| Mandatory| Description| +| ------ | ------ | ---- | -------------------- | +| code | number | Yes| Result code of the common event.| +| data | string | Yes| Result data of the common event.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - subscriber.setCodeAndData(1, "publish_data_changed").then(() => { - console.info("==========================>setCodeAndData=======================>"); - }); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +subscriber.setCodeAndData(1, "publish_data_changed").then(() => { + console.info("==========================>setCodeAndData=======================>"); +}); +``` -### isOrderedCommonEvent (callback) +### isOrderedCommonEvent -- Functionality +isOrderedCommonEvent(callback: AsyncCallback\): void - Checks whether this common event is an ordered one. This method uses a callback to return the result. +Checks whether this common event is an ordered one. This method uses a callback to return the result. -- Parameters +**Parameters** - | Name| Type| Mandatory| Description| - | -------- | ----------------------- | ---- | -------------------------------- | - | callback | AsyncCallback\ | Yes| Returns **true** if the common event is an ordered one; returns **false** otherwise.| +| Name| Type| Mandatory| Description| +| -------- | ----------------------- | ---- | ---------------------------------- | +| callback | AsyncCallback\ | Yes| Returns **true** if the common event is an ordered one; returns **false** otherwise.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - // Callback for result data setting of an ordered common event - function isOrderedCallback(err, data) { - console.info("==========================>isOrderedCallback=======================>"); - console.info("==========================>err:=======================>", err.code); - console.info("==========================>isOrdered:=======================>", data); - } - subscriber.isOrderedCommonEvent(isOrderedCallback); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +// Callback for result data setting of an ordered common event +function isOrderedCallback(err, data) { + console.info("==========================>isOrderedCallback=======================>"); + console.info("==========================>err:=======================>", err.code); + console.info("==========================>isOrdered:=======================>", data); +} +subscriber.isOrderedCommonEvent(isOrderedCallback); +``` -### isOrderedCommonEvent (promise) +### isOrderedCommonEvent -- Functionality +isOrderedCommonEvent(): Promise\ - Checks whether this common event is an ordered one. This method uses a promise to return the result. +Checks whether this common event is an ordered one. This method uses a promise to return the result. -- Return values +**Return value** - | Type| Description| - | ----------------- | -------------------------------- | - | Promise\ | Returns **true** if the common event is an ordered one; returns **false** otherwise.| +| Type| Description| +| ----------------- | -------------------------------- | +| Promise\ | Returns **true** if the common event is an ordered one; returns **false** otherwise.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - subscriber.isOrderedCommonEvent().then((data) => { - console.info("==========================>isOrdered:=======================>", data); - }); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +subscriber.isOrderedCommonEvent().then((data) => { + console.info("==========================>isOrdered:=======================>", data); +}); +``` -### abortCommonEvent (callback) +### abortCommonEvent -- Functionality +abortCommonEvent(callback: AsyncCallback\): void - Aborts this common event. After the abort, the common event is not sent to the next subscriber. This method takes effect only for ordered common events. It uses a callback to return the result. +Aborts this common event. After the abort, the common event is not sent to the next subscriber. This method takes effect only for ordered common events. It uses a callback to return the result. -- Parameters +**Parameters** - | Name| Type| Mandatory| Description| - | -------- | ----------------------- | ---- | ------------------ | - | callback | AsyncCallback\ | Yes| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| -------- | -------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes| Callback used to return the result.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - // Callback for result data setting of an ordered common event - function abortCallback(err) { - console.info("==========================>abortCallback=======================>"); - console.info("==========================>err:=======================>", err.code); - } - subscriber.abortCommonEvent(abortCallback); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +// Callback for result data setting of an ordered common event +function abortCallback(err) { + console.info("==========================>abortCallback=======================>"); + console.info("==========================>err:=======================>", err.code); +} +subscriber.abortCommonEvent(abortCallback); +``` -### abortCommonEvent (promise) +### abortCommonEvent -- Functionality +abortCommonEvent(): Promise\ - Aborts this common event. After the abort, the common event is not sent to the next subscriber. This method takes effect only for ordered common events. It uses a promise to return the result. +Aborts this common event. After the abort, the common event is not sent to the next subscriber. This method takes effect only for ordered common events. It uses a promise to return the result. -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - subscriber.abortCommonEvent().then(() => { - console.info("==========================>abortCommonEvent:=======================>"); - }); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +subscriber.abortCommonEvent().then(() => { + console.info("==========================>abortCommonEvent:=======================>"); +}); +``` -### clearAbortCommonEvent (callback) +### clearAbortCommonEvent -- Functionality +clearAbortCommonEvent(callback: AsyncCallback\): void - Clears the aborted state of this common event. This method takes effect only for ordered common events. It uses a callback to return the result. +Clears the aborted state of this common event. This method takes effect only for ordered common events. It uses a callback to return the result. -- Parameters +**Parameters** - | Name| Type| Mandatory| Description| - | -------- | -------------------- | ---- | -------------------- | - | callback | AsyncCallback\ | Yes| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| -------- | -------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes| Callback used to return the result.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - // Callback for result data setting of an ordered common event - function clearAbortCallback(err) { - console.info("==========================>clearAbortCallback=======================>"); - console.info("==========================>err:=======================>", err.code); - } - subscriber.clearAbortCommonEvent(clearAbortCallback); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +// Callback for result data setting of an ordered common event +function clearAbortCallback(err) { + console.info("==========================>clearAbortCallback=======================>"); + console.info("==========================>err:=======================>", err.code); +} +subscriber.clearAbortCommonEvent(clearAbortCallback); +``` -### clearAbortCommonEvent (promise) +### clearAbortCommonEvent -- Functionality +clearAbortCommonEvent(): Promise\ - Clears the aborted state of this common event. This method takes effect only for ordered common events. It uses a promise to return the result. +Clears the aborted state of this common event. This method takes effect only for ordered common events. It uses a promise to return the result. -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - subscriber.clearAbortCommonEvent().then(() => { - console.info("==========================>clearAbortCommonEvent:=======================>"); - }); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +subscriber.clearAbortCommonEvent().then(() => { + console.info("==========================>clearAbortCommonEvent:=======================>"); +}); +``` -### getAbortCommonEvent (callback) +### getAbortCommonEvent -- Functionality +getAbortCommonEvent(callback: AsyncCallback\): void - Checks whether this common event is in the aborted state. This method takes effect only for ordered common events. It uses a callback to return the result. +Checks whether this common event is in the aborted state. This method takes effect only for ordered common events. It uses a callback to return the result. -- Parameters +**Parameters** - | Name| Type| Mandatory| Description| - | -------- | ----------------------- | ---- | ---------------------------------- | - | callback | AsyncCallback\ | Yes| Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.| +| Name| Type| Mandatory| Description| +| -------- | ----------------------- | ---- | ---------------------------------- | +| callback | AsyncCallback\ | Yes| Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - // Callback for result data setting of an ordered common event - function getAbortCallback(err, data) { - console.info("==========================>getAbortCallback=======================>"); - console.info("==========================>err:=======================>", err.code); - console.info("==========================>abort:=======================>", data); - } - subscriber.getAbortCommonEvent(getAbortCallback); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +// Callback for result data setting of an ordered common event +function getAbortCallback(err, data) { + console.info("==========================>getAbortCallback=======================>"); + console.info("==========================>err:=======================>", err.code); + console.info("==========================>abort:=======================>", data); +} +subscriber.getAbortCommonEvent(getAbortCallback); +``` -### getAbortCommonEvent (promise) +### getAbortCommonEvent -- Functionality +getAbortCommonEvent(): Promise\ - Checks whether this common event is in the aborted state. This method takes effect only for ordered common events. It uses a promise to return the result. +Checks whether this common event is in the aborted state. This method takes effect only for ordered common events. It uses a promise to return the result. -- Return values +**Return value** - | Type| Description| - | ----------------- | ---------------------------------- | - | Promise\ | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.| +| Type| Description| +| ----------------- | ---------------------------------- | +| Promise\ | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - subscriber.getAbortCommonEvent().then((data) => { - console.info("==========================>getAbortCommonEvent:=======================>"); - console.info("==========================>abort:=======================>", data); - }); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +subscriber.getAbortCommonEvent().then((data) => { + console.info("==========================>getAbortCommonEvent:=======================>"); + console.info("==========================>abort:=======================>", data); +}); +``` -### getSubscribeInfo (callback) +### getSubscribeInfo -- Functionality +getSubscribeInfo(callback: AsyncCallback\): void - Obtains the subscriber information. This method uses a callback to return the result. +Obtains the subscriber information. This method uses a callback to return the result. -- Parameters +**Parameters** - | Name| Type| Mandatory| Description| - | -------- | ---------------------------------------- | ---- | -------------------- | - | callback | AsyncCallback\ | Yes| Callback used to return the subscriber information.| +| Name| Type| Mandatory| Description| +| -------- | ------------------------------------------------------------ | ---- | ---------------------- | +| callback | AsyncCallback\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Yes| Callback used to return the subscriber information.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - // Callback for result data setting of an ordered common event - function getSubscribeInfoCallback(err, data) { - console.info("==========================>getSubscribeInfoCallback=======================>"); - console.info("==========================>err:=======================>", err.code); - console.info("==========================>priority:=======================>", data.priority); - } - subscriber.getSubscribeInfo(getSubscribeInfoCallback); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +// Callback for result data setting of an ordered common event +function getSubscribeInfoCallback(err, data) { + console.info("==========================>getSubscribeInfoCallback=======================>"); + console.info("==========================>err:=======================>", err.code); + console.info("==========================>priority:=======================>", data.priority); +} +subscriber.getSubscribeInfo(getSubscribeInfoCallback); +``` -### getSubscribeInfo (promise) +### getSubscribeInfo -- Functionality +getSubscribeInfo(): Promise\ - Obtains the subscriber information. This method uses a promise to return the result. +Obtains the subscriber information. This method uses a promise to return the result. -- Return values +**Return value** - | Type| Description| - | ---------------------------------- | -------------------- | - | Promise\ | A promise used to return the subscriber information.| +| Type| Description| +| ------------------------------------------------------------ | ---------------------- | +| Promise\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Promise returned with the subscriber information.| -- Example +**Example** - ```js - var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. - subscriber.getSubscribeInfo().then((data) => { - console.info("==========================>getSubscribeInfo:=======================>"); - console.info("==========================>priority:=======================>", data.priority); - }); - ``` +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +subscriber.getSubscribeInfo().then((data) => { + console.info("==========================>getSubscribeInfo:=======================>"); + console.info("==========================>priority:=======================>", data.priority); +}); +``` diff --git a/en/application-dev/reference/apis/js-apis-display.md b/en/application-dev/reference/apis/js-apis-display.md index 5de72ecfb4..dd7e82d326 100644 --- a/en/application-dev/reference/apis/js-apis-display.md +++ b/en/application-dev/reference/apis/js-apis-display.md @@ -1,436 +1,141 @@ -# Display +# Display ->![](../../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. +> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** +> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. -## Modules to Import + +## Modules to Import ``` import display from '@ohos.display'; ``` -## Required Permissions + +## Required Permissions None -## DisplayState + +## DisplayState Provides the state of a display. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Default Value

-

Description

-

STATE_UNKNOWN

-

0

-

Unknown.

-

STATE_OFF

-

1

-

The display is shut down.

-

STATE_ON

-

2

-

The display is powered on.

-

STATE_DOZE

-

3

-

The display is in sleep mode.

-

STATE_DOZE_SUSPEND

-

4

-

The display is in sleep mode, and the CPU is suspended.

-

STATE_VR

-

5

-

The display is in VR mode.

-

STATE_ON_SUSPEND

-

6

-

The display is powered on, and the CPU is suspended.

-
- -## Display +| Name| Default Value| Description| +| -------- | -------- | -------- | +| STATE_UNKNOWN | 0 | Unknown.| +| STATE_OFF | 1 | The display is shut down.| +| STATE_ON | 2 | The display is powered on.| +| STATE_DOZE | 3 | The display is in sleep mode.| +| STATE_DOZE_SUSPEND | 4 | The display is in sleep mode, and the CPU is suspended.| +| STATE_VR | 5 | The display is in VR mode.| +| STATE_ON_SUSPEND | 6 | The display is powered on, and the CPU is suspended.| + + +## Display Describes the attributes of a display. -### Attributes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

id

-

number

-

Yes

-

No

-

ID of the display.

-

name

-

string

-

Yes

-

No

-

Name of the display.

-

alive

-

boolean

-

Yes

-

No

-

Whether the display is alive.

-

state

-

DisplayState

-

Yes

-

No

-

State of the display.

-

refreshRate

-

number

-

Yes

-

No

-

Refresh rate of the display.

-

rotation

-

number

-

Yes

-

No

-

Screen rotation angle of the display.

-

width

-

number

-

Yes

-

No

-

Width of the display, in pixels.

-

height

-

number

-

Yes

-

No

-

Height of the display, in pixels.

-

densityDPI

-

number

-

Yes

-

No

-

Screen density of the display, in DPI.

-

densityPixels

-

number

-

Yes

-

No

-

Screen density of the display, in pixels.

-

scaledDensity

-

number

-

Yes

-

No

-

Scaling factor for fonts displayed on the display.

-

xDPI

-

number

-

Yes

-

No

-

Exact physical dots per inch of the screen in the horizontal direction.

-

yDPI

-

number

-

Yes

-

No

-

Exact physical dots per inch of the screen in the vertical direction.

-
- -## display.getDefaultDisplay - -getDefaultDisplay\(callback: AsyncCallback\): void; +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| id | number | Yes| No| ID of the display.| +| name | string | Yes| No| Name of the display.| +| alive | boolean | Yes| No| Whether the display is alive.| +| state | [DisplayState](#displaystate) | Yes| No| State of the display.| +| refreshRate | number | Yes| No| Refresh rate of the display.| +| rotation | number | Yes| No| Screen rotation angle of the display.| +| width | number | Yes| No| Width of the display, in pixels.| +| height | number | Yes| No| Height of the display, in pixels.| +| densityDPI | number | Yes| No| Screen density of the display, in DPI.| +| densityPixels | number | Yes| No| Screen density of the display, in pixels.| +| scaledDensity | number | Yes| No| Scaling factor for fonts displayed on the display.| +| xDPI | number | Yes| No| Exact physical dots per inch of the screen in the horizontal direction.| +| yDPI | number | Yes| No| Exact physical dots per inch of the screen in the vertical direction.| + + +## display.getDefaultDisplay + +getDefaultDisplay(callback: AsyncCallback<Display>): void; Obtains the default display object. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

callback

-

AsyncCallback<Display>

-

Yes

-

Callback used to return the attributes of the default display.

-
- -- Example - - ``` - var displayClass = null; - display.getDefaultDisplay((err, data) => { - if (err) { - console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data)); - displayClass = data; - }); - ``` - - -## display.getAllDisplay - -getAllDisplay\(callback: AsyncCallback\>\): void; +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<[Display](#display)> | Yes| Callback used to return the attributes of the default display.| + +- Example + ``` + var displayClass = null; + display.getDefaultDisplay((err, data) => { + if (err) { + console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err)); + return; + } + console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data)); + displayClass = data; + }); + ``` + + +## display.getAllDisplay + +getAllDisplay(callback: AsyncCallback<Array<Display>>): void; Obtains all the display objects. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

callback

-

AsyncCallback<Array<Display>>

-

Yes

-

Callback used to return the attributes of all displays.

-
- -- Example - - ``` - display.getAllDisplay((err, data) => { - if (err) { - console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data)) - }); - ``` - - -## display.on\('add'|'remove'|'change'\) - -on\(type: 'add'|'remove'|'change', callback: Callback\): void; +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<Array<[Display](#display)>> | Yes| Callback used to return the attributes of all displays.| + +- Example + ``` + display.getAllDisplay((err, data) => { + if (err) { + console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err)); + return; + } + console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data)) + }); + ``` + + +## display.on('add'|'remove'|'change') + +on(type: 'add'|'remove'|'change', callback: Callback<number>): void; Enables listening. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

string

-

Yes

-

Listening type.

-
  • add: listening for whether a display is added
  • remove: listening for whether a display is removed
  • change: listening for whether a display is changed
-

callback

-

Callback<number>

-

Yes

-

Callback used to return the ID of the display.

-
- -- Example - - ``` - var type = "add"; - var callback = (data) => { - console.info('Listening enabled. Data: ' + JSON.stringify(data)) - } - display.on(type, callback); - ``` - - -## display.off\('add'|'remove'|'change'\) - -off\(type: 'add'|'remove'|'change', callback?: Callback\): void; +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Listening type. The available values are as follows:
- **add**: listening for whether a display is added
- **remove**: listening for whether a display is removed
- **change**: listening for whether a display is changed| + | callback | Callback<number> | Yes| Callback used to return the ID of the display.| + +- Example + ``` + var type = "add"; + var callback = (data) => { + console.info('Listening enabled. Data: ' + JSON.stringify(data)) + } + display.on(type, callback); + ``` -Disables listening. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

string

-

Yes

-

Listening type.

-
  • add: listening for whether a display is added
  • remove: listening for whether a display is removed
  • change: listening for whether a display is changed
-

callback

-

Callback<number>

-

No

-

Callback used to return the ID of the display.

-
- -- Example - - ``` - var type = "remove"; - display.off(type); - ``` +## display.off('add'|'remove'|'change') +off(type: 'add'|'remove'|'change', callback?: Callback<number>): void; + +Disables listening. +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Listening type. The available values are as follows:
- **add**: listening for whether a display is added
- **remove**: listening for whether a display is removed
- **change**: listening for whether a display is changed| + | callback | Callback<number> | No| Callback used to return the ID of the display.| + +- Example + ``` + var type = "remove"; + display.off(type); + ``` diff --git a/en/application-dev/reference/apis/js-apis-faultLogger.md b/en/application-dev/reference/apis/js-apis-faultLogger.md index 7dba1772e4..8c4be914dd 100644 --- a/en/application-dev/reference/apis/js-apis-faultLogger.md +++ b/en/application-dev/reference/apis/js-apis-faultLogger.md @@ -12,7 +12,7 @@ import faultLogger from '@ohos.faultLogger' None -## faultLogger.FaultType +## FaultType Enumerates the fault types. @@ -23,7 +23,7 @@ Enumerates the fault types. | JS_CRASH | 3 | JS program crash.| | APP_FREEZE | 4 | Application freezing.| -## faultLogger.FaultLogInfo +## FaultLogInfo Defines the data structure of the fault log information. @@ -31,7 +31,7 @@ Defines the data structure of the fault log information. | -------- | -------- | -------- | | pid | number | Process ID of the faulty process.| | uid | number | User ID of the faulty process.| -| type | [FaultType](#faultloggerfaulttype) | Fault type.| +| type | [FaultType](#faulttype) | Fault type.| | timestamp | number | Second-level timestamp when the log was generated.| | reason | string | Reason for the fault.| | module | string | Module on which the fault occurred.| @@ -47,8 +47,8 @@ Obtains the fault information about the current process. This method uses a call - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | faultType | [FaultType](#faultloggerfaulttype) | Yes| Fault type.| - | callback | AsyncCallbackArray<Array<[FaultLogInfo](#faultloggerfaultloginfo)>> | Yes| Callback used to return the fault information array.
The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval. In this case, an error string will be returned. + | faultType | [FaultType](#faulttype) | Yes| Fault type.| + | callback | AsyncCallbackArray<Array<[FaultLogInfo](#faultloginfo)>> | Yes| Callback used to return the fault information array.
The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval. In this case, an error string will be returned. - Example ``` @@ -83,12 +83,12 @@ Obtains the fault information about the current process. This method uses a prom - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | faultType | [FaultType](#faultloggerfaulttype) | Yes| Fault type.| + | faultType | [FaultType](#faulttype) | Yes| Fault type.| -- Return values +- Return value | Type| Description| | -------- | -------- | - | Promise<Array<[FaultLogInfo](#faultloggerfaultloginfo)>> | Promise used to return the fault information array. You can obtain the fault information instance in its **then()** method or use **await**.
The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval.| + | Promise<Array<[FaultLogInfo](#faultloginfo)>> | Promise used to return the fault information array. You can obtain the fault information instance in its **then()** method or use **await**.
The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval.| - Example ``` diff --git a/en/application-dev/reference/apis/js-apis-featureAbility.md b/en/application-dev/reference/apis/js-apis-featureAbility.md index c07e862c47..6e899315a9 100644 --- a/en/application-dev/reference/apis/js-apis-featureAbility.md +++ b/en/application-dev/reference/apis/js-apis-featureAbility.md @@ -1,30 +1,29 @@ # FeatureAbility Module (JavaScript) -#### Constraints +## Constraints APIs of the **FeatureAbility** module can be called only by Page abilities. -#### Modules to Import +## Modules to Import ``` import featureAbility from '@ohos.ability.featureAbility' ``` -#### FeatureAbility.startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\): void +## featureAbility.startAbility -* Functionality +startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\): void - Starts an ability. This method uses a callback to return the result. +Starts an ability. This method uses a callback to return the result. -* Parameters - -| Name| Readable/Writable| Type| Mandatory| Description| -| --------- | -------- | --------------------- | ---- | ------------------- | -| parameter | Read-only| [StartAbilityParameter](#StartAbilityParameter)| Yes| Ability to start.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**Parameters** +| Name| Type| Mandatory| Description| +| --------- | --------------------- | ---- | ------------------- | +| parameter | [StartAbilityParameter](#startabilityparameter) | Yes| Ability to start.| +| callback | AsyncCallback\ | Yes| Callback used to return the result.| -- Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureAbility' @@ -48,20 +47,19 @@ featureAbility.startAbility( -#### FeatureAbility.startAbility(parameter: StartAbilityParameter): Promise\ +## featureAbility.startAbility -* Functionality +startAbility(parameter: StartAbilityParameter): Promise\ - Starts an ability. This method uses a promise to return the result. +Starts an ability. This method uses a promise to return the result. -* Parameters - -| Name| Readable/Writable| Type| Mandatory| Description| -| --------- | -------- | ------------------------------------------------------- | ---- | ------------------- | -| parameter | Read-only| [StartAbilityParameter](#StartAbilityParameter)| Yes| Ability to start.| +**Parameters** +| Name| Type| Mandatory| Description| +| --------- | ----------------------------------------------- | ---- | --------------------- | +| parameter | [StartAbilityParameter](#startabilityparameter) | Yes| Ability to start.| -- Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureAbility' @@ -84,27 +82,25 @@ featureAbility.startAbility( }); ``` +## featureAbility.acquireDataAbilityHelper +acquireDataAbilityHelper(uri: string): DataAbilityHelper -#### FeatureAbility.acquireDataAbilityHelper(uri: string): DataAbilityHelper +Obtains a **dataAbilityHelper** object. -* Functionality +**Parameters** - Obtains a **dataAbilityHelper**. - -* Parameters - -| Name| Readable/Writable| Type| Mandatory| Description| -| ---- | -------- | ------ | ---- | ---------------------- | -| uri | Read-only| string | Yes| URI of the file to open.| +| Name| Type| Mandatory| Description| +| ---- | ------ | ---- | ------------------------ | +| uri | string | Yes| URI of the file to open.| -* Return values +**Return value** | Type| Description| -| ----------------- | ------------------------------------------ | +| ----------------- | -------------------------------------------- | | DataAbilityHelper | A utility class used to help other abilities access the Data ability.| -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureAbility' @@ -113,26 +109,20 @@ featureAbility.acquireDataAbilityHelper( ) ``` +## featureAbility.startAbilityForResult +startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\): void -#### FeatureAbility.startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\): void +Starts an ability. This method uses a callback to return the execution result when the ability is destroyed. -* Functionality +**Parameters** - Starts an ability. This method uses a callback to return the execution result when the ability is destroyed. +| Name| Type| Mandatory| Description| +| --------- | ----------------------------------------------- | ---- | --------------------- | +| parameter | [StartAbilityParameter](#startabilityparameter) | Yes| Ability to start.| +| callback | AsyncCallback\<[AbilityResult](#abilityresult)> | Yes| Callback used to return the result.| -* Parameters - -| Name| Readable/Writable| Type| Mandatory| Description| -| --------- | -------- | ---------------------- | ---- | ------------------- | -| parameter | Read-only| [StartAbilityParameter](#StartAbilityParameter)| Yes| Ability to start.| -| callback | Read-only| AsyncCallback\<[AbilityResult](#AbilityResult)>| Yes| Callback used to return the result.| - -* Return values - - Returns [AbilityResult](#AbilityResult). - -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureability'; @@ -153,25 +143,24 @@ featureAbility.startAbilityForResult( ) ``` +## featureAbility.startAbilityForResult +startAbilityForResult(parameter: StartAbilityParameter): Promise\ -#### FeatureAbility.startAbilityForResult(parameter: StartAbilityParameter): Promise\ - -* Functionality +Starts an ability. This method uses a promise to return the execution result when the ability is destroyed. - Starts an ability. This method uses a promise to return the execution result when the ability is destroyed. +**Parameters** -* Parameters +| Name| Type| Mandatory| Description| +| --------- | ----------------------------------------------- | ---- | ------------------- | +| parameter | [StartAbilityParameter](#startabilityparameter) | Yes| Ability to start.| -| Name| Readable/Writable| Type| Mandatory| Description| -| --------- | -------- | ------------------------------------------------------- | ---- | ------------------- | -| parameter | Read-only| [StartAbilityParameter](#StartAbilityParameter)| Yes| Ability to start.| - -* Return values - - Returns [AbilityResult](#AbilityResult). +**Return value** +| Type| Description| +| ----------------------------------------- | -------------- | +| Promise\<[AbilityResult](#abilityresult)> | Promised returned with the execution result.| -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureability'; @@ -206,24 +195,20 @@ featureAbility.startAbilityForResult( }); ``` +## featureAbility.terminateSelfWithResult +terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\): void -#### FeatureAbility.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. -* Functionality +**Parameters** - Destroys this Page ability, with the result code and data sent to the caller. This method uses a callback to return the result. +| Name| Type| Mandatory| Description| +| --------- | ------------- | ---- | ------------------- | +| parameter | [AbilityResult](#abilityresult) | Yes| Ability to start.| +| callback | AsyncCallback\ | Yes| Callback used to return the result.| - -* Parameters - -| Name| Readable/Writable| Type| Mandatory| Description| -| --------- | -------- | ------------- | ---- | ------------------- | -| parameter | Read-only| [AbilityResult](#AbilityResult)| Yes| Ability to start.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| - - -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureAbility' @@ -255,22 +240,24 @@ featureAbility.terminateSelfWithResult( ); ``` +## featureAbility.terminateSelfWithResult +terminateSelfWithResult(parameter: AbilityResult): Promise\ -#### FeatureAbility.terminateSelfWithResult(parameter: AbilityResult): Promise\ - -* Functionality +Destroys this Page ability, with the result code and data sent to the caller. This method uses a promise to return the result. - Destroys this Page ability, with the result code and data sent to the caller. This method uses a promise to return the result. +**Parameters** -* Parameters - -| Name| Readable/Writable| Type| Mandatory| Description| -| --------- | -------- | --------------------------------------- | ---- | ------------------- | -| parameter | Read-only| [AbilityResult](#AbilityResult)| Yes| Ability to start.| +| Name| Type| Mandatory| Description| +| --------- | ------------------------------- | ---- | ------------------- | +| parameter | [AbilityResult](#abilityresult) | Yes| Ability to start.| +**Return value** +| Type| Description| +| -------------- | ----------------------- | +| Promise\ | Promise returned with the result.| -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureability'; @@ -306,23 +293,19 @@ featureAbility.terminateSelfWithResult( -#### FeatureAbility.hasWindowFocus(callback: AsyncCallback\): void +## featureAbility.hasWindowFocus -* Functionality +hasWindowFocus(callback: AsyncCallback\): void - Checks whether the main window of this ability has the focus. This method uses a callback to return the result. +Checks whether the main window of this ability has the focus. This method uses a callback to return the result. -* Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | ----------------------- | ---- | ---------------- | -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| - -* Return values +| Name| Type| Mandatory| Description| +| -------- | ----------------------- | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback\ | Yes| Callback used to return the result.
Returns **true** if the main window of this ability has the focus; returns **false** otherwise.| - Returns **true** if the main window of this ability has the focus; returns **false** otherwise. - -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureability'; @@ -331,21 +314,19 @@ featureAbility.hasWindowFocus() -#### FeatureAbility.hasWindowFocus(): Promise\ - -* Functionality +## featureAbility.hasWindowFocus - Checks whether the main window of this ability has the focus. This method uses a promise to return the result. +hasWindowFocus(): Promise\ -* Parameters +Checks whether the main window of this ability has the focus. This method uses a promise to return the result. - None +**Return value** -* Return values - - Returns **true** if the main window of this ability has the focus; returns **false** otherwise. +| Type| Description| +| ----------------- | ---------------------------------------------------------- | +| Promise\ | Returns **true** if the main window of this ability has the focus; returns **false** otherwise.| -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureability'; @@ -356,20 +337,19 @@ featureAbility.hasWindowFocus().then((void) => { -#### FeatureAbility.getWant(callback: AsyncCallback\) +## featureAbility.getWant -* Functionality +getWant(callback: AsyncCallback\): void - Obtains the **Want** object sent from this ability. This method uses a callback to return the result. +Obtains the **Want** object sent from this ability. This method uses a callback to return the result. -* Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | -------------------- | ---- | ---------------- | -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| -------- | ----------------------------- | ---- | ------------------ | +| callback | AsyncCallback\<[Want](#want)> | Yes| Callback used to return the result.| - -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureability'; @@ -378,17 +358,18 @@ featureAbility.getWant() -#### FeatureAbility.getWant(): void - -* Functionality +## featureAbility.getWant - Obtains the **Want** object sent from this ability. This method uses a promise to return the result. +getWant(): Promise\ -* Parameters +Obtains the **Want** object sent from this ability. This method uses a promise to return the result. - None +**Return value** +| Type| Description| +| ----------------------- | ------------------------- | +| Promise\<[Want](#want)> | Promise returned with the result.| -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureability'; @@ -397,19 +378,18 @@ featureAbility.getWant().then((void) => { }); ``` +## featureAbility.getContext +getContext(): Context -#### FeatureAbility.getContext(): Context - -* Functionality - - Obtains the application context. - -* Return values +Obtains the application context. - Returns the application context. +**Return value** +| Type| Description| +| ------- | -------------------- | +| Context | Application context returned.| -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureability'; @@ -419,19 +399,19 @@ context.getBundleName() -#### FeatureAbility.terminateSelf(callback: AsyncCallback\): void +## featureAbility.terminateSelf -* Functionality +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. +Destroys this Page ability, with the result code and data sent to the caller. This method uses a callback to return the result. -* Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | -------------------- | ---- | ---------------- | -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| -------- | -------------------- | ---- | ---------------- | +| callback | AsyncCallback\ | Yes| Callback used to return the result.| -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureability'; @@ -440,17 +420,18 @@ featureAbility.terminateSelf() -#### FeatureAbility.terminateSelf(): Promise\ +## featureAbility.terminateSelf -* Functionality +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. +Destroys this Page ability, with the result code and data sent to the caller. This method uses a promise to return the result. -* Parameters - - None +**Return value** +| Type| Description| +| -------------- | ------------------------- | +| Promise\ | Promise returned with the result.| -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureability'; @@ -458,20 +439,20 @@ featureAbility.terminateSelf().then((void) => { console.info("============= }); ``` -#### FeatureAbility.connectAbility(request: Want, options:ConnectOptions): number +## featureAbility.connectAbility -* Functionality +connectAbility(request: Want, options:ConnectOptions): number - Connects this ability to a specific Service ability. This method uses a callback to return the result. +Connects this ability to a specific Service ability. This method uses a callback to return the result. -* Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| ------- | -------- | -------------- | ---- | -------------------------- | -| request | Read-only| Want | Yes| Service ability to connect.| -| options | Read-only| ConnectOptions | Yes| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| ------- | -------------- | ---- | ---------------------------- | +| request | [Want](#want) | Yes| Service ability to connect.| +| options | ConnectOptions | Yes| Callback used to return the result.| -* Want parameters +Want | Name| Readable/Writable| Type| Mandatory| Description| | ------------ | -------- | -------- | ---- | ---------------------------------- | @@ -479,7 +460,7 @@ featureAbility.terminateSelf().then((void) => { console.info("============= | 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 +ConnectOptions | Name| Readable/Writable| Type| Mandatory| Description| | ------------ | -------- | -------- | ---- | ---------------------------------- | @@ -487,11 +468,12 @@ featureAbility.terminateSelf().then((void) => { console.info("============= | 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 values - - Returns the ID of the Service ability connected. +**Return value** +| Type| Description| +| ------ | ------------------------ | +| number | Returns the ID of the Service ability connected.| -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureAbility' @@ -518,20 +500,20 @@ var connId = featureAbility.connectAbility( ); ``` -#### FeatureAbility.disconnectAbility(connection: number, callback:AsyncCallback\): void +## featureAbility.disconnectAbility -* Functionality +disconnectAbility(connection: number, callback:AsyncCallback\): void - Disconnects this ability from a specific Service ability. This method uses a callback to return the result. +Disconnects this ability from a specific Service ability. This method uses a callback to return the result. -* Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| ---------- | -------- | ------------- | ---- | ------------------------------ | -| connection | Read-only| number | Yes| ID of the Service ability to disconnect.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| ---------- | ------------- | ---- | ------------------------------ | +| connection | number | Yes| ID of the Service ability to disconnect.| +| callback | AsyncCallback\ | Yes| Callback used to return the result.| -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureAbility' @@ -562,19 +544,24 @@ var result = featureAbility.disconnectAbility(connId, ); ``` -#### FeatureAbility.disconnectAbility(connection: number): Promise\ +## featureAbility.disconnectAbility -* Functionality +disconnectAbility(connection: number): Promise\ - Disconnects this ability from a specific Service ability. This method uses a promise to return the result. +Disconnects this ability from a specific Service ability. This method uses a promise to return the result. -* Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| ---------- | -------- | ------ | ---- | ------------------------------ | -| connection | Read-only| number | Yes| ID of the Service ability to disconnect.| +| Name| Type| Mandatory| Description| +| ---------- | ------ | ---- | ------------------------------ | +| connection | number | Yes| ID of the Service ability to disconnect.| + +**Return value** +| Type| Description| +| -------------- | ----------------------- | +| Promise\ | Promise returned with the result.| -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureAbility' @@ -601,28 +588,27 @@ var connId = featureAbility.connectAbility( var result = await featureAbility.disconnectAbility(connId); ``` +## featureAbility.continueAbility -#### FeatureAbility.continueAbility(options: ContinueAbilityOptions, callback: AsyncCallback\): void; - -* Functionality +continueAbility(options: ContinueAbilityOptions, callback: AsyncCallback\): void - Migrates an ability to another device. This method uses a callback to return the execution result. +Migrates an ability to another device. This method uses a callback to return the execution result. -* Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | ---------------------- | ---- | ------------------- | -| options | Read-only| ContinueAbilityOptions | Yes| Ability to migrate.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| -------- | ---------------------- | ---- | ------------------- | +| options | ContinueAbilityOptions | Yes| Ability to migrate.| +| callback | AsyncCallback\ | Yes| Callback used to return the result.| -- ContinueAbilityOptions +ContinueAbilityOptions | Name| Readable/Writable| Type| Mandatory| Description| -| ---------- | -------- | ------- | ---- | ----------------------------------------------------------- | +| ---------- | -------- | ------- | ---- | ------------------------------------------------------------ | | deviceId | Read-only| string | Yes| Information about the ability to migrate.| | reversible | Read-only| boolean | Yes| Whether migration back is supported. Currently, this feature is not supported. This parameter is reserved and can be set to **false**.| -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureAbility' @@ -642,21 +628,21 @@ async StartContinueAbility(deviceId) { this.StartContinueAbility(remoteDeviceId); //remoteDeviceId is acquired from DeviceManager ``` -#### AbilityResult +## AbilityResult | 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.| -| 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**.| +| 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**.| -#### StartAbilityParameter +## StartAbilityParameter | Name| Readable/Writable| Type| Mandatory| Description| -| ------------------- | -------- | --------------------- | ---- | ------------------------------------------------------------ | -| 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 | 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 +## Want | Name| Readable/Writable| Type| Mandatory| Description| | ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ | diff --git a/en/application-dev/reference/apis/js-apis-particleAbility.md b/en/application-dev/reference/apis/js-apis-particleAbility.md index 9d4a14ccbe..9704897e75 100644 --- a/en/application-dev/reference/apis/js-apis-particleAbility.md +++ b/en/application-dev/reference/apis/js-apis-particleAbility.md @@ -10,25 +10,21 @@ The ParticleAbility module is used to perform operations on abilities of the Dat import particleAbility from '@ohos.ability.particleAbility' ``` -## particleAbility.startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\: void +## particleAbility.startAbility -- Functionality +startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\: void - Starts a Service ability. This method uses a callback to return the result. +Starts a Service ability. This method uses a callback to return the result. -- Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| --------- | -------- | ------------------------------------------------------- | ---- | ----------------- | -| parameter | Read-only| [StartAbilityParameter](#StartAbilityParameter)| Yes| Ability to start.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| - -- Return values +| Name| Type| Mandatory| Description| +| --------- | ----------------------------------------------- | ---- | ----------------- | +| parameter | [StartAbilityParameter](#startabilityparameter) | Yes| Ability to start.| +| callback | AsyncCallback\ | Yes| Callback used to return the result.| - void - -- Example +**Example** ```js import particleAbility from '@ohos.ability.particleAbility' @@ -54,22 +50,23 @@ particleAbility.startAbility( -## particleAbility.startAbility(parameter: StartAbilityParameter): Promise\ +## particleAbility.startAbility -- Functionality +startAbility(parameter: StartAbilityParameter): Promise\ Starts a Service ability. This method uses a promise to return the result. -- Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| --------- | -------- | ------------------------------------------------------- | ---- | ----------------- | -| parameter | Read-only| [StartAbilityParameter](#StartAbilityParameter)| Yes| Ability to start.| -- Return values - - Promise\ +| Name| Type| Mandatory| Description| +| --------- | ----------------------------------------------- | ---- | ----------------- | +| parameter | [StartAbilityParameter](#startabilityparameter) | Yes| Ability to start.| +**Return value** +| Type| Description| +| -------------- | ------------------------- | +| Promise\ | Promise returned with the result.| -- Example +**Example** ```js import particleAbility from '@ohos.ability.particleAbility' @@ -94,23 +91,19 @@ particleAbility.startAbility( -## particleAbility.terminateSelf(callback: AsyncCallback\): void +## particleAbility.terminateSelf -- Functionality +terminateSelf(callback: AsyncCallback\): void - Terminates this Service ability. This method uses a callback to return the result. +Terminates this Service ability. This method uses a callback to return the result. -- Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| -------- | -------- | -------------------- | ---- | -------------------- | -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| -------- | -------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes| Callback used to return the result.| -- Return values - - void - -- Example +**Example** ```js import particleAbility from '@ohos.ability.particleAbility' @@ -123,17 +116,18 @@ particleAbility.terminateSelf( -## particleAbility.terminateSelf(): Promise\ - -- Functionality +## particleAbility.terminateSelf - Terminates this Service ability. This method uses a promise to return the result. +terminateSelf(): Promise\ -- Return values +Terminates this Service ability. This method uses a promise to return the result. - Promise\ +**Return value** +| Type| Description| +| -------------- | ------------------------- | +| Promise\ | Promise returned with the result.| -- Example +**Example** ```js import particleAbility from '@ohos.ability.particleAbility' @@ -144,25 +138,25 @@ particleAbility.terminateSelf().then((void) => { -## particleAbility.acquireDataAbilityHelper(uri: string): DataAbilityHelper +## particleAbility.acquireDataAbilityHelper -- Functionality +acquireDataAbilityHelper(uri: string): DataAbilityHelper - Obtains a **dataAbilityHelper** object. +Obtains a **dataAbilityHelper** object. -- Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| :--- | -------- | ------ | ---- | ---------------------- | -| uri | Read-only| string | Yes| URI of the file to open.| +| Name| Type| Mandatory| Description| +| :--- | ------ | ---- | ------------------------ | +| uri | string | Yes| URI of the file to open.| -- Return values +**Return value** | Type| Description| -| ----------------- | ------------------------------------------ | +| ----------------- | -------------------------------------------- | | DataAbilityHelper | A utility class used to help other abilities access a Data ability.| -- Example +**Example** ```js import particleAbility from '@ohos.ability.particleAbility' @@ -170,20 +164,20 @@ var uri = ""; particleAbility.acquireDataAbilityHelper(uri) ``` -## particleAbility.connectAbility(request: Want, options:ConnectOptions): number +## particleAbility.connectAbility -* Functionality +connectAbility(request: Want, options:ConnectOptions): number - Connects this ability to a specific Service ability. This method uses a callback to return the result. +Connects this ability to a specific Service ability. This method uses a callback to return the result. -* Parameters +**Parameters** -| Name| Readable/Writable| Type| Mandatory| Description| -| ------- | -------- | -------------- | ---- | -------------------------- | -| request | Read-only| Want | Yes| Service ability to connect.| -| options | Read-only| ConnectOptions | Yes| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| ------- | -------------- | ---- | -------------------------- | +| request | [Want](#want) | Yes| Service ability to connect.| +| options | ConnectOptions | Yes| Callback used to return the result.| -- ConnectOptions +ConnectOptions | Name| Readable/Writable| Type| Mandatory| Description| | ------------ | -------- | -------- | ---- | ---------------------------------- | @@ -191,11 +185,12 @@ particleAbility.acquireDataAbilityHelper(uri) | onDisconnect | Read-only| function | Yes| Callback invoked when the connection is interrupted.| | onFailed | Read-only| function | Yes| Callback invoked when the connection fails.| -* Return values - - Returns the unique identifier of the connection. +**Return value** +| Type| Description| +| ------ | -------------------------- | +| number | Unique identifier of the connection between the client and the service side.| -* Example +**Example** ```javascript import particleAbility from '@ohos.ability.particleAbility' @@ -221,24 +216,20 @@ var connId = particleAbility.connectAbility( ); ``` -## particleAbility.disconnectAbility(connection: number, callback:AsyncCallback\): void - -* Functionality +## particleAbility.disconnectAbility - Disconnects this ability from a specific Service ability. This method uses a callback to return the result. +disconnectAbility(connection: number, callback:AsyncCallback\): void -* Parameters +Disconnects this ability from a specific Service ability. This method uses a callback to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| ---------- | -------- | ------------- | ---- | ------------------------------ | -| connection | Read-only| number | Yes| ID of the Service ability to disconnect.| -| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| - -* Return values +**Parameters** - void +| Name| Type| Mandatory| Description| +| ---------- | ------------- | ---- | ------------------------------ | +| connection | number | Yes| ID of the Service ability to disconnect.| +| callback | AsyncCallback\ | Yes| Callback used to return the result.| -* Example +**Example** ```javascript import particleAbility from '@ohos.ability.particleAbility' @@ -269,23 +260,24 @@ var result = particleAbility.disconnectAbility(connId, ); ``` -## particleAbility.disconnectAbility(connection: number): Promise\ - -* Functionality +## particleAbility.disconnectAbility - Disconnects this ability from a specific Service ability. This method uses a promise to return the result. +disconnectAbility(connection: number): Promise\ -* Parameters +Disconnects this ability from a specific Service ability. This method uses a promise to return the result. -| Name| Readable/Writable| Type| Mandatory| Description| -| ---------- | -------- | ------ | ---- | ------------------------------ | -| connection | Read-only| number | Yes| ID of the Service ability to disconnect.| +**Parameters** -* Return values +| Name| Type| Mandatory| Description| +| ---------- | ------ | ---- | ------------------------------ | +| connection | number | Yes| ID of the Service ability to disconnect.| - Promise\ +**Return value** +| Type| Description| +| -------------- | ------------------------- | +| Promise\ | Promise returned with the result.| -* Example +**Example** ```javascript import particleAbility from '@ohos.ability.particleAbility' @@ -318,7 +310,7 @@ var result = particleAbility.disconnectAbility(connId).then((void) => { | Name| Readable/Writable| Type| Mandatory| Description| | ------------------- | -------- | --------------------- | ---- | ------------------------------------------------------------ | -| want | Read-only| [Want](#Want)| Yes| Information about the ability to start.| +| 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 @@ -358,10 +350,10 @@ var result = particleAbility.disconnectAbility(connId).then((void) => { ## AbilityStartSetting -Defines special attributes of an ability, for example, **featureAbility.AbilityStartSetting.BOUNDS_KEY**. - 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.| diff --git a/zh-cn/application-dev/reference/apis/js-apis-featureAbility.md b/zh-cn/application-dev/reference/apis/js-apis-featureAbility.md index a0d8e9a415..33d2be271c 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-featureAbility.md +++ b/zh-cn/application-dev/reference/apis/js-apis-featureAbility.md @@ -662,18 +662,18 @@ this.StartContinueAbility(remoteDeviceId); //remoteDeviceId is acquired from Dev | ------------------------------------ | ---------- | ------------------------------------------------------------ | | FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | 指示对URI执行读取操作的授权 | | FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | 指示对URI执行写入操作的授权 | -| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | 将结果返回给源能力 | +| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | 将结果返回给元能力 | | FLAG_ABILITY_CONTINUATION | 0x00000008 | 确定是否可以将本地设备上的功能迁移到远程设备 | | FLAG_NOT_OHOS_COMPONENT | 0x00000010 | 指定组件是否属于OHOS | | FLAG_ABILITY_FORM_ENABLED | 0x00000020 | 指定是否启动某个能力 | | FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | 指示URI上可能持久化的授权 | -| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | 指示对URI前缀进行授权的权限 | +| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | 按照前缀匹配的方式验证URI权限 | | FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | 支持分布式调度系统中的多设备启动 | | FLAG_START_FOREGROUND_ABILITY | 0x00000200 | 指示无论主机应用程序是否已启动,都将启动使用服务模板的功能 | | FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | 表示迁移是可拉回的。 | | FLAG_INSTALL_ON_DEMAND | 0x00000800 | 如果未安装指定的功能,请安装该功能 | | FLAG_INSTALL_WITH_BACKGROUND_MODE | 0x80000000 | 如果未安装,使用后台模式安装该功能。 | -| FLAG_ABILITY_CLEAR_MISSION | 0x00008000 | 指示清除其他任务的操作。可以为传递给{@link ohos.app.Context#startAbility}的{@code Want}设置此标志,并且必须与{@link flag_ABILITY_NEW_MISSION}一起使用 | +| FLAG_ABILITY_CLEAR_MISSION | 0x00008000 | 指示清除其他任务的操作。可以为传递给**ohos.app.Context#startAbility**的**Want**设置此标志,并且必须与**flag_ABILITY_NEW_MISSION**一起使用 | | FLAG_ABILITY_NEW_MISSION | 0x10000000 | 指示在历史任务堆栈上创建任务的操作。 | | FLAG_ABILITY_MISSION_TOP | 0x20000000 | 指示如果启动能力的现有实例已位于任务堆栈的顶部,则将重用该实例。否则,将创建一个新的能力实例。 | diff --git a/zh-cn/application-dev/reference/apis/js-apis-particleAbility.md b/zh-cn/application-dev/reference/apis/js-apis-particleAbility.md index 0e2cad1377..7850f79370 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-particleAbility.md +++ b/zh-cn/application-dev/reference/apis/js-apis-particleAbility.md @@ -333,12 +333,12 @@ var result = particleAbility.disconnectAbility(connId).then((void) => { | ------------------------------------ | ---------- | ------------------------------------------------------------ | | FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | 指示对URI执行读取操作的授权 | | FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | 指示对URI执行写入操作的授权 | -| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | 将结果返回给源能力 | +| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | 将结果返回给元能力 | | FLAG_ABILITY_CONTINUATION | 0x00000008 | 确定是否可以将本地设备上的功能迁移到远程设备 | | FLAG_NOT_OHOS_COMPONENT | 0x00000010 | 指定组件是否属于OHOS | | FLAG_ABILITY_FORM_ENABLED | 0x00000020 | 指定是否启动某个能力 | | FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | 指示URI上可能持久化的授权 | -| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | 将结果返回到源能力 | +| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | 按照前缀匹配的方式验证URI权限 | | FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | 支持分布式调度系统中的多设备启动 | | FLAG_START_FOREGROUND_ABILITY | 0x00000200 | 指示无论主机应用程序是否已启动,都将启动使用服务模板的功能 | | FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | 表示迁移是可拉回的。 | -- GitLab