From 9a8fb2dfa4c47b631b16869409f7cf935400a144 Mon Sep 17 00:00:00 2001 From: wusongqing Date: Thu, 27 Jan 2022 19:46:52 +0800 Subject: [PATCH] updated docs Signed-off-by: wusongqing --- .../reference/apis/Readme-EN.md | 9 + .../reference/apis/js-apis-Context.md | 559 +++ .../reference/apis/js-apis-DataUriUtils.md | 117 + .../reference/apis/js-apis-commonEvent.md | 871 +++++ .../reference/apis/js-apis-featureAbility.md | 32 +- .../reference/apis/js-apis-notification.md | 3267 +++++++++++++++++ .../reference/apis/js-apis-particleAbility.md | 394 ++ 7 files changed, 5233 insertions(+), 16 deletions(-) create mode 100644 en/application-dev/reference/apis/js-apis-Context.md create mode 100644 en/application-dev/reference/apis/js-apis-DataUriUtils.md create mode 100644 en/application-dev/reference/apis/js-apis-commonEvent.md create mode 100644 en/application-dev/reference/apis/js-apis-notification.md create mode 100644 en/application-dev/reference/apis/js-apis-particleAbility.md diff --git a/en/application-dev/reference/apis/Readme-EN.md b/en/application-dev/reference/apis/Readme-EN.md index 4638d0eecb..e5eeb0eb1f 100644 --- a/en/application-dev/reference/apis/Readme-EN.md +++ b/en/application-dev/reference/apis/Readme-EN.md @@ -1,5 +1,13 @@ # APIs +- Ability Framework + - [FeatureAbility Module](js-apis-featureAbility.md) + - [ParticleAbility Module](js-apis-particleAbility.md) + - [DataUriUtils Module](js-apis-DataUriUtils.md) + - [Context Module](js-apis-Context.md) +- Event Notification + - [CommonEvent Module](js-apis-commonEvent.md) + - [Notification Module](js-apis-notification.md) - Resource Management - [Resource Manager](js-apis-resource-manager.md) - [Internationalization \(intl\) ](js-apis-intl.md) @@ -47,6 +55,7 @@ - [Animation](js-apis-basic-features-animator.md) - [HiAppEvent](js-apis-hiappevent.md) - [Performance Tracing](js-apis-bytrace.md) + - [Fault Logger](js-apis-faultLogger.md) - Language Base Class Library - [Obtaining Process Information](js-apis-process.md) - [URL String Parsing](js-apis-url.md) diff --git a/en/application-dev/reference/apis/js-apis-Context.md b/en/application-dev/reference/apis/js-apis-Context.md new file mode 100644 index 0000000000..e2b51f2e3c --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-Context.md @@ -0,0 +1,559 @@ +# Context Module + +## Applicable Devices + +| API | Phone| Tablet| Smart TV| Wearable| Lite Wearable| SmartVision Device| +| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -------------- | ------------ | +| Context.getOrCreateLocalDir(callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| +| Context.getOrCreateLocalDir() | Yes| Yes| Yes| Yes| No| No| +| Context.verifyPermission(permission: string, options: PermissionOptions, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| +| Context.verifyPermission(permission: string, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| +| Context.verifyPermission(permission: string, options?: PermissionOptions) | Yes| Yes| Yes| Yes| No| No| +| Context.requestPermissionsFromUser(permissions: Array\, requestCode: number, resultCallback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| +| Context.getApplicationInfo(callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| +| Context.getApplicationInfo() | Yes| Yes| Yes| Yes| No| No| +| Context.getBundleName(callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| +| Context.getBundleName() | Yes| Yes| Yes| Yes| No| No| +| Context.getProcessInfo(callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| +| Context.getProcessInfo() | Yes| Yes| Yes| Yes| No| No| +| Context.getElementName(callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| +| Context.getElementName() | Yes| Yes| Yes| Yes| No| No| +| Context.getProcessName(callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| +| Context.getProcessName() | Yes| Yes| Yes| Yes| No| No| +| Context.getCallingBundle(callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| No| +| Context.getCallingBundle() | Yes| Yes| Yes| Yes| No| No| + +## Modules to Import + +```js +import featureAbility from '@ohos.ability.featureAbility' +import bundle from '@ohos.bundle' +``` + +The **Context** object is created in a **featureAbility** and returned through its **getContext()** method. Therefore, you must import the **@ohos.ability.featureAbility** package before using the Context module. An example is as follows: + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getOrCreateLocalDir() +``` + +## Context.getOrCreateLocalDir(callback: AsyncCallback) + +- Functionality + + 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. + +- Parameters + + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | ---------------------- | ---- | ------------------------ | +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the local root directory of the application.| + +- Return values + + void + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getOrCreateLocalDir((err, data)=>{ + console.info("data=" + data); +}) +``` + + + +## Context.getOrCreateLocalDir() + +- Functionality + + 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. + +- Parameters + + None + +- Return values + + | Type| Description| + | --------------- | -------------------- | + | Promise | Promise used to return the local root directory of the application.| + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getOrCreateLocalDir().then((void) => { + console.info("==========================>getOrCreateLocalDirCallback=======================>"); +}); +``` + +## 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) + +- Functionality + + Verifies whether a specific 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.| +| 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 + + void + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +import bundle from '@ohos.bundle' +var context = featureAbility.getContext(); +var datainfo = await bundle.getBundleInfo('com.context.test',1); +context.verifyPermission("com.example.permission",datainfo.uid) + +``` + + + +## Context.verifyPermission(permission: string, callback: AsyncCallback) + +- Functionality + + 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 + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.verifyPermission("com.example.permission") +``` + + + +## Context.verifyPermission(permission: string, options?: PermissionOptions) + +- Functionality + + Verifies whether a specific PID and UID have the given permission. This method uses a promise to return the result. + +- Parameters + + +| 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.| + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +var Permission = context.PermissionOptions(1,1); +context.getOrCreateLocalDir('com.context.permission',Permission).then((void) => { + console.info("==========================>verifyPermissionCallback=======================>"); +}); +``` + +## 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 + + 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 + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getOrCreateLocalDir( + ["com.example.permission1", + "com.example.permission2", + "com.example.permission3", + "com.example.permission4", + "com.example.permission5"], + 1, +) +``` + + + +## Context.getApplicationInfo(callback: AsyncCallback) + +- Functionality + + Obtains information about the current application. This method uses a callback to return the result. + +- Parameters + + | Name| Readable/Writable| Type| Mandatory| Description| + | -------- | -------- | ------------------------------- | ---- | ---------------------- | + | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the application information.| + +- Return values + + void + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getApplicationInfo() +``` + + + +## Context.getApplicationInfo + +- Functionality + + Obtains information about the current application. This method uses a promise to return the result. + +- Parameters + + None + +- Return values + + | Type| Description| + | ------------------------ | ------------------ | + | Promise | Promise used to return the application information.| + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getApplicationInfo().then((void) => { + console.info("==========================>getApplicationInfoCallback=======================>"); +}); +``` + + + +## Context.getBundleName(callback: AsyncCallback) + +- Functionality + + Obtains the bundle name of the current ability. This method uses a callback to return the result. + +- Parameters + + | Name| Readable/Writable| Type| Mandatory| Description| + | -------- | -------- | ---------------------- | ---- | --------------------------- | + | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the bundle name.| + +- Return values + + void + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getBundleName() +``` + + + +## Context.getBundleName + +- Functionality + + Obtains the bundle name of the current ability. This method uses a promise to return the result. + +- Parameters + + None + +- Return values + + | Type| Description| + | --------------- | ----------------------- | + | Promise | Promise used to return the bundle name.| + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getBundleName().then((void) => { + console.info("==========================>getBundleNameCallback=======================>"); +}); +``` + + + +## Context.getProcessInfo(callback: AsyncCallback) + +- Functionality + + Obtains information about the current process, including the PID and process name. This method uses a callback to return the result. + +- Parameters + + | Name| Readable/Writable| Type| Mandatory| Description| + | -------- | -------- | --------------------------- | ---- | ------------------ | + | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the process information.| + +- Return values + + void + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getProcessInfo() +``` + + + +## Context.getProcessInfo + +- Functionality + + Obtains information about the current process, including the PID and process name. This method uses a promise to return the result. + +- Parameters + + None + +- Return values + + | Type| Description| + | -------------------- | -------------- | + | Promise | Promise used to return the process information.| + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getProcessInfo().then((void) => { + console.info("==========================>getProcessInfoCallback=======================>"); +}); +``` + + + +## Context.getElementName(callback: AsyncCallback) + +- Functionality + + 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. + +- Parameters + + | Name| Readable/Writable| Type| Mandatory| Description| + | -------- | -------- | --------------------------- | ---- | -------------------------------------------- | + | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the **ohos.bundle.ElementName** object.| + +- Return values + + void + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getElementName() +``` + + + +## Context.getElementName + +- Functionality + + 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. + +- Parameters + + None + +- Return values + + | Type| Description| + | -------------------- | ---------------------------------------- | + | Promise | Promise used to return the **ohos.bundle.ElementName** object.| + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getElementName().then((void) => { + console.info("==========================>getElementNameCallback=======================>"); +}); +``` + +## **Context.getProcessName(callback: AsyncCallback)** + +- Functionality + + Obtains the name of the current process. This method uses a callback to return the result. + +- Parameters + + | Name| Readable/Writable| Type| Mandatory| Description| + | -------- | -------- | ---------------------- | ---- | ------------------ | + | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the process name.| + +- Return values + + void + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getProcessName() +``` + + + +## Context.getProcessName + +- Functionality + + Obtains the name of the current process. This method uses a promise to return the result. + +- Parameters + + None + +- Return values + + | Type| Description| + | --------------- | -------------- | + | Promise | Promise used to return the process name.| + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getProcessName().then((void) => { + console.info("==========================>getProcessNameCallback=======================>"); +}); +``` + + + +## Context.getCallingBundle(callback: AsyncCallback) + +- Functionality + + Obtains the bundle name of the calling ability. This method uses a callback to return the result. + +- Parameters + + | Name| Readable/Writable| Type| Mandatory| Description| + | -------- | -------- | ---------------------- | ---- | ------------------------- | + | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the bundle name.| + +- Return values + + void + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getCallingBundle() +``` + + + +## Context.getCallingBundle + +- Functionality + + Obtains the bundle name of the calling ability. This method uses a promise to return the result. + +- Parameters + + None + +- Return values + + | Type| Description| + | --------------- | ------------------------- | + | Promise | Promise used to return the bundle name.| + + + +- Example + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getCallingBundle().then((void) => { + console.info("==========================>getCallingBundleCallback=======================>"); +}); +``` diff --git a/en/application-dev/reference/apis/js-apis-DataUriUtils.md b/en/application-dev/reference/apis/js-apis-DataUriUtils.md new file mode 100644 index 0000000000..494c24532e --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-DataUriUtils.md @@ -0,0 +1,117 @@ +# DataUriUtils Module + +## Modules to Import + +```js +import dataUriUtils from '@ohos.ability.dataUriUtils'; +``` + +## DataUriUtils.getId + +- Functionality + + Obtains the ID attached to the end of a given URI. + +- Parameters + + +| Name| Readable/Writable| Type| Mandatory| Description| +| ---- | -------- | ------ | ---- | ------------------------- | +| uri | Read-only| string | Yes| URI object from which the ID is to be obtained.| + +- Return values + + Returns the ID obtained from the URI object. + +- Example + +```js +import dataUriUtils from '@ohos.ability.datauriutils' +dataUriUtils.getIdSync("com.example.dataUriUtils/1221") +``` + + + +## DataUriUtils.attachId + +- Functionality + + 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 + + Returns the URI object with the ID attached. + +- Example + +```js +import dataUriUtils from '@ohos.ability.datauriutils' +var idint = 1122; +dataUriUtils.attachId( + "com.example.dataUriUtils" + idint, +) +``` + + + +## DataUriUtils.deleteId + +- Functionality + + Deletes the ID from the end of a given URI. + +- Parameters + + | Name| Readable/Writable| Type| Mandatory| Description| + | ---- | -------- | ------ | ---- | ------------------------- | + | uri | Read-only| string | Yes| URI object from which the ID is to be deleted.| + +- Return values + + Returns the URI object with the ID deleted. + +- Example + +```js +import dataUriUtils from '@ohos.ability.datauriutils' +dataUriUtils.deleteId("com.example.dataUriUtils/1221") +``` + + + +## DataUriUtils.updateId + +- Functionality + + Updates the ID in a given URI. + +- Parameters + + | Name| Readable/Writable| Type| Mandatory| Description| + | ---- | -------- | ------ | ---- | ------------------- | + | uri | Read-only| string | Yes| URI object to be updated.| + | id | Read-only| number | Yes| New ID.| + +- Return values + + Returns the URI object with the new ID. + +- Example + +```js +import dataUriUtils from '@ohos.ability.datauriutils' +var idint = 1122; +dataUriUtils.updateId( + "com.example.dataUriUtils" + idint, +) +``` diff --git a/en/application-dev/reference/apis/js-apis-commonEvent.md b/en/application-dev/reference/apis/js-apis-commonEvent.md new file mode 100644 index 0000000000..e3f7238a12 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-commonEvent.md @@ -0,0 +1,871 @@ +# 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. + +## Applicable Devices + +| API | Phone| Tablet| Smart TV| Wearable| Lite Wearable| +| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -------------- | +| CommonEvent.publish(event: string, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| +| CommonEvent.publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| +| CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| +| CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo) | Yes| Yes| Yes| Yes| No| +| CommonEvent.subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\) | Yes| Yes| Yes| Yes| No| +| CommonEvent.unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\) | Yes| Yes| Yes| Yes| No| + +## 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| +| COMMON_EVENT_BATTERY_LOW | usual.event.BATTERY_LOW | N/A| +| COMMON_EVENT_BATTERY_OKAY | usual.event.BATTERY_OKAY | N/A| +| COMMON_EVENT_POWER_CONNECTED | usual.event.POWER_CONNECTED | N/A| +| COMMON_EVENT_POWER_DISCONNECTED | usual.event.POWER_DISCONNECTED | N/A| +| COMMON_EVENT_SCREEN_OFF | usual.event.SCREEN_OFF | N/A| +| COMMON_EVENT_SCREEN_ON | usual.event.SCREEN_ON | N/A| +| COMMON_EVENT_USER_PRESENT | usual.event.USER_PRESENT | N/A| +| COMMON_EVENT_TIME_TICK | usual.event.TIME_TICK | N/A| +| COMMON_EVENT_TIME_CHANGED | usual.event.TIME_CHANGED | N/A| +| COMMON_EVENT_DATE_CHANGED | usual.event.DATE_CHANGED | N/A| +| COMMON_EVENT_TIMEZONE_CHANGED | usual.event.TIMEZONE_CHANGED | N/A| +| COMMON_EVENT_CLOSE_SYSTEM_DIALOGS | usual.event.CLOSE_SYSTEM_DIALOGS | N/A| +| COMMON_EVENT_PACKAGE_ADDED | usual.event.PACKAGE_ADDED | N/A| +| COMMON_EVENT_PACKAGE_REPLACED | usual.event.PACKAGE_REPLACED | N/A| +| COMMON_EVENT_MY_PACKAGE_REPLACED | usual.event.MY_PACKAGE_REPLACED | N/A| +| COMMON_EVENT_PACKAGE_REMOVED | usual.event.PACKAGE_REMOVED | N/A| +| COMMON_EVENT_PACKAGE_FULLY_REMOVED | usual.event.PACKAGE_FULLY_REMOVED | N/A| +| COMMON_EVENT_PACKAGE_CHANGED | usual.event.PACKAGE_CHANGED | N/A| +| COMMON_EVENT_PACKAGE_RESTARTED | usual.event.PACKAGE_RESTARTED | N/A| +| COMMON_EVENT_PACKAGE_DATA_CLEARED | usual.event.PACKAGE_DATA_CLEARED | N/A| +| COMMON_EVENT_PACKAGES_SUSPENDED | usual.event.PACKAGES_SUSPENDED | N/A| +| COMMON_EVENT_PACKAGES_UNSUSPENDED | usual.event.PACKAGES_UNSUSPENDED | N/A| +| COMMON_EVENT_MY_PACKAGE_SUSPENDED | usual.event.MY_PACKAGE_SUSPENDED | N/A| +| COMMON_EVENT_MY_PACKAGE_UNSUSPENDED | usual.event.MY_PACKAGE_UNSUSPENDED | N/A| +| COMMON_EVENT_UID_REMOVED | usual.event.UID_REMOVED | N/A| +| COMMON_EVENT_PACKAGE_FIRST_LAUNCH | usual.event.PACKAGE_FIRST_LAUNCH | N/A| +| COMMON_EVENT_PACKAGE_NEEDS_VERIFICATION | usual.event.PACKAGE_NEEDS_VERIFICATION | N/A| +| COMMON_EVENT_PACKAGE_VERIFIED | usual.event.PACKAGE_VERIFIED | N/A| +| COMMON_EVENT_EXTERNAL_APPLICATIONS_AVAILABLE | usual.event.EXTERNAL_APPLICATIONS_AVAILABLE | N/A| +| COMMON_EVENT_EXTERNAL_APPLICATIONS_UNAVAILABLE | usual.event.EXTERNAL_APPLICATIONS_UNAVAILABLE | N/A| +| COMMON_EVENT_CONFIGURATION_CHANGED | usual.event.CONFIGURATION_CHANGED | N/A| +| COMMON_EVENT_LOCALE_CHANGED | usual.event.LOCALE_CHANGED | N/A| +| COMMON_EVENT_MANAGE_PACKAGE_STORAGE | usual.event.MANAGE_PACKAGE_STORAGE | N/A| +| COMMON_EVENT_DRIVE_MODE | common.event.DRIVE_MODE | N/A| +| COMMON_EVENT_HOME_MODE | common.event.HOME_MODE | N/A| +| COMMON_EVENT_OFFICE_MODE | common.event.OFFICE_MODE | N/A| +| COMMON_EVENT_USER_STARTED | usual.event.USER_STARTED | N/A| +| COMMON_EVENT_USER_BACKGROUND | usual.event.USER_BACKGROUND | N/A| +| COMMON_EVENT_USER_FOREGROUND | usual.event.USER_FOREGROUND | N/A| +| COMMON_EVENT_USER_SWITCHED | usual.event.USER_SWITCHED | ohos.permission.MANAGE_USERS | +| COMMON_EVENT_USER_UNLOCKED | usual.event.USER_UNLOCKED | N/A| +| COMMON_EVENT_USER_STOPPED | usual.event.USER_STOPPED | N/A| +| COMMON_EVENT_HWID_LOGIN | common.event.HWID_LOGIN | N/A| +| COMMON_EVENT_HWID_LOGOUT | common.event.HWID_LOGOUT | N/A| +| COMMON_EVENT_HWID_TOKEN_INVALID | common.event.HWID_TOKEN_INVALID | N/A| +| COMMON_EVENT_HWID_LOGOFF | common.event.HWID_LOGOFF | N/A| +| COMMON_EVENT_WIFI_POWER_STATE | usual.event.wifi.POWER_STATE | N/A| +| COMMON_EVENT_WIFI_SCAN_FINISHED | usual.event.wifi.SCAN_FINISHED | ohos.permission.LOCATION | +| COMMON_EVENT_WIFI_RSSI_VALUE | usual.event.wifi.RSSI_VALUE | ohos.permission.GET_WIFI_INFO | +| COMMON_EVENT_WIFI_CONN_STATE | usual.event.wifi.CONN_STATE | N/A| +| COMMON_EVENT_WIFI_HOTSPOT_STATE | usual.event.wifi.HOTSPOT_STATE | N/A| +| COMMON_EVENT_WIFI_AP_STA_JOIN | usual.event.wifi.WIFI_HS_STA_JOIN | ohos.permission.GET_WIFI_INFO | +| COMMON_EVENT_WIFI_AP_STA_LEAVE | usual.event.wifi.WIFI_HS_STA_LEAVE | ohos.permission.GET_WIFI_INFO | +| COMMON_EVENT_WIFI_P2P_CONN_STATE | usual.event.wifi.p2p.CONN_STATE_CHANGE | ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION | +| COMMON_EVENT_WIFI_P2P_STATE_CHANGED | usual.event.wifi.p2p.STATE_CHANGE | ohos.permission.GET_WIFI_INFO | +| COMMON_EVENT_WIFI_P2P_PEERS_STATE_CHANGED | usual.event.wifi.p2p.DEVICES_CHANGE | ohos.permission.GET_WIFI_INFO | +| COMMON_EVENT_WIFI_P2P_PEERS_DISCOVERY_STATE_CHANGED | usual.event.wifi.p2p.PEER_DISCOVERY_STATE_CHANGE | ohos.permission.GET_WIFI_INFO | +| COMMON_EVENT_WIFI_P2P_CURRENT_DEVICE_STATE_CHANGED | usual.event.wifi.p2p.CURRENT_DEVICE_CHANGE | ohos.permission.GET_WIFI_INFO | +| COMMON_EVENT_WIFI_P2P_GROUP_STATE_CHANGED | usual.event.wifi.p2p.GROUP_STATE_CHANGED | ohos.permission.GET_WIFI_INFO | +| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsource.AVRCP_CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_SDP_RESULT | usual.event.bluetooth.remotedevice.SDP_RESULT | N/A| +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_CANCEL | usual.event.bluetooth.remotedevice.PAIRING_CANCEL | N/A| +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REQ | usual.event.bluetooth.remotedevice.CONNECT_REQ | N/A| +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REPLY | usual.event.bluetooth.remotedevice.CONNECT_REPLY | N/A| +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_CANCEL | usual.event.bluetooth.remotedevice.CONNECT_CANCEL | N/A| +| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_CONNECT_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.CONNECT_STATE_UPDATE | N/A| +| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AUDIO_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.AUDIO_STATE_UPDATE | N/A| +| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_COMMON_EVENT | usual.event.bluetooth.handsfreeunit.AG_COMMON_EVENT | N/A| +| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_CALL_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.AG_CALL_STATE_UPDATE | N/A| +| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISCOVERABLE | usual.event.bluetooth.host.REQ_DISCOVERABLE | N/A| +| COMMON_EVENT_NFC_ACTION_ADAPTER_STATE_CHANGED | usual.event.nfc.action.ADAPTER_STATE_CHANGED | N/A| +| COMMON_EVENT_DISCHARGING | usual.event.DISCHARGING | N/A| +| COMMON_EVENT_CHARGING | usual.event.CHARGING | N/A| +| COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED | usual.event.DEVICE_IDLE_MODE_CHANGED | N/A| +| COMMON_EVENT_POWER_SAVE_MODE_CHANGED | usual.event.POWER_SAVE_MODE_CHANGED | N/A| +| COMMON_EVENT_USER_ADDED | usual.event.USER_ADDED | ohos.permission.MANAGE_USERS | +| COMMON_EVENT_USER_REMOVED | usual.event.USER_REMOVED | ohos.permission.MANAGE_USERS | +| COMMON_EVENT_LOCATION_MODE_STATE_CHANGED | usual.event.location.MODE_STATE_CHANGED | N/A| +| COMMON_EVENT_IVI_SLEEP | common.event.IVI_SLEEP | N/A| +| COMMON_EVENT_IVI_PAUSE | common.event.IVI_PAUSE | N/A| +| COMMON_EVENT_IVI_STANDBY | common.event.IVI_STANDBY | N/A| +| COMMON_EVENT_IVI_LASTMODE_SAVE | common.event.IVI_LASTMODE_SAVE | N/A| +| COMMON_EVENT_IVI_VOLTAGE_ABNORMAL | common.event.IVI_VOLTAGE_ABNORMAL | N/A| +| COMMON_EVENT_IVI_HIGH_TEMPERATURE | common.event.IVI_HIGH_TEMPERATURE | N/A| +| COMMON_EVENT_IVI_EXTREME_TEMPERATURE | common.event.IVI_EXTREME_TEMPERATURE | N/A| +| COMMON_EVENT_IVI_TEMPERATURE_ABNORMAL | common.event.IVI_TEMPERATURE_ABNORMAL | N/A| +| COMMON_EVENT_IVI_VOLTAGE_RECOVERY | common.event.IVI_VOLTAGE_RECOVERY | N/A| +| COMMON_EVENT_IVI_TEMPERATURE_RECOVERY | common.event.IVI_TEMPERATURE_RECOVERY | N/A| +| COMMON_EVENT_IVI_ACTIVE | common.event.IVI_ACTIVE | N/A| +| COMMON_EVENT_USB_DEVICE_ATTACHED | usual.event.hardware.usb.action.USB_DEVICE_ATTACHED | N/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_AIRPLANE_MODE_CHANGED | usual.event.AIRPLANE_MODE | N/A| + +## Modules to Import + +```js +import CommonEvent from '@ohos.commonevent'; +``` + + + +## CommonEvent.publish(event: string, callback: AsyncCallback\): void + +- Functionality + + Publishes a common event. This method uses a callback to return the result. + +* 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.| + +* Example + +```js +// Callback for common event publication +function PublishCallBack(err) { + console.info("==========================>PublishCallBack=======================>"); + console.info("==========================>err:=======================>", err.code); +} +// Publish a common event. +CommonEvent.publish("publish_event", PublishCallBack); +``` + + + +## CommonEvent.publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\): void + +- Functionality + + Publishes a common event with given attributes. This method uses a callback to return the result. + +- 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.| + +- Example + + +```js +// Attributes of a common event. +var options = { + code: 0; // Result code of the common event + data: "initial data";// Result data of the common event + isOrdered: true; // The common event is an ordered one. +} +// Callback for common event publication +function PublishCallBack(err) { + console.info("==========================>PublishCallBack=======================>"); +} +// Publish a common event. +CommonEvent.publish("publish_event", options, PublishCallBack); +``` + + + +## CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback\): void + +- Functionality + + Creates a subscriber. This method uses a callback to return the result. + +- 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.| + +- Example + + +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +// Subscriber information +var subscribeInfo = { + events: ["event"] +}; +// Callback for subscriber creation +function CreateSubscriberCallBack(err, data) { + console.info("==========================>CreateSubscriberCallBack=======================>"); + subscriber = data; +} +// Create a subscriber. +CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); +``` + + + +## CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\ + +- Functionality + + Creates a subscriber. This method uses a promise to return the result. + +- Parameters + + | Name| Readable/Writable| Type| Mandatory| Description| + | ------------- | -------- | ------------------------------------------ | ---- | ------------ | + | subscribeInfo | Read-only| [CommonEventSubscribeInfo](#SubscribeInfo) | Yes| Subscriber information.| + +- Return values + + Promise\<[CommonEventSubscriber](#Subscriber)> + + Returns a subscriber object. + +- Example + +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +// Subscriber information +var subscribeInfo = { + events: ["event"] +}; +// Create a subscriber. +CommonEvent.createSubscriber(subscribeInfo).then((data) => { + console.info("==========================>createSubscriberPromise=======================>"); + subscriber = data; +}); +``` + + + +## CommonEvent.subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\): void + +- Functionality + + Subscribes to common events. This method uses a callback to return the result. + +- 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.| + +- Example + + Unordered common event: + + +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +// Subscriber information +var subscribeInfo = { + events: ["event"] +}; +// Callback for common event subscription +function SubscribeCallBack(err, data) { + console.info("==========================>SubscribeCallBack=======================>"); +} +// Callback for subscriber creation +function CreateSubscriberCallBack(err, data) { + console.info("==========================>CreateSubscriberCallBack=======================>"); + subscriber = data; + // Subscribe to a common event. + CommonEvent.subscribe(subscriber, SubscribeCallBack); +} +// Create a subscriber. +CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); +``` + +​ Ordered common event: + +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +// Subscriber information +var subscribeInfo = { + events: ["event"] +}; + +// Callback for result code setting of an ordered common event +function SetCodeCallBack(err) { + console.info("==========================>SetCodeCallBack=======================>"); +} +// Callback for result data setting of an ordered common event +function SetDataCallBack(err) { + console.info("==========================>SetDataCallBack=======================>"); +} +// Callback for ordered common event processing +function FinishCommonEventCallBack(err) { + console.info("==========================>FinishCommonEventCallBack=======================>"); +} +// Callback for common event subscription +function SubscribeCallBack(err, data) { + console.info("==========================>SubscribeCallBack=======================>"); + // Set the result code for the ordered common event. + subscriber.setCode(0, SetCodeCallBack); + // Set the result data for the ordered common event. + subscriber.setData("publish_data_changed", SetDataCallBack); + // Complete the processing of the ordered common event. + subscriber.finishCommonEvent(FinishCommonEventCallBack) +} + +// Callback for subscriber creation +function CreateSubscriberCallBack(err, data) { + console.info("==========================>CreateSubscriberCallBack=======================>"); + subscriber = data; + // Subscribe to a common event. + CommonEvent.subscribe(subscriber, SubscribeCallBack); +} + +// Create a subscriber. +CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); +``` + +​ + +## CommonEvent.unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\): void + +- Functionality + + Unsubscribes from common events. This method uses a callback to return the result. + +- 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.| + +- Example + +```js +var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. +// Subscriber information +var subscribeInfo = { + events: ["event"] +}; +// Callback for common event subscription +function SubscribeCallBack(err, data) { + console.info("==========================>SubscribeCallBack=======================>"); +} +// Callback for subscriber creation +function CreateSubscriberCallBack(err, data) { + console.info("==========================>CreateSubscriberCallBack=======================>"); + subscriber = data; + // Subscribe to a common event. + CommonEvent.subscribe(subscriber, SubscribeCallBack); +} +// Callback for common event unsubscription +function UnsubscribeCallBack(err) { + console.info("==========================>UnsubscribeCallBack=======================>"); +} +// Create a subscriber. +CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); +// Unsubscribe from the common event. +CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack); +``` + +## CommonEventPublishData + +| Name| Readable/Writable| Type| Mandatory| Description| +| --------------------- | -------- | -------------------- | ---- | ---------------------------- | +| bundleName | Read-only| string | No| Bundle name.| +| code | Read-only| number | No| Result code of the common event.| +| data | Read-only| string | No| Custom result data of the common event.| +| subscriberPermissions | Read-only| Array\ | No| Permissions required for subscribers to receive the common event.| +| 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 + +| Name| Readable/Writable| Type| Mandatory| Description| +| ------------------- | -------- | -------------- | ---- | ------------------------------------------------------------ | +| events | Read-only| Array\ | Yes| Common events to subscribe to.| +| publisherPermission | Read-only| string | No| Permission required for the publisher.| +| publisherDeviceId | Read-only| string | No| Device ID. The value must be the ID of an existing device on the same network.| +| 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 + +| Name| Readable/Writable| Type| Mandatory| Description| +| ---------- | -------- | -------------------- | ---- | ------------------------------------------------------ | +| event | Read-only| string | Yes| Name of the common event to subscribe to.| +| bundleName | Read-only| string | No| Bundle name.| +| code | Read-only| number | No| Result code of the common event, which is used to transfer data of the int type.| +| 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 + +### getCode (callback) + +- Functionality + + Obtains the result code of this common event. This method uses a callback to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | -------- | ---------------------- | ---- | ------------------ | + | callback | AsyncCallback\ | Yes| Callback used to return the result code.| + +- 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); + ``` + +### getCode (promise) + +- Functionality + + Obtains the result code of this common event. This method uses a promise to return the result. + +- Return values + + | Type| Description| + | ---------------- | ------------------ | + | Promise\ | A promise used to return the result code.| + +- 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); + }); + ``` + +### setCode (callback) + +- Functionality + + Sets the result code for this common event. This method uses a callback to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | -------- | -------------------- | ---- | -------------------- | + | code | number | Yes| Result code of the common event.| + | callback | AsyncCallback\ | Yes| Callback used to return the result.| + +- 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); + ``` + +### setCode (promise) + +- Functionality + + Sets the result code for this common event. This method uses a promise to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | ------ | ------ | ---- | ------------------ | + | code | number | Yes| Result code of the common event.| + +- Example + + ```js + var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. + subscriber.setCode(1).then(() => { + console.info("==========================>setCodePromise=======================>"); + }); + ``` + +### getData (callback) + +- Functionality + + Obtains the result data of this common event. This method uses a callback to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | -------- | ---------------------- | ---- | ------------------ | + | callback | AsyncCallback\ | Yes| Callback used to return the result data.| + +- 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); + ``` + +### getData (promise) + +- Functionality + + Obtains the result data of this common event. This method uses a promise to return the result. + +- Return values + + | Type| Description| + | ---------------- | ------------------ | + | Promise\ | A promise used to return the result data.| + +- 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); + }); + ``` + +### setData (callback) + +- Functionality + + Sets the result data for this common event. This method uses a callback to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | -------- | -------------------- | ---- | -------------------- | + | data | string | Yes| Result data of the common event.| + | callback | AsyncCallback\ | Yes| Callback used to return the result.| + +- 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); + ``` + +### setData (promise) + +- Functionality + + Sets the result data for this common event. This method uses a promise to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | ------ | ------ | ---- | ------------------ | + | data | string | Yes| Result data of the common event.| + +- 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=======================>"); + }); + ``` + +### setCodeAndData (callback) + +- Functionality + + Sets the result code and result data for this common event. This method uses a callback to return the result. + +- 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.| + +- 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); + ``` + +### setCodeAndData (promise) + +- Functionality + + Sets the result code and result data for this common event. This method uses a promise to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | ------ | ------ | ---- | ------------------ | + | code | number | Yes| Result code of the common event.| + | data | string | Yes| Result data of the common event.| + +- 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=======================>"); + }); + ``` + +### isOrderedCommonEvent (callback) + +- Functionality + + Checks whether this common event is an ordered one. This method uses a callback to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | -------- | ----------------------- | ---- | -------------------------------- | + | callback | AsyncCallback\ | Yes| Returns **true** if the common event is an ordered one; returns **false** otherwise.| + +- 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); + ``` + +### isOrderedCommonEvent (promise) + +- Functionality + + Checks whether this common event is an ordered one. This method uses a promise to return the result. + +- Return values + + | Type| Description| + | ----------------- | -------------------------------- | + | Promise\ | Returns **true** if the common event is an ordered one; returns **false** otherwise.| + +- Example + + ```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) + +- Functionality + + 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 + + | Name| Type| Mandatory| Description| + | -------- | ----------------------- | ---- | ------------------ | + | callback | AsyncCallback\ | Yes| Callback used to return the result.| + +- 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); + ``` + +### abortCommonEvent (promise) + +- Functionality + + 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 + + ```js + var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. + subscriber.abortCommonEvent().then(() => { + console.info("==========================>abortCommonEvent:=======================>"); + }); + ``` + +### clearAbortCommonEvent (callback) + +- Functionality + + 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 + + | Name| Type| Mandatory| Description| + | -------- | -------------------- | ---- | -------------------- | + | callback | AsyncCallback\ | Yes| Callback used to return the result.| + +- 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); + ``` + +### clearAbortCommonEvent (promise) + +- Functionality + + 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 + + ```js + var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. + subscriber.clearAbortCommonEvent().then(() => { + console.info("==========================>clearAbortCommonEvent:=======================>"); + }); + ``` + +### getAbortCommonEvent (callback) + +- Functionality + + 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 + + | Name| Type| Mandatory| Description| + | -------- | ----------------------- | ---- | ---------------------------------- | + | callback | AsyncCallback\ | Yes| Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.| + +- 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); + ``` + +### getAbortCommonEvent (promise) + +- Functionality + + 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 + + | Type| Description| + | ----------------- | ---------------------------------- | + | Promise\ | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.| + +- 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); + }); + ``` + +### getSubscribeInfo (callback) + +- Functionality + + Obtains the subscriber information. This method uses a callback to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | -------- | ---------------------------------------- | ---- | -------------------- | + | callback | AsyncCallback\ | Yes| Callback used to return the subscriber information.| + +- 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); + ``` + +### getSubscribeInfo (promise) + +- Functionality + + Obtains the subscriber information. This method uses a promise to return the result. + +- Return values + + | Type| Description| + | ---------------------------------- | -------------------- | + | Promise\ | A promise used to return the subscriber information.| + +- 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); + }); + ``` diff --git a/en/application-dev/reference/apis/js-apis-featureAbility.md b/en/application-dev/reference/apis/js-apis-featureAbility.md index d8b1cfc3bd..88279ca859 100644 --- a/en/application-dev/reference/apis/js-apis-featureAbility.md +++ b/en/application-dev/reference/apis/js-apis-featureAbility.md @@ -696,19 +696,19 @@ this.StartContinueAbility(remoteDeviceId); //remoteDeviceId is acquired from Dev | Name| Name| Description| | ------------------------------------ | ---------- | ------------------------------------------------------------ | -| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Permission to read the URI.| -| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Permission to write the URI.| -| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | Whether to return the result to the ability.| -| FLAG_ABILITY_CONTINUATION | 0x00000008 | Whether abilities on the local device can be migrated to a remote device.| -| FLAG_NOT_OHOS_COMPONENT | 0x00000010 | Whether a component belongs to OHOS.| -| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | Whether to enable an ability.| -| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Permission to make the URI persist.| -| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | Permission to authenticate prefix URI.| -| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | Support for the startup across multiple devices in a distributed scheduler.| -| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | Functionality of using the Service template is enabled regardless of whether the host application is started.| -| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Whether the migration is reversible.| -| FLAG_INSTALL_ON_DEMAND | 0x00000800 | A demand for the installation of a specific function.| -| FLAG_INSTALL_WITH_BACKGROUND_MODE | 0x80000000 | A demand for the installation of a specific function in background mode.| -| FLAG_ABILITY_CLEAR_MISSION | 0x00008000 | An instruction for clearing other tasks. This flag can be set for the **Want** object passed to **ohos.app.Context#startAbility** and must be used together with **flag_ABILITY_NEW_MISSION**.| -| FLAG_ABILITY_NEW_MISSION | 0x10000000 | An instruction for creating a task on the history task stack.| -| FLAG_ABILITY_MISSION_TOP | 0x20000000 | An existing instance of the ability to start will be reused if it is already at the top of the task stack. Otherwise, a new ability instance is created.| +| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Indicates the permission to read the URI.| +| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Indicates the permission to write the URI.| +| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | Returns the result to the ability.| +| FLAG_ABILITY_CONTINUATION | 0x00000008 | Indicates whether the ability on the local device can be migrated to a remote device.| +| FLAG_NOT_OHOS_COMPONENT | 0x00000010 | Indicates that a component does not belong to OHOS.| +| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | Indicates whether to enable an ability.| +| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Indicates the permission to make the URI persistent.| +| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | Indicates the permission to verify URIs by prefix matching.| +| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | Supports cross-device startup in a distributed scheduler.| +| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | Indicates that the Service ability is started regardless of whether the host application has been started.| +| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that the migration is reversible.| +| FLAG_INSTALL_ON_DEMAND | 0x00000800 | Indicates that the specific ability will be installed if it has not been installed.| +| FLAG_INSTALL_WITH_BACKGROUND_MODE | 0x80000000 | Indicates that the specific ability will be installed in the background if it has not been installed.| +| FLAG_ABILITY_CLEAR_MISSION | 0x00008000 | Clears other operation missions. This flag can be set for the **Want** object passed to **ohos.app.Context#startAbility** and must be used together with **flag_ABILITY_NEW_MISSION**.| +| FLAG_ABILITY_NEW_MISSION | 0x10000000 | Creates a mission on the historical mission stack.| +| FLAG_ABILITY_MISSION_TOP | 0x20000000 | Starts the mission on the top of the existing mission stack; creates an ability instance if no mission exists.| diff --git a/en/application-dev/reference/apis/js-apis-notification.md b/en/application-dev/reference/apis/js-apis-notification.md new file mode 100644 index 0000000000..1e4bbafcd5 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-notification.md @@ -0,0 +1,3267 @@ +# Notification Module + +## Applicable Devices + +| API | Phone | Tablet | Smart TV | Wearable | +| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | +| Notification.publish(request: NotificationRequest, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.publish(request: NotificationRequest) | Yes | Yes | Yes | Yes | +| Notification.cancel(id: number, label: string, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.cancel(id:number, label?:string) | Yes | Yes | Yes | Yes | +| Notification.cancel(id: number, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.cancelAll(callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.cancelAll() | Yes | Yes | Yes | Yes | +| Notification.addSlot(slot: NotificationSlot, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.addSlot(slot: NotificationSlot) | Yes | Yes | Yes | Yes | +| Notification.addSlot(type: SlotType, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.addSlot(type: SlotType) | Yes | Yes | Yes | Yes | +| Notification.addSlots(slots: Array\, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.addSlots(slots: Array\) | Yes | Yes | Yes | Yes | +| Notification.getSlot(slotType: SlotType, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.getSlot(slotType: SlotType) | Yes | Yes | Yes | Yes | +| Notification.getSlots(callback: AsyncCallback>) | Yes | Yes | Yes | Yes | +| Notification.getSlots() | Yes | Yes | Yes | Yes | +| Notification.removeSlot(slotType: SlotType, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.removeSlot(slotType: SlotType) | Yes | Yes | Yes | Yes | +| Notification.removeAllSlots(callback: AsyncCallback\): void | Yes | Yes | Yes | Yes | +| Notification.removeAllSlots(): Promise\ | Yes | Yes | Yes | Yes | +| Notification.subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo) | Yes | Yes | Yes | Yes | +| Notification.unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.unsubscribe(subscriber: NotificationSubscriber) | Yes | Yes | Yes | Yes | +| Notification.enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.enableNotification(bundle: BundleOption, enable: boolean) | Yes | Yes | Yes | Yes | +| Notification.isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.isNotificationEnabled(bundle: BundleOption) | Yes | Yes | Yes | Yes | +| Notification.isNotificationEnabled(callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.isNotificationEnabled() | Yes | Yes | Yes | Yes | +| Notification.displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.displayBadge(bundle: BundleOption, enable: boolean) | Yes | Yes | Yes | Yes | +| Notification.isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.isBadgeDisplayed(bundle: BundleOption) | Yes | Yes | Yes | Yes | +| Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot) | Yes | Yes | Yes | Yes | +| Notification.getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback>) | Yes | Yes | Yes | Yes | +| Notification.getSlotsByBundle(bundle: BundleOption) | Yes | Yes | Yes | Yes | +| Notification.getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.getSlotNumByBundle(bundle: BundleOption) | Yes | Yes | Yes | Yes | +| Notification.remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.remove(bundle: BundleOption, notificationKey: NotificationKey) | Yes | Yes | Yes | Yes | +| Notification.remove(hashCode: string, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.remove(hashCode: string) | Yes | Yes | Yes | Yes | +| Notification.removeAll(bundle: BundleOption, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.removeAll(callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.removeAll(bundle?: BundleOption) | Yes | Yes | Yes | Yes | +| Notification.getAllActiveNotifications(callback: AsyncCallback>) | Yes | Yes | Yes | Yes | +| Notification.getAllActiveNotifications() | Yes | Yes | Yes | Yes | +| Notification.getActiveNotificationCount(callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.getActiveNotificationCount() | Yes | Yes | Yes | Yes | +| Notification.getActiveNotifications(callback: AsyncCallback>) | Yes | Yes | Yes | Yes | +| Notification.getActiveNotifications() | Yes | Yes | Yes | Yes | +| Notification.cancelGroup(groupName: string, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.cancelGroup(groupName: string) | Yes | Yes | Yes | Yes | +| Notification.removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.removeGroupByBundle(bundle: BundleOption, groupName: string) | Yes | Yes | Yes | Yes | +| Notification.setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.setDoNotDisturbDate(date: DoNotDisturbDate) | Yes | Yes | Yes | Yes | +| Notification.getDoNotDisturbDate(callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.getDoNotDisturbDate() | Yes | Yes | Yes | Yes | +| Notification.supportDoNotDisturbMode(callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| Notification.supportDoNotDisturbMode() | Yes | Yes | Yes | Yes | +| WantAgent.getWantAgent(info: WantAgentInfo, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| WantAgent.getWantAgent(info: WantAgentInfo): Promise\ | Yes | Yes | Yes | Yes | +| WantAgent.getBundleName(agent: WantAgent, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| WantAgent.getBundleName(agent: WantAgent): Promise\ | Yes | Yes | Yes | Yes | +| WantAgent.getUid(agent: WantAgent, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| WantAgent.getUid(agent: WantAgent): Promise\ | Yes | Yes | Yes | Yes | +| WantAgent.getWant(agent: WantAgent, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| WantAgent.getWant(agent: WantAgent): Promise\ | Yes | Yes | Yes | Yes | +| WantAgent.cancel(agent: WantAgent, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| WantAgent.cancel(agent: WantAgent): Promise\ | Yes | Yes | Yes | Yes | +| WantAgent.trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback\) | Yes | Yes | Yes | Yes | +| WantAgent.equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\) | Yes | Yes | Yes | Yes | +| WantAgent.equal(agent: WantAgent, otherAgent: WantAgent): Promise\ | Yes | Yes | Yes | Yes | + + +## Required Permissions + +None + + +## Modules to Import + +```js +import Notification from '@ohos.notification'; +``` + +## Notification.publish(request: NotificationRequest, callback: AsyncCallback\) + +- Functionality + + Publishes a notification. This method uses a callback to return the result. + +- Parameters + + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | ------------------------------------------- | +| request | Read-only| NotificationRequest | Yes| Notification to publish.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- NotificationRequest + +| Name| Readable/Writable| Type| Mandatory| Description| +| --------------------- | -------- | --------------------------------------------- | ---- | -------------------------- | +| content | Readable and writable| NotificationContent | Yes| Notification content.| +| id | Readable and writable| number | No| Notification ID.| +| slotType | Readable and writable| SlotType | No| Notification slot type.| +| isOngoing | Readable and writable| boolean | No| Whether the notification is an ongoing notification.| +| isUnremovable | Readable and writable| boolean | No| Whether the notification can be removed.| +| deliveryTime | Readable and writable| number | No| Time when the notification is sent.| +| tapDismissed | Readable and writable| boolean | No| Whether the notification can be automatically cleared.| +| autoDeletedTime | Readable and writable| number | No| Time when the notification is automatically cleared.| +| wantAgent | Readable and writable| WantAgent | No| **WantAgent** object to which the notification will be redirected after being clicked.| +| extraInfo | Readable and writable| {[key: string]: any} | No| Extended parameter.| +| color | Readable and writable| number | No| Background color of the notification.| +| colorEnabled | Readable and writable| boolean | No| Whether the notification background color is enabled.| +| isAlertOnce | Readable and writable| boolean | No| Whether the notification triggers an alert only once.| +| isStopwatch | Readable and writable| boolean | No| Whether to display the stopwatch.| +| isCountDown | Readable and writable| boolean | No| Whether to display the countdown time.| +| isFloatingIcon | Readable and writable| boolean | No| Whether the notification is displayed as a floating icon.| +| label | Readable and writable| string | No| Notification label.| +| badgeIconStyle | Readable and writable| number | No| Notification badge type.| +| showDeliveryTime | Readable and writable| boolean | No| Whether to display the time when the notification is delivered.| +| actionButtons | Readable and writable| Array\ | No| Buttons in the notification. Up to two buttons are allowed.| +| smallIcon | Readable and writable| PixelMap | No| Small notification icon.| +| largeIcon | Readable and writable| PixelMap | No| Large notification icon.| +| creatorBundleName | Read-only| string | No| Name of the bundle that creates the notification.| +| creatorUid | Read-only| number | No| UID of the notification creator.| +| creatorPid | Read-only| number | No| PID of the notification creator.| +| hashCode | Read-only| string | No| Unique ID of the notification.| +| classification | Readable and writable| string | No| Notification category.| +| groupName | Readable and writable| string | No| Notification group name.| +| template8+ | Readable and writable| [NotificationTemplate](#notificationtemplate) | No| Notification template.| + +NotificationContent + +| Name| Readable/Writable| Type| Mandatory| Description| +| ----------- | -------- | ---------------------------- | ---- | ------------------ | +| contentType | Readable and writable| ContentType | Yes| Notification content type.| +| normal | Readable and writable| NotificationBasicContent | No| Normal text.| +| longText | Readable and writable| NotificationLongTextContent | No| Long text.| +| multiLine | Readable and writable| NotificationMultiLineContent | No| Multi-line text.| +| picture | Readable and writable| NotificationPictureContent | No| Picture-attached.| + +- ContentType + +| Name| Readable/Writable| Type| Description| +| --------------------------------- | -------- | ----------- | ---------------- | +| NOTIFICATION_CONTENT_BASIC_TEXT | Read-only| ContentType | Normal text notification.| +| NOTIFICATION_CONTENT_LONG_TEXT | Read-only| ContentType | Long text notification.| +| NOTIFICATION_CONTENT_PICTURE | Read-only| ContentType | Picture-attached notification.| +| NOTIFICATION_CONTENT_CONVERSATION | Read-only| ContentType | Conversation notification.| +| NOTIFICATION_CONTENT_MULTILINE | Read-only| ContentType | Multi-line text notification.| + +- NotificationBasicContent + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------------- | -------- | ------ | ---- | -------------------------------- | +| title | Readable and writable| string | Yes| Notification title.| +| text | Readable and writable| string | Yes| Notification content.| +| additionalText | Readable and writable| string | Yes| Additional information of the notification.| + +- NotificationLongTextContent + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------------- | -------- | ------ | ---- | -------------------------------- | +| title | Readable and writable| string | Yes| Notification title.| +| text | Readable and writable| string | Yes| Notification content.| +| additionalText | Readable and writable| string | Yes| Additional information of the notification.| +| longText | Readable and writable| string | Yes| Long text content of the notification.| +| briefText | Readable and writable| string | Yes| Brief text of the notification.| +| expandedTitle | Readable and writable| string | Yes| Title of the notification in the expanded state.| + +- NotificationMultiLineContent + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------------- | -------- | --------------- | ---- | -------------------------------- | +| title | Readable and writable| string | Yes| Notification title.| +| text | Readable and writable| string | Yes| Notification content.| +| additionalText | Readable and writable| string | Yes| Additional information of the notification.| +| briefText | Readable and writable| string | Yes| Brief text of the notification.| +| longTitle | Readable and writable| string | Yes| Title of the notification in the expanded state.| +| lines | Readable and writable| Array\ | Yes| Multi-line content.| + +- NotificationPictureContent + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------------- | -------- | -------------- | ---- | -------------------------------- | +| title | Readable and writable| string | Yes| Notification title.| +| text | Readable and writable| string | Yes| Notification content.| +| additionalText | Readable and writable| string | Yes| Additional information of the notification.| +| briefText | Readable and writable| string | Yes| Brief text of the notification.| +| expandedTitle | Readable and writable| string | Yes| Title of the notification in the expanded state.| +| picture | Readable and writable| image.PixelMap | Yes| Picture included in the notification.| + +- SlotType + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------------------- | -------- | -------- | ---- | -------- | +| SOCIAL_COMMUNICATION | Read-only| SlotType | No| Notification slot for social communication.| +| SERVICE_INFORMATION | Read-only| SlotType | No| Notification slot for service information.| +| CONTENT_INFORMATION | Read-only| SlotType | No| Notification slot for content consultation.| +| OTHER_TYPES | Read-only| SlotType | No| Notification slot for other purposes.| + +- NotificationActionButton + +| Name| Readable/Writable| Type| Mandatory| Description| +| --------- | -------- | --------------------- | ---- | ------------------------- | +| title | Readable and writable| string | Yes| Button title.| +| wantAgent | Readable and writable| wantAgent | Yes| **WantAgent** of the button.| +| extras | Readable and writable| Array\ | No| Extra information of the button.| +| icon | Readable and writable| image.PixelMap | No| Button icon.| +| userInput | Readable and writable| NotificationUserInput | No| User input object.| + +- NotificationUserInput + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | ------ | ---- | ----------------------------- | +| inputKey | Readable and writable| string | Yes| Key to identify the user input.| + + +- Return value + + void + +- Example + +```js +// publish callback +function publishCallback(err) { + console.info("==========================>publishCallback=======================>"); +} +// NotificationRequest object +var notificationRequest = { + id: 1, + content: { + contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } +} +Notification.publish(notificationRequest, publishCallback) +``` + + + +## Notification.publish(request: NotificationRequest) + +- Functionality + + Publishes a notification. This method uses a promise to return the result. + +- Return value + + Promise\ + +- Example + +```js +// NotificationRequest object +var notificationRequest = { + notificationId: 1, + content: { + contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } +} +Notification.publish(notificationRequest).then((void) => { + console.info("==========================>publishCallback=======================>"); +}); + +``` + + + +## Notification.cancel(id: number, label: string, callback: AsyncCallback\) + +- Functionality + + Cancels a notification with the specified ID and label. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | -------------------- | +| id | Read-only| number | Yes| Notification ID.| +| label | Read-only| string | Yes| Notification label.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +// cancel callback +function cancelCallback(err) { + console.info("==========================>cancelCallback=======================>"); +} +Notification.cancel(0, "label", cancelCallback) +``` + + + +## Notification.cancel(id: number, label? : string) + +- Functionality + + Cancels a notification with the specified ID and label. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ----- | -------- | ------ | ---- | -------- | +| id | Read-only| number | Yes| Notification ID.| +| label | Read-only| string | No| Notification label.| + +- Return value + + Promise\ + +- Example + +```js +Notification.cancel(0).then((void) => { + console.info("==========================>cancelCallback=======================>"); +}); +``` + + + +## Notification.cancel(id: number, callback: AsyncCallback\) + +- Functionality + + Cancels a notification with the specified ID. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | -------------------- | +| id | Read-only| number | Yes| Notification ID.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +// cancel callback +function cancelCallback(err) { + console.info("==========================>cancelCallback=======================>"); +} +Notification.cancel(0, cancelCallback) +``` + + + +## Notification.cancelAll(callback: AsyncCallback\) + +- Functionality + + Cancels all notifications. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | -------------------- | +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +// cancel callback +function cancelAllback(err) { + console.info("==========================>cancelAllback=======================>"); +} +Notification.cancelAll(cancelCallback) +``` + + + +## Notification.cancelAll() + +- Functionality + + Cancels all notifications. This method uses a promise to return the result. + +- Parameters + + None + +- Return value + + Promise\ + +- Example + +```js +Notification.cancelAll().then((void) => { + console.info("==========================>cancelAllback=======================>"); +}); +``` + + + +## Notification.addSlot(slot: NotificationSlot, callback: AsyncCallback\) + +- Functionality + + Adds a notification slot. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | -------------------- | +| slot | Read-only| NotificationSlot | Yes| Notification slot to add.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- NotificationSlot + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------------------- | -------- | --------------- | ---- | ------------------------------------------ | +| type | Readable and writable| SlotType | Yes| Notification slot type.| +| level | Readable and writable| number | No| Notification level. If this parameter is not set, the default value is used based on the notification slot type.| +| desc | Readable and writable| string | No| Description of the notification slot.| +| badgeFlag | Readable and writable| boolean | No| Whether to display the badge.| +| bypassDnd | Readable and writable| boolean | No| Whether to bypass the system do-not-disturb (DND) setting.| +| lockscreenVisibility | Readable and writable| boolean | No| How the notification is displayed on the locked screen.| +| vibrationEnabled | Readable and writable| boolean | No| Whether vibration is enabled for the notification.| +| sound | Readable and writable| string | No| Notification sound.| +| lightEnabled | Readable and writable| boolean | No| Whether light is enabled for the notification.| +| lightColor | Readable and writable| number | No| Notification light color.| +| vibrationValues | Readable and writable| Array\ | No| Notification vibration mode.| + +* Return values + + void + +* Example + +```js +// addSlot callback +function addSlotCallBack(err) { + console.info("==========================>addSlotCallBack=======================>"); +} +// NotificationSlot object +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +Notification.addSlot(notificationSlot, addSlotCallBack) +``` + + + +## Notification.addSlot(slot: NotificationSlot) + +- Functionality + + Adds a notification slot. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ---- | -------- | ---------------- | ---- | -------------------- | +| slot | Read-only| NotificationSlot | Yes| Notification slot to add.| + +- Return value + + Promise\ + +- Example + +```js +// NotificationSlot object +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +Notification.addSlot(notificationSlot).then((void) => { + console.info("==========================>addSlotCallback=======================>"); +}); +``` + + + +## Notification.addSlot(type: SlotType, callback: AsyncCallback\) + +- Functionality + + Adds a notification slot. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | ---------------------- | +| type | Read-only| SlotType | Yes| Type of the notification slot to add.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +// addSlot callback +function addSlotCallBack(err) { + console.info("==========================>addSlotCallBack=======================>"); +} +Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack) +``` + + + +## Notification.addSlot(type: SlotType) + +- Functionality + + Adds a notification slot. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ---- | -------- | -------- | ---- | ---------------------- | +| type | Read-only| SlotType | Yes| Type of the notification slot to add.| + +- Return value + + Promise\ + +- Example + +```js +Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then((void) => { + console.info("==========================>addSlotCallback=======================>"); +}); +``` + + + +## Notification.addSlots(slots: Array\, callback: AsyncCallback\) + +- Functionality + + Adds multiple notification slots. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | ------------------------- | ---- | ------------------------ | +| slots | Read-only| Array\ | Yes| Notification slots to add.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +// addSlots callback +function addSlotsCallBack(err) { + console.info("==========================>addSlotsCallBack=======================>"); +} +// NotificationSlot object +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +// NotificationSlotArray object +var notificationSlotArray = new Array(); +notificationSlotArray[0] = notificationSlot; + +Notification.addSlots(notificationSlotArray, addSlotsCallBack) +``` + + + +## Notification.addSlots(slots: Array\) + +- Functionality + + Adds multiple notification slots. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ----- | -------- | ------------------------- | ---- | ------------------------ | +| slots | Read-only| Array\ | Yes| Notification slots to add.| + +- Return value + + Promise\ + +- Example + +```js +// NotificationSlot object +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +// NotificationSlotArray object +var notificationSlotArray = new Array(); +notificationSlotArray[0] = notificationSlot; + +Notification.addSlots(notificationSlotArray).then((void) => { + console.info("==========================>addSlotCallback=======================>"); +}); +``` + + + +## Notification.getSlot(slotType: SlotType, callback: AsyncCallback\) + +- Functionality + + Obtains a notification slot of the specified type. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------------------- | ---- | ----------------------------------------------------------- | +| slotType | Read-only| slotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +// getSlot callback +function getSlotCallback(err,data) { + console.info("==========================>getSlotCallback=======================>"); +} +var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; +Notification.getSlot(slotType, getSlotCallback) +``` + + + +## Notification.getSlot(slotType) + +- Functionality + + Obtains a notification slot of the specified type. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | -------- | ---- | ----------------------------------------------------------- | +| slotType | Read-only| slotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| + +- Return value + + Promise\ + +- Example + +```js +var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; +Notification.getSlot(slotType).then((data) => { + console.info("==========================>getSlotCallback=======================>"); +}); +``` + + + +## Notification.getSlots(callback: AsyncCallback>) + +- Functionality + + Obtains all notification slots. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------------------- | ---- | -------------------- | +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +// getSlots callback +function getSlotsCallback(err,data) { + console.info("==========================>getSlotsCallback=======================>"); +} +Notification.getSlots(getSlotsCallback) +``` + + + +## Notification.getSlots() + +- Functionality + + Obtains all notification slots of the current application. This method uses a promise to return the result. + +- Parameters + + None + +- Return value + + Promise\\> + +- Example + +```js +Notification.getSlots().then((data) => { + console.info("==========================>getSlotsCallback=======================>"); +}); +``` + + + +## Notification.removeSlot(slotType: SlotType, callback: AsyncCallback\) + +- Functionality + + Removes a notification slot of the specified type. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | ----------------------------------------------------------- | +| SlotType | Read-only| SlotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +// removeSlot callback +function removeSlotCallback(err) { + console.info("==========================>removeSlotCallback=======================>"); +} +var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; +Notification.removeSlot(slotType,removeSlotCallback) +``` + + + +## Notification.removeSlot(slotType: SlotType) + +- Functionality + + Removes a notification slot of the specified type. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | -------- | ---- | ----------------------------------------------------------- | +| SlotType | Read-only| SlotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| + +- Return value + + Promise\ + +- Example + +```js +var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; +Notification.removeSlot(slotType).then((void) => { + console.info("==========================>removeSlotCallback=======================>"); +}); +``` + + + +## Notification.removeAllSlots(callback: AsyncCallback\) + +- Functionality + + Removes all notification slots. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | -------------------- | +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function removeAllCallBack(err) { + console.info("================>removeAllCallBack=======================>"); +} +Notification.removeAllSlots(removeAllCallBack) +``` + + + +## Notification.removeAllSlots() + +- Functionality + + Removes all notification slots. This method uses a promise to return the result. + +- Parameters + + None + +- Return value + + Promise\ + +- Example + +```js +Notification.removeAllSlots().then((void) => { + console.info("==========================>removeAllCallBack=======================>"); +}); +``` + + + +## Notification.subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\) + +- Functionality + + Subscribes to a notification with the subscription information specified. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ---------- | -------- | ------------------------- | ---- | ---------------- | +| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.| +| info | Read-only| NotificationSubscribeInfo | Yes| Subscription information.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- NotificationSubscriber + +| Name| Readable/Writable| Type| Mandatory| Description| +| ------------------------------------------------------------ | -------- | -------- | ---- | -------------------------- | +| onConsume?:(data: SubscribeCallbackData) | Readable and writable| function | No| Callback for receiving notifications.| +| onCancel?:(data: SubscribeCallbackData) | Readable and writable| function | No| Callback for canceling notifications.| +| onUpdate?:(data: NotificationSortingMap) | Readable and writable| function | No| Callback for notification sorting updates.| +| onConnect?:() | Readable and writable| function | No| Callback for subscription.| +| onDisconnect?:() | Readable and writable| function | No| Callback for unsubscription.| +| onDestroy?:() | Readable and writable| function | No| Callback for service destruction.| +| onDoNotDisturbDateChange?:(mode: notification.DoNotDisturbDate) | Readable and writable| function | No| Callback for DND time setting updates.| + +- SubscribeCallbackData + +| Name| Readable/Writable| Type| Mandatory| Description| +| --------------- | -------- | ---------------------- | ---- | -------- | +| request | Read-only| NotificationRequest | Yes| Notification content.| +| sortingMap | Read-only| NotificationSortingMap | No| Notification sorting information.| +| reason | Read-only| number | No| Reason for deletion.| +| sound | Read-only| string | No| Sound used for notification.| +| vibrationValues | Read-only| Array\ | No| Vibration used for notification.| + +- NotificationSortingMap + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------------- | -------- | ------------------------------------ | ---- | ---------------- | +| sortings | Read-only| {[key: string]: NotificationSorting} | Yes| Array of notification sorting information.| +| sortedHashCode | Read-only| Array\ | Yes| Array of unique notification IDs.| + +- NotificationSorting + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | ---------------- | ---- | ------------ | +| slot | Read-only| NotificationSlot | Yes| Notification slot.| +| hashCode | Read-only| string | Yes| Unique ID of the notification.| +| ranking | Read-only| number | Yes| Notification sequence number.| + +- DoNotDisturbType + + +| Name| Readable/Writable| Type| Description| +| ------------ | -------- | --------------------- | ---------------------------------------- | +| TYPE_NONE | Read-only| enum DoNotDisturbType | Non-DND.| +| TYPE_ONCE | Read-only| enum DoNotDisturbType | One-shot DND at the specified time segment (only considering the hour and minute)| +| TYPE_DAILY | Read-only| enum DoNotDisturbType | Daily DND at the specified time segment (only considering the hour and minute)| +| TYPE_CLEARLY | Read-only| enum DoNotDisturbType | DND at the specified time segment (considering the year, month, day, hour, and minute)| + +- DoNotDisturbDate + +| Name| Readable/Writable| Type| Description| +| ----- | -------- | ---------------- | ------------------------ | +| type | Readable and writable| DoNotDisturbType | DND time type.| +| begin | Readable and writable| Date | DND start time.| +| end | Readable and writable| Date | DND end time.| + +- NotificationSubscribeInfo + +| Name| Readable/Writable| Type| Mandatory| Description| +| ----------- | -------- | --------------- | ---- | ------------------------------- | +| bundleNames | Readable and writable| Array\ | No| Bundle names of the applications whose notifications are to be subscribed to.| +| userId | Readable and writable| number | No| User whose notifications are to be subscribed to.| + +- Return value + + void + +- Example + +```js +// subscribe callback +function subscribeCallback(err) { + console.info("==========================>subscribeCallback=======================>"); +} +function onConsumeCallback(err, data) { + console.info("==========================>onConsumeCallback=======================>"); +} +var subscriber = { + onConsume: onConsumeCallback +} +var info = { + bundleNames: ["bundleName1","bundleName2"] +} +Notification.subscribe(subscriber, info, subscribeCallback); +``` + + + +## Notification.subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\) + +- Functionality + + Subscribes to a notification. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ---------- | -------- | ---------------------- | ---- | ---------------- | +| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function subscribeCallback(err) { + console.info("==========================>subscribeCallback=======================>"); +} +function onConsumeCallback(err, data) { + console.info("==========================>onConsumeCallback=======================>"); +} +var subscriber = { + onConsume: onConsumeCallback +} +Notification.subscribe(subscriber, subscribeCallback); +``` + + + +## Notification.subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo) + +- Functionality + + Subscribes to a notification with the subscription information specified. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ---------- | -------- | ------------------------- | ---- | ------------ | +| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.| +| info | Read-only| NotificationSubscribeInfo | No| Subscription information.| + +- Return value + + Promise\ + +- Example + +```js +function onConsumeCallback(err, data) { + console.info("==========================>onConsumeCallback=======================>"); +} +var subscriber = { + onConsume: onConsumeCallback +}; +Notification.subscribe(subscriber).then((void) => { + console.info("==========================>subscribeCallback=======================>"); +}); +``` + + + +## Notification.unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\) + +- Functionality + + Unsubscribes from a notification. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ---------- | -------- | ---------------------- | ---- | -------------------- | +| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function unsubscribeCallback(err) { + console.info("==========================>unsubscribeCallback=======================>"); +} +function onConsumeCallback(err, data) { + console.info("==========================>onConsumeCallback=======================>"); +} +var subscriber = { + onConsume: onConsumeCallback +} +Notification.unsubscribe(subscriber, unsubscribeCallback); +``` + + + +## Notification.unsubscribe(subscriber: NotificationSubscriber) + +- Functionality + + Unsubscribes from a notification. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ---------- | -------- | ---------------------- | ---- | ------------ | +| subscriber | Read-only| NotificationSubscriber | Yes| Notification subscriber.| + +- Return value + + Promise\ + +- Example + +```js +function onConsumeCallback(err, data) { + console.info("==========================>onConsumeCallback=======================>"); +} +var subscriber = { + onConsume: onConsumeCallback +}; +Notification.unsubscribe(subscriber).then((void) => { + console.info("==========================>unsubscribeCallback=======================>"); +}); +``` + + + +## Notification.enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\) + +- Functionality + + Sets whether to enable notification for a specified bundle. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | -------------------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| +| enable | Read-only| boolean | Yes| Whether to enable notification.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- BundleOption + +| Name| Readable/Writable| Type| Mandatory| Description| +| ------ | -------- | ------ | ---- | ------ | +| bundle | Readable and writable| string | Yes| Bundle name.| +| uid | Readable and writable| number | No| User ID.| +- Return value + + void + +- Example + +```js +function enableNotificationCallback(err) { + console.info("==========================>enableNotificationCallback=======================>"); +} +var bundle = { + bundle: "bundleName1"; +} +Notification.enableNotification(bundle, false, enableNotificationCallback); +``` + + + +## Notification.enableNotification(bundle: BundleOption, enable: boolean) + +- Functionality + + Sets whether to enable notification for a specified bundle. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ------ | -------- | ------------ | ---- | ---------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| +| enable | Read-only| boolean | Yes| Whether to enable notification.| + +- Return value + + Promise\ + +- Example + +```js +var bundle = { + bundle: "bundleName1"; +} +Notification.enableNotification(bundle, false).then((void) => { + console.info("==========================>enableNotificationCallback=======================>"); +}); +``` + + + +## Notification.isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\) + +- Functionality + + Checks whether notification is enabled for a specified bundle. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | ------------------------ | +| bundle | Read-only| BundleOption | Yes| Bundle information.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function isNotificationEnabledCallback(err, data) { + console.info("==========================>isNotificationEnabledCallback=======================>"); +} +var bundle = { + bundle: "bundleName1"; +} +Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback); +``` + + + +## Notification.isNotificationEnabled(bundle: BundleOption) + +- Functionality + + Checks whether notification is enabled for a specified bundle. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ------ | -------- | ------------ | ---- | ---------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| + +- Return value + + Promise\ + +- Example + +```js +var bundle = { + bundle: "bundleName1"; +} +Notification.isNotificationEnabled(bundle).then((data) => { + console.info("==========================>isNotificationEnabledCallback=======================>"); +}); +``` + + + +## Notification.isNotificationEnabled(callback: AsyncCallback\) + +- Functionality + + Checks whether notification is enabled for the current application. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | ------------------------ | +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function isNotificationEnabledCallback(err, data) { + console.info("==========================>isNotificationEnabledCallback=======================>"); +} + +Notification.isNotificationEnabled(isNotificationEnabledCallback); +``` + + + +## Notification.isNotificationEnabled() + +- Functionality + + Checks whether notification is enabled for the current application. This method uses a promise to return the result. + +- Parameters + + None + +- Return value + + Promise\ + +- Example + +```js +Notification.isNotificationEnabled().then((data) => { + console.info("==========================>isNotificationEnabledCallback=======================>"); +}); +``` + + + +## Notification.displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\) + +- Functionality + + Sets whether to display the badge in notifications for a specified bundle. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | -------------------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| +| enable | Read-only| boolean | Yes| Whether to display the badge.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function displayBadgeCallback(err) { + console.info("==========================>displayBadgeCallback=======================>"); +} +var bundle = { + bundle: "bundleName1"; +} +Notification.displayBadge(bundle, false, displayBadgeCallback); +``` + + + +## Notification.displayBadge(bundle: BundleOption, enable: boolean) + +- Functionality + + Sets whether to display the badge in notifications for a specified bundle. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ------ | -------- | ------------ | ---- | ---------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| +| enable | Read-only| boolean | Yes| Whether to display the badge.| + +- Return value + + Promise\ + +- Example + +```js +var bundle = { + bundle: "bundleName1"; +} +Notification.displayBadge(bundle, false).then((void) => { + console.info("==========================>displayBadgeCallback=======================>"); +}); +``` + + + +## Notification.isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\) + +- Functionality + + Checks whether the badge will be displayed in notifications of a specified bundle. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | ------------------------ | +| bundle | Read-only| BundleOption | Yes| Bundle information.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function isBadgeDisplayedCallback(err, data) { + console.info("==========================>isBadgeDisplayedCallback=======================>"); +} +var bundle = { + bundle: "bundleName1"; +} +Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback); +``` + + + +## Notification.isBadgeDisplayed(bundle: BundleOption) + +- Functionality + + Checks whether the badge will be displayed in notifications of a specified bundle. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ------ | -------- | ------------ | ---- | ---------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| + +- Return value + + Promise\ + +- Example + +```js +var bundle = { + bundle: "bundleName1"; +} +Notification.isBadgeDisplayed(bundle).then((data) => { + console.info("==========================>isBadgeDisplayedCallback=======================>"); +}); +``` + + + +## Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\) + +- Functionality + + Sets a notification slot for a specified bundle. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | -------------------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| +| slot | Read-only| NotificationSlot | Yes| Notification slot.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function setSlotByBundleCallback(err) { + console.info("==========================>setSlotByBundleCallback=======================>"); +} +var bundle = { + bundle: "bundleName1"; +} +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback); +``` + + + +## Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot) + +- Functionality + + Sets a notification slot for a specified bundle. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ------ | -------- | ------------ | ---- | ---------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| +| slot| Read-only| NotificationSlot| Yes| Notification slot.| + +- Return value + + Promise\ + +- Example + +```js +var bundle = { + bundle: "bundleName1"; +} +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +Notification.displayBadge(bundle, notificationSlot).then((void) => { + console.info("==========================>setSlotByBundleCallback=======================>"); +}); +``` + + + +## Notification.getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback>) + +- Functionality + + Obtains the notification slots of a specified bundle. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | ---------------------------------------- | ---- | -------------------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| +| callback | Read-only| AsyncCallback> | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function getSlotsByBundleCallback(err, data) { + console.info("==========================>getSlotsByBundleCallback=======================>"); +} +var bundle = { + bundle: "bundleName1"; +} +Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback); +``` + + + +## Notification.getSlotsByBundle(bundle: BundleOption) + +- Functionality + + Obtains the notification slots of a specified bundle. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ------ | -------- | ------------ | ---- | ---------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| + +- Return value + + Promise> + +- Example + +```js +var bundle = { + bundle: "bundleName1"; +} +Notification.getSlotsByBundle(bundle).then((data) => { + console.info("==========================>getSlotsByBundleCallback=======================>"); +}); +``` + + + +## Notification.getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\) + +- Functionality + + Obtains the number of notification slots of a specified bundle. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | ------------------------- | ---- | ---------------------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function getSlotNumByBundle(err, data) { + console.info("==========================>getSlotNumByBundleCallback=======================>"); +} +var bundle = { + bundle: "bundleName1"; +} +Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback); +``` + + + +## Notification.getSlotNumByBundle(bundle: BundleOption) + +- Functionality + + Obtains the number of notification slots of a specified bundle. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ------ | -------- | ------------ | ---- | ---------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| + +- Return value + + Promise\ + +- Example + +```js +var bundle = { + bundle: "bundleName1"; +} +Notification.getSlotNumByBundle(bundle).then((data) => { + console.info("==========================>getSlotNumByBundleCallback=======================>"); +}); +``` + + + +## Notification.remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback\) + +- Functionality + + Removes a notification for a specified bundle. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| --------------- | -------- | --------------------- | ---- | -------------------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| +| notificationKey | Read-only| NotificationKey | Yes| Notification key.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- NotificationKey + +| Name| Readable/Writable| Type| Mandatory| Description| +| ----- | -------- | ------ | ---- | -------- | +| id | Readable and writable| number | Yes| Notification ID.| +| label | Readable and writable| string | No| Notification label.| + +- Return value + + void + +- Example + +```js +function removeCallback(err) { + console.info("==========================>removeCallback=======================>"); +} +var bundle = { + bundle: "bundleName1"; +} +var notificationKey = { + id: 0; + label: "label"; +} +Notification.remove(bundle, notificationKey, removeCallback); +``` + + + +## Notification.remove(bundle: BundleOption, notificationKey: NotificationKey) + +- Functionality + + Removes a notification for a specified bundle. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| --------------- | -------- | --------------- | ---- | ---------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| +| notificationKey | Read-only| NotificationKey | Yes| Notification key.| + +- Return value + + Promise\ + +- Example + +```js +var bundle = { + bundle: "bundleName1"; +} +var notificationKey = { + id: 0; + label: "label"; +} +Notification.remove(bundle, notificationKey).then((void) => { + console.info("==========================>removeCallback=======================>"); +}); +``` + + + +## Notification.remove(hashCode: string, callback: AsyncCallback\) + +- Functionality + + Removes a notification. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | -------------------- | +| hashCode | Read-only| string | Yes| Unique notification ID.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function removeCallback(err) { + console.info("==========================>removeCallback=======================>"); +} + +Notification.remove(hashCode, removeCallback); +``` + + + +## Notification.remove(hashCode: string) + +- Functionality + + Removes a notification. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | ---------- | ---- | ---------- | +| hashCode | Read-only| string | Yes| Unique notification ID.| + +- Return value + + Promise\ + +- Example + +```js +Notification.remove(hashCode).then((void) => { + console.info("==========================>removeCallback=======================>"); +}); +``` + + + +## Notification.removeAll(bundle: BundleOption, callback: AsyncCallback\) + +- Functionality + + Removes all notifications for a specified bundle. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | ---------------------------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function removeAllCallback(err) { + console.info("==========================>removeAllCallback=======================>"); +} +var bundle = { + bundle: "bundleName1"; +} +Notification.removeAll(bundle, removeAllCallback); +``` + + + +## Notification.removeAll(callback: AsyncCallback\) + +- Functionality + + Removes all notifications. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | -------------------- | +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function removeAllCallback(err) { + console.info("==========================>removeAllCallback=======================>"); +} + +Notification.removeAll(removeAllCallback); +``` + + + +## Notification.removeAll(bundle?: BundleOption) + +- Functionality + + Removes all notifications for a specified bundle. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ------ | -------- | ------------ | ---- | ---------- | +| bundle | Read-only| BundleOption | No| Bundle information.| + +- Return value + + Promise\ + +- Example + +```js +Notification.removeAll().then((void) => { + console.info("==========================>removeAllCallback=======================>"); +}); +``` + + + +## Notification.getAllActiveNotifications(callback: AsyncCallback>) + +- Functionality + + Obtains all active notifications. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | ------------------------------------------- | ---- | -------------------- | +| callback | Read-only| AsyncCallback> | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function getAllActiveNotificationsCallback(err, data) { + console.info("==========================>getAllActiveNotificationsCallback=======================>"); +} + +Notification.getAllActiveNotifications(getAllActiveNotificationsCallback); +``` + + + +## Notification.getAllActiveNotifications() + +- Functionality + + Obtains all active notifications. This method uses a promise to return the result. + +- Parameters + + None + +- Return value + + Promise\\> + +- Example + +```js +Notification.getAllActiveNotifications().then((data) => { + console.info("==========================>getAllActiveNotificationsCallback=======================>"); +}); +``` + + + +## Notification.getActiveNotificationCount(callback: AsyncCallback\) + +- Functionality + + Obtains the number of active notifications. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | ---------------------- | ---- | ---------------------- | +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function getActiveNotificationCountCallback(err, data) { + console.info("==========================>getActiveNotificationCountCallback=======================>"); +} + +Notification.getActiveNotificationCount(getActiveNotificationCountCallback); +``` + + + +## Notification.getActiveNotificationCount() + +- Functionality + + Obtains the number of active notifications. This method uses a promise to return the result. + +- Parameters + + None + +- Return value + + Promise\ + +- Example + +```js +Notification.getActiveNotificationCount().then((data) => { + console.info("==========================>getActiveNotificationCountCallback=======================>"); +}); +``` + + + +## Notification.getActiveNotifications(callback: AsyncCallback>) + +- Functionality + + Obtains active notifications of the current application. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | ------------------------------------------- | ---- | ------------------------------ | +| callback | Read-only| AsyncCallback> | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function getActiveNotificationsCallback(err, data) { + console.info("==========================>getActiveNotificationsCallback=======================>"); +} + +Notification.getActiveNotifications(getActiveNotificationsCallback); +``` + + + +## Notification.getActiveNotifications() + +- Functionality + + Obtains active notifications. This method uses a promise to return the result. + +- Parameters + + None + +- Return value + + Promise\\> + +- Example + +```js +Notification.getActiveNotifications().then((data) => { + console.info("==========================>getActiveNotificationsCallback=======================>"); +}); +``` + + + +## Notification.cancelGroup(groupName: string, callback: AsyncCallback\) + +- Functionality + + Cancels a notification group of the current application. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| --------- | -------- | --------------------- | ---- | ---------------------------- | +| groupName | Read-only| string | Yes| Name of the notification group to cancel.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function cancelGroupCallback(err) { + console.info("==========================>cancelGroupCallback=======================>"); +} + +var groupName = "GroupName"; + +Notification.cancelGroup(groupName, cancelGroupCallback); +``` + + + +## Notification.cancelGroup(groupName: string) + +- Functionality + + Cancels a notification group of the current application. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| --------- | -------- | ------ | ---- | -------------- | +| groupName | Read-only| string | Yes| Name of the notification group to cancel.| + +- Return value + + Promise\ + +- Example + +```js +var groupName = "GroupName"; +Notification.cancelGroup(groupName).then(() => { + console.info("==========================>cancelGroupPromise=======================>"); +}); +``` + + + +## Notification.removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\) + +- Functionality + + Removes a notification group for a specified bundle. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| --------- | -------- | --------------------- | ---- | ---------------------------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| +| groupName | Read-only| string | Yes| Name of the notification group to remove.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function removeGroupByBundleCallback(err) { + console.info("==========================>removeGroupByBundleCallback=======================>"); +} + +var bundleOption = {bundle: "Bundle"}; +var groupName = "GroupName"; + +Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCallback); +``` + + + +## Notification.removeGroupByBundle(bundle: BundleOption, groupName: string) + +- Functionality + + Removes a notification group for a specified bundle. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| --------- | -------- | ------------ | ---- | -------------- | +| bundle | Read-only| BundleOption | Yes| Bundle information.| +| groupName | Read-only| string | Yes| Name of the notification group to remove.| + +- Return value + + Promise\ + +- Example + +```js +var bundleOption = {bundle: "Bundle"}; +var groupName = "GroupName"; +Notification.removeGroupByBundle(bundleOption, groupName).then(() => { + console.info("==========================>removeGroupByBundlePromise=======================>"); +}); +``` + + + +## Notification.setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\) + +- Functionality + + Sets the DND time. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | ---------------------- | +| date | Read-only| DoNotDisturbDate | Yes| DND time to set.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function setDoNotDisturbDateCallback(err) { + console.info("==========================>setDoNotDisturbDateCallback=======================>"); +} + +var doNotDisturbDate = { + type: notification.DoNotDisturbType.TYPE_ONCE, + begin: new Date(), + end: new Date(2021, 11, 15, 18, 0) +} + +Notification.setDoNotDisturbDate(doNotDisturbDate, setDoNotDisturbDateCallback); +``` + + + +## Notification.setDoNotDisturbDate(date: DoNotDisturbDate) + +- Functionality + + Sets the DND time. This method uses a promise to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ---- | -------- | ---------------- | ---- | -------------- | +| date | Read-only| DoNotDisturbDate | Yes| DND time to set.| + +- Return value + + Promise\ + +- Example + +```js +var doNotDisturbDate = { + type: notification.DoNotDisturbType.TYPE_ONCE, + begin: new Date(), + end: new Date(2021, 11, 15, 18, 0) +} +Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => { + console.info("==========================>setDoNotDisturbDatePromise=======================>"); +}); +``` + + + +## Notification.getDoNotDisturbDate(callback: AsyncCallback\) + +- Functionality + + Obtains the DND time. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------------------- | ---- | ---------------------- | +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function getDoNotDisturbDateCallback(err,data) { + console.info("==========================>getDoNotDisturbDateCallback=======================>"); +} + +Notification.getDoNotDisturbDate(getDoNotDisturbDateCallback); +``` + + + +## Notification.getDoNotDisturbDate() + +- Functionality + + Obtains the DND time. This method uses a promise to return the result. + +- Parameters + + None + +- Return value + + Promise\ + +- Example + +```js +Notification.getDoNotDisturbDate().then((data) => { + console.info("==========================>getDoNotDisturbDatePromise=======================>"); +}); +``` + + + +## Notification.supportDoNotDisturbMode(callback: AsyncCallback\) + +- Functionality + + Checks whether the DND mode is supported. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | ------------------------ | ---- | -------------------------------- | +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +function supportDoNotDisturbModeCallback(err,data) { + console.info("==========================>supportDoNotDisturbModeCallback=======================>"); +} + +Notification.supportDoNotDisturbMode(supportDoNotDisturbModeCallback); +``` + + + +## Notification.supportDoNotDisturbMode() + +- Functionality + + Checks whether the DND mode is supported. This method uses a promise to return the result. + +- Parameters + + None + +- Return value + + Promise\ + +- Example + +```js +Notification.supportDoNotDisturbMode().then((data) => { + console.info("==========================>supportDoNotDisturbModePromise=======================>"); +}); +``` + + + +## Notification.isSupportTemplate + +isSupportTemplate(templateName: string, callback: AsyncCallback\): void + +Checks whether a specified template exists. This method uses a callback to return the result. + +- Parameters + +| Name| Type| Mandatory| Description| +| ------------ | ------------------------ | ---- | -------------------------- | +| templateName | string | Yes| Template name.| +| callback | AsyncCallback\ | Yes| Callback used to return the result.| + +- Example + +```javascript +var templateName = 'process'; +function isSupportTemplateCallback(err, data) { + console.info("isSupportTemplateCallback"); +} + +Notification.isSupportTemplate(templateName, isSupportTemplateCallback); +``` + + + +## Notification.isSupportTemplate + +isSupportTemplate(templateName: string): Promise\ + +Checks whether a specified template exists. This method uses a promise to return the result. + +- Parameters + +| Name| Type| Mandatory| Description| +| ------------ | ------ | ---- | -------- | +| templateName | string | Yes| Name| + +- Return value + +| Type| Description| +| ------------------ | --------------- | +| Promise\ | Promise used to return the result.| + +- Example + +```javascript +var templateName = 'process'; + +Notification.isSupportTemplate(templateName).then((data) => { + console.info("isSupportTemplateCallback"); +}); +``` + + + +## NotificationTemplate + +Describes the template information. + +| Name| Type| Readable| Writable| Description| +| ---- | ---------------------- | ---- | ---- | -------- | +| name | string | Yes| Yes| Template name.| +| data | {[key:string]: Object} | Yes| Yes| Template data.| + + + +## WantAgent APIs + +## Modules to Import + +```js +import WantAgent from '@ohos.wantAgent'; +``` + +## WantAgent.getWantAgent(info: WantAgentInfo, callback: AsyncCallback\) + +- Functionality + + Obtains a **WantAgent** object. This method uses a callback to return the result. + +- Parameters + + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | -------------------------- | ---- | ----------------------- | +| info | Read-only| WantAgentInfo | Yes| Information about the **WantAgent** object to obtain.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- WantAgentInfo + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------------- | -------- | ------------------------------- | ---- | ---------------------- | +| wants | Readable and writable| Array\ | Yes| Array of all **Want** objects.| +| operationType | Readable and writable| wantAgent.OperationType | Yes| Type of the operation specified in a **Want** object.| +| requestCode | Readable and writable| number | Yes| Request code defined by the user.| +| wantAgentFlags | Readable and writable| Array | No| Array of flags for using the **WantAgent** object.| +| extraInfo | Readable and writable| {[key: string]: any} | No| Extra information.| + +- + WantAgentFlags + + +| Name| Readable/Writable| Type| Mandatory| Description| +| ------------------- | -------- | ---- | ---- | ------------------------------------------------------------ | +| ONE_TIME_FLAG | Read-only| enum | No| The **WantAgent** object can be used only once.| +| NO_BUILD_FLAG | Read-only| enum | No| The **WantAgent** object does not exist and hence it is not created. In this case, **null** is returned.| +| CANCEL_PRESENT_FLAG | Read-only| enum | No| The existing **WantAgent** object should be canceled before a new object is generated.| +| UPDATE_PRESENT_FLAG | Read-only| enum | No| Extra data of the existing **WantAgent** object is replaced with that of the new object.| +| CONSTANT_FLAG | Read-only| enum | No| The **WantAgent** object is immutable.| + +- OperationType + +| Name| Readable/Writable| Type| Mandatory| Description| +| ----------------- | -------- | ---- | ---- | ----------------------- | +| UNKNOWN_TYPE | Read-only| enum | No| Unknown operation.| +| START_ABILITY | Read-only| enum | No| Starts an ability with a UI.| +| START_ABILITIES | Read-only| enum | No| Starts multiple abilities with a UI.| +| START_SERVICE | Read-only| enum | No| Starts an ability without a UI.| +| SEND_COMMON_EVENT | Read-only| enum | No| Sends a common event.| + +- Return value + + void + +- Example + +```js +import WantAgent from '@ohos.wantAgent'; +import { OperationType, WantAgentFlags } from '@ohos.wantagent'; + +// getWantAgent callback +function getWantAgentCallback(err, data) { + console.info("==========================>getWantAgentCallback=======================>"); +} +// WantAgentInfo object +var wantAgentInfo = { + wants: [ + { + deviceId: "deviceId", + bundleName: "com.neu.setResultOnAbilityResultTest1", + abilityName: "com.example.test.MainAbility", + action: "action1", + entities: ["entity1"], + type: "MIMETYPE", + uri: "key={true,true,false}", + parameters: + { + mykey0: 2222, + mykey1: [1, 2, 3], + mykey2: "[1, 2, 3]", + mykey3: "ssssssssssssssssssssssssss", + mykey4: [false, true, false], + mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], + mykey6: true, + } + } + ], + operationType: OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] +} + +WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) +``` + + + +## WantAgent.getWantAgent(info: WantAgentInfo): Promise\ + +- Functionality + + Obtains a **WantAgent** object. This method uses a promise to return the result. + +- Parameters + + +| Name| Readable/Writable| Type| Mandatory| Description| +| ---- | -------- | ------------- | ---- | ------------- | +| info | Read-only| WantAgentInfo | Yes| Information about the **WantAgent** object to obtain.| + +- Return value + + Promise\ + +- Example + +```js +import WantAgent from '@ohos.wantAgent'; +import { OperationType, WantAgentFlags } from '@ohos.wantagent'; + +// WantAgentInfo object +var wantAgentInfo = { + wants: [ + { + deviceId: "deviceId", + bundleName: "com.neu.setResultOnAbilityResultTest1", + abilityName: "com.example.test.MainAbility", + action: "action1", + entities: ["entity1"], + type: "MIMETYPE", + uri: "key={true,true,false}", + parameters: + { + mykey0: 2222, + mykey1: [1, 2, 3], + mykey2: "[1, 2, 3]", + mykey3: "ssssssssssssssssssssssssss", + mykey4: [false, true, false], + mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], + mykey6: true, + } + } + ], + operationType: OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] +} + +WantAgent.getWantAgent(wantAgentInfo).then((data) => { + console.info("==========================>getWantAgentCallback=======================>"); +}); +``` + + + +## WantAgent.getBundleName(agent: WantAgent, callback: AsyncCallback\) + +- Functionality + + Obtains the bundle name of a **WantAgent** object. This method uses a callback to return the result. + +- Parameters + + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | ----------------------- | ---- | --------------------------------- | +| agent | Read-only| WantAgent | Yes| **WantAgent** object whose bundle name is to be obtained.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +import WantAgent from '@ohos.wantAgent'; +import { OperationType, WantAgentFlags } from '@ohos.wantagent'; + +// WantAgent object +var wantAgent; + +// getWantAgent callback +function getWantAgentCallback(err, data) { + console.info("==========================>getWantAgentCallback=======================>"); + if (err.code == 0) { + wantAgent = data; + } else { + console.info('----getWantAgent failed!----'); + } +} +// WantAgentInfo object +var wantAgentInfo = { + wants: [ + { + deviceId: "deviceId", + bundleName: "com.neu.setResultOnAbilityResultTest1", + abilityName: "com.example.test.MainAbility", + action: "action1", + entities: ["entity1"], + type: "MIMETYPE", + uri: "key={true,true,false}", + parameters: + { + mykey0: 2222, + mykey1: [1, 2, 3], + mykey2: "[1, 2, 3]", + mykey3: "ssssssssssssssssssssssssss", + mykey4: [false, true, false], + mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], + mykey6: true, + } + } + ], + operationType: OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] +} + +WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) + +// getBundleName callback +function getBundleNameCallback(err, data) { + console.info("==========================>getBundleNameCallback=======================>"); +} +WantAgent.getBundleName(wantAgent, getBundleNameCallback) +``` + + + +## WantAgent.getBundleName(agent: WantAgent): Promise\ + +- Functionality + + Obtains the bundle name of a **WantAgent** object. This method uses a promise to return the result. + +- Parameters + + +| Name| Readable/Writable| Type| Mandatory| Description| +| ----- | -------- | --------- | ---- | ------------- | +| agent | Read-only| WantAgent | Yes| **WantAgent** object whose bundle name is to be obtained.| + +- Return value + + Promise\ + +- Example + +```js +import WantAgent from '@ohos.wantAgent'; +import { OperationType, WantAgentFlags } from '@ohos.wantagent'; + +// WantAgent object +var wantAgent; + +// WantAgentInfo object +var wantAgentInfo = { + wants: [ + { + deviceId: "deviceId", + bundleName: "com.neu.setResultOnAbilityResultTest1", + abilityName: "com.example.test.MainAbility", + action: "action1", + entities: ["entity1"], + type: "MIMETYPE", + uri: "key={true,true,false}", + parameters: + { + mykey0: 2222, + mykey1: [1, 2, 3], + mykey2: "[1, 2, 3]", + mykey3: "ssssssssssssssssssssssssss", + mykey4: [false, true, false], + mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], + mykey6: true, + } + } + ], + operationType: OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] +} + +WantAgent.getWantAgent(wantAgentInfo).then((data) => { + console.info("==========================>getWantAgentCallback=======================>"); + wantAgent = data; +}); + +WantAgent.getBundleName(wantAgent).then((data) => { + console.info("==========================>getBundleNameCallback=======================>"); +}); +``` + + + +## WantAgent.getUid(agent: WantAgent, callback: AsyncCallback\) + +- Functionality + + Obtains the user ID of a **WantAgent** object. This method uses a callback to return the result. + +- Parameters + + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | ----------------------- | ---- | ----------------------------------- | +| agent | Read-only| WantAgent | Yes| **WantAgent** object whose user ID is to be obtained.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +import WantAgent from '@ohos.wantAgent'; +import { OperationType, WantAgentFlags } from '@ohos.wantagent'; + +// WantAgent object +var wantAgent; + +// getWantAgent callback +function getWantAgentCallback(err, data) { + console.info("==========================>getWantAgentCallback=======================>"); + if (err.code == 0) { + wantAgent = data; + } else { + console.info('----getWantAgent failed!----'); + } +} +// WantAgentInfo object +var wantAgentInfo = { + wants: [ + { + deviceId: "deviceId", + bundleName: "com.neu.setResultOnAbilityResultTest1", + abilityName: "com.example.test.MainAbility", + action: "action1", + entities: ["entity1"], + type: "MIMETYPE", + uri: "key={true,true,false}", + parameters: + { + mykey0: 2222, + mykey1: [1, 2, 3], + mykey2: "[1, 2, 3]", + mykey3: "ssssssssssssssssssssssssss", + mykey4: [false, true, false], + mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], + mykey6: true, + } + } + ], + operationType: OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] +} + +WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) + +// getUid callback +function getUidCallback(err, data) { + console.info("==========================>getUidCallback=======================>"); +} +WantAgent.getUid(wantAgent, getUidCallback) +``` + + + +## WantAgent.getUid(agent: WantAgent): Promise\ + +- Functionality + + Obtains the user ID of a **WantAgent** object. This method uses a promise to return the result. + +- Parameters + + +| Name| Readable/Writable| Type| Mandatory| Description| +| ----- | -------- | --------- | ---- | ------------- | +| agent | Read-only| WantAgent | Yes| **WantAgent** object whose user ID is to be obtained.| + +- Return value + + Promise\ + +- Example + +```js +import WantAgent from '@ohos.wantAgent'; +import { OperationType, WantAgentFlags } from '@ohos.wantagent'; + +// WantAgent object +var wantAgent; + +// WantAgentInfo object +var wantAgentInfo = { + wants: [ + { + deviceId: "deviceId", + bundleName: "com.neu.setResultOnAbilityResultTest1", + abilityName: "com.example.test.MainAbility", + action: "action1", + entities: ["entity1"], + type: "MIMETYPE", + uri: "key={true,true,false}", + parameters: + { + mykey0: 2222, + mykey1: [1, 2, 3], + mykey2: "[1, 2, 3]", + mykey3: "ssssssssssssssssssssssssss", + mykey4: [false, true, false], + mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], + mykey6: true, + } + } + ], + operationType: OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] +} + +WantAgent.getWantAgent(wantAgentInfo).then((data) => { + console.info("==========================>getWantAgentCallback=======================>"); + wantAgent = data; +}); + +WantAgent.getUid(wantAgent).then((data) => { + console.info("==========================>getUidCallback=======================>"); +}); +``` + + + +## WantAgent.getWant(agent: WantAgent, callback: AsyncCallback\) + +- Functionality + + Obtains the want in a **WantAgent** object. This method uses a callback to return the result. + +- Parameters + + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | ------------------------------- | +| agent | Read-only| WantAgent | Yes| **WantAgent** object.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +import WantAgent from '@ohos.wantAgent'; +import { OperationType, WantAgentFlags } from '@ohos.wantagent'; + +// WantAgent object +var wantAgent; + +// getWantAgent callback +function getWantAgentCallback(err, data) { + console.info("==========================>getWantAgentCallback=======================>"); + if (err.code == 0) { + wantAgent = data; + } else { + console.info('----getWantAgent failed!----'); + } +} +// WantAgentInfo object +var wantAgentInfo = { + wants: [ + { + deviceId: "deviceId", + bundleName: "com.neu.setResultOnAbilityResultTest1", + abilityName: "com.example.test.MainAbility", + action: "action1", + entities: ["entity1"], + type: "MIMETYPE", + uri: "key={true,true,false}", + parameters: + { + mykey0: 2222, + mykey1: [1, 2, 3], + mykey2: "[1, 2, 3]", + mykey3: "ssssssssssssssssssssssssss", + mykey4: [false, true, false], + mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], + mykey6: true, + } + } + ], + operationType: OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags:[WantAgentWantAgentFlags.UPDATE_PRESENT_FLAG] +} + +WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) + +// getWant callback +function getWantCallback(err, data) { + console.info("==========================>getWantCallback=======================>"); +} +WantAgent.getWant(wantAgent, getWantCallback) +``` + + + +## WantAgent.getWant(agent: WantAgent): Promise\ + +- Functionality + + Obtains the want in a **WantAgent** object. This method uses a promise to return the result. + +- Parameters + + +| Name| Readable/Writable| Type| Mandatory| Description| +| ----- | -------- | --------- | ---- | ------------- | +| agent | Read-only| WantAgent | Yes| **WantAgent** object.| + +- Return value + + Promise\ + +- Example + +```js +import WantAgent from '@ohos.wantAgent'; +import { OperationType, WantAgentFlags } from '@ohos.wantagent'; + +// WantAgent object +var wantAgent; + +// WantAgentInfo object +var wantAgentInfo = { + wants: [ + { + deviceId: "deviceId", + bundleName: "com.neu.setResultOnAbilityResultTest1", + abilityName: "com.example.test.MainAbility", + action: "action1", + entities: ["entity1"], + type: "MIMETYPE", + uri: "key={true,true,false}", + parameters: + { + mykey0: 2222, + mykey1: [1, 2, 3], + mykey2: "[1, 2, 3]", + mykey3: "ssssssssssssssssssssssssss", + mykey4: [false, true, false], + mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], + mykey6: true, + } + } + ], + operationType: OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] +} + +WantAgent.getWantAgent(wantAgentInfo).then((data) => { + console.info("==========================>getWantAgentCallback=======================>"); + wantAgent = data; +}); + +WantAgent.getWant(wantAgent).then((data) => { + console.info("==========================>getWantCallback=======================>"); +}); +``` + + + +## WantAgent.cancel(agent: WantAgent, callback: AsyncCallback\) + +- Functionality + + Cancels a **WantAgent** object. This method uses a callback to return the result. + +- Parameters + + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | --------------------- | ---- | --------------------------- | +| agent | Read-only| WantAgent | Yes| **WantAgent** object to cancel.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +import WantAgent from '@ohos.wantAgent'; +import { OperationType, WantAgentFlags } from '@ohos.wantagent'; + +// WantAgent object +var wantAgent; + +// getWantAgent callback +function getWantAgentCallback(err, data) { + console.info("==========================>getWantAgentCallback=======================>"); + if (err.code == 0) { + wantAgent = data; + } else { + console.info('----getWantAgent failed!----'); + } +} +// WantAgentInfo object +var wantAgentInfo = { + wants: [ + { + deviceId: "deviceId", + bundleName: "com.neu.setResultOnAbilityResultTest1", + abilityName: "com.example.test.MainAbility", + action: "action1", + entities: ["entity1"], + type: "MIMETYPE", + uri: "key={true,true,false}", + parameters: + { + mykey0: 2222, + mykey1: [1, 2, 3], + mykey2: "[1, 2, 3]", + mykey3: "ssssssssssssssssssssssssss", + mykey4: [false, true, false], + mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], + mykey6: true, + } + } + ], + operationType: OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] +} + +WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) + +// cancel callback +function cancelCallback(err, data) { + console.info("==========================>cancelCallback=======================>"); +} +WantAgent.cancel(wantAgent, cancelCallback) +``` + + + +## WantAgent.cancel(agent: WantAgent): Promise\ + +- Functionality + + Cancels a **WantAgent** object. This method uses a promise to return the result. + +- Parameters + + +| Name| Readable/Writable| Type| Mandatory| Description| +| ----- | -------- | --------- | ---- | ------------- | +| agent | Read-only| WantAgent | Yes| **WantAgent** object to cancel.| + +- Return value + + Promise\ + +- Example + +```js +import WantAgent from '@ohos.wantAgent'; +import { OperationType, WantAgentFlags } from '@ohos.wantagent'; + +// WantAgent object +var wantAgent; + +// WantAgentInfo object +var wantAgentInfo = { + wants: [ + { + deviceId: "deviceId", + bundleName: "com.neu.setResultOnAbilityResultTest1", + abilityName: "com.example.test.MainAbility", + action: "action1", + entities: ["entity1"], + type: "MIMETYPE", + uri: "key={true,true,false}", + parameters: + { + mykey0: 2222, + mykey1: [1, 2, 3], + mykey2: "[1, 2, 3]", + mykey3: "ssssssssssssssssssssssssss", + mykey4: [false, true, false], + mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], + mykey6: true, + } + } + ], + operationType: OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] +} + +WantAgent.getWantAgent(wantAgentInfo).then((data) => { + console.info("==========================>getWantAgentCallback=======================>"); + wantAgent = data; +}); + +WantAgent.cancel(wantAgent).then((data) => { + console.info("==========================>cancelCallback=======================>"); +}); +``` + + + +## WantAgent.trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback\) + +- Functionality + + Triggers a **WantAgent** object. This method uses a callback to return the result. + +- Parameters + + +| Name| Readable/Writable| Type| Mandatory| Description| +| ----------- | -------- | ----------------------------- | ---- | ------------------------------- | +| agent | Read-only| WantAgent | Yes| **WantAgent** object to trigger.| +| triggerInfo | Read-only| TriggerInfo | Yes| **TriggerInfo** object.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- TriggerInfo + +| Name| Readable/Writable| Type| Mandatory| Description| +| ---------- | -------- | -------------------- | ---- | ----------- | +| code | Readable and writable| number | Yes| Result code.| +| want | Readable and writable| Want | No| Want.| +| permission | Readable and writable| string | No| Permission.| +| extraInfo | Readable and writable| {[key: string]: any} | No| Extra information.| + +- Return value + + void + +- Example + +```js +import WantAgent from '@ohos.wantAgent'; +import { OperationType, WantAgentFlags } from '@ohos.wantagent'; + +// WantAgent object +var wantAgent; + +// getWantAgent callback +function getWantAgentCallback(err, data) { + console.info("==========================>getWantAgentCallback=======================>"); + if (err.code == 0) { + wantAgent = data; + } else { + console.info('----getWantAgent failed!----'); + } +} +// WantAgentInfo object +var wantAgentInfo = { + wants: [ + { + deviceId: "deviceId", + bundleName: "com.neu.setResultOnAbilityResultTest1", + abilityName: "com.example.test.MainAbility", + action: "action1", + entities: ["entity1"], + type: "MIMETYPE", + uri: "key={true,true,false}", + parameters: + { + mykey0: 2222, + mykey1: [1, 2, 3], + mykey2: "[1, 2, 3]", + mykey3: "ssssssssssssssssssssssssss", + mykey4: [false, true, false], + mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], + mykey6: true, + } + } + ], + operationType: OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] +} + +WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) + +//Trigger callback +function triggerCallback(err, data) { + console.info("==========================>triggerCallback=======================>"); +} + +var triggerInfo = { + code:0 +} +WantAgent.trigger(wantAgent, triggerInfo, triggerCallback) +``` + + + +## WantAgent.equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\) + +- Functionality + + Checks whether two **WantAgent** objects are equal. This method uses a callback to return the result. + +- Parameters + + +| Name| Readable/Writable| Type| Mandatory| Description| +| ---------- | -------- | ------------------------ | ---- | --------------------------------------- | +| agent | Read-only| WantAgent | Yes| The first **WantAgent** object.| +| otherAgent | Read-only| WantAgent | Yes| The second **WantAgent** object.| +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return value + + void + +- Example + +```js +import WantAgent from '@ohos.wantAgent'; +import { OperationType, WantAgentFlags } from '@ohos.wantagent'; + +// WantAgent object +var wantAgent1; +var wantAgent2; + +// getWantAgent callback +function getWantAgentCallback(err, data) { + console.info("==========================>getWantAgentCallback=======================>"); + if (err.code == 0) { + wantAgent1 = data; + wantAgent2 = data; + } else { + console.info('----getWantAgent failed!----'); + } +} +// WantAgentInfo object +var wantAgentInfo = { + wants: [ + { + deviceId: "deviceId", + bundleName: "com.neu.setResultOnAbilityResultTest1", + abilityName: "com.example.test.MainAbility", + action: "action1", + entities: ["entity1"], + type: "MIMETYPE", + uri: "key={true,true,false}", + parameters: + { + mykey0: 2222, + mykey1: [1, 2, 3], + mykey2: "[1, 2, 3]", + mykey3: "ssssssssssssssssssssssssss", + mykey4: [false, true, false], + mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], + mykey6: true, + } + } + ], + operationType: OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] +} + +WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) + +// equal callback +function equalCallback(err, data) { + console.info("==========================>equalCallback=======================>"); +} +WantAgent.equal(wantAgent1, wantAgent2, equalCallback) +``` + + + +## WantAgent.equal(agent: WantAgent, otherAgent: WantAgent): Promise\ + +- Functionality + + Checks whether two **WantAgent** objects are equal. This method uses a promise to return the result. + +- Parameters + + +| Name| Readable/Writable| Type| Mandatory| Description| +| ---------- | -------- | --------- | ---- | ------------- | +| agent | Read-only| WantAgent | Yes| The first **WantAgent** object.| +| otherAgent | Read-only| WantAgent | Yes| The second **WantAgent** object.| + +- Return value + + Promise\ + +- Example + +```js +import WantAgent from '@ohos.wantAgent'; +import { OperationType, WantAgentFlags } from '@ohos.wantagent'; + +// WantAgent object +var wantAgent1; +var wantAgent2; + +// WantAgentInfo object +var wantAgentInfo = { + wants: [ + { + deviceId: "deviceId", + bundleName: "com.neu.setResultOnAbilityResultTest1", + abilityName: "com.example.test.MainAbility", + action: "action1", + entities: ["entity1"], + type: "MIMETYPE", + uri: "key={true,true,false}", + parameters: + { + mykey0: 2222, + mykey1: [1, 2, 3], + mykey2: "[1, 2, 3]", + mykey3: "ssssssssssssssssssssssssss", + mykey4: [false, true, false], + mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], + mykey6: true, + } + } + ], + operationType: OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] +} + +WantAgent.getWantAgent(wantAgentInfo).then((data) => { + console.info("==========================>getWantAgentCallback=======================>"); + wantAgent1 = data; + wantAgent2 = data; +}); + +WantAgent.equal(wantAgent1, wantAgent2).then((data) => { + console.info("==========================>equalCallback=======================>"); +}); +``` + + + +#### diff --git a/en/application-dev/reference/apis/js-apis-particleAbility.md b/en/application-dev/reference/apis/js-apis-particleAbility.md new file mode 100644 index 0000000000..128d8282ba --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-particleAbility.md @@ -0,0 +1,394 @@ +# ParticleAbility Module + +## Applicable Devices + +| API | Phone| Tablet| Smart TV| Wearable| Lite Wearable| SmartVision Device| +| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -------------- | ------------ | +| particleAbility.startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\: void | Yes| Yes| Yes| Yes| No| No| +| particleAbility.startAbility(parameter: StartAbilityParameter): Promise\ | Yes| Yes| Yes| Yes| No| No| +| particleAbility.terminateSelf(callback: AsyncCallback\): void | Yes| Yes| Yes| Yes| No| No| +| particleAbility.terminateSelf(): Promise\ | Yes| Yes| Yes| Yes| No| No| +| particleAbility.acquireDataAbilityHelper(uri: string): DataAbilityHelper | Yes| Yes| Yes| Yes| No| No| +| particleAbility.connectAbility(request: Want, options:ConnectOptions): number | Yes| Yes| Yes| Yes| No| No| +| particleAbility.disconnectAbility(connection: number, callback:AsyncCallback\): void | Yes| Yes| Yes| Yes| No| No| +| particleAbility.disconnectAbility(connection: number): Promise\ | Yes| Yes| Yes| Yes| No| No| + +## Constraints + +The ParticleAbility module is used to perform operations on abilities of the Data and Service types. + +## Modules to Import + +```js +import particleAbility from '@ohos.ability.particleAbility' +``` + +## particleAbility.startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\: void + +- Functionality + + Starts a Service 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.| + +- Return values + + void + +- Example + +```js +import particleAbility from '@ohos.ability.particleAbility' +particleAbility.startAbility( + { + want: + { + action: "action.system.home", + entities: ["entity.system.home"], + type: "MIMETYPE", + flags: FLAG_AUTH_READ_URI_PERMISSION; + deviceId: "", + bundleName: "com.example.Data", + abilityName: "com.example.Data.MainAbility", + uri:"" + }, + }, + (error, result) => { + console.log('particleAbility startAbility errCode:' + error + 'result:' + result) + }, +) +``` + + + +## particleAbility.startAbility(parameter: StartAbilityParameter): Promise\ + +- Functionality +Starts a Service 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.| +- Return values + + Promise\ + +- Example + +```js +import particleAbility from '@ohos.ability.particleAbility' +particleAbility.startAbility( + { + want: + { + action: "action.system.home", + entities: ["entity.system.home"], + type: "MIMETYPE", + flags: FLAG_AUTH_READ_URI_PERMISSION; + deviceId: "", + bundleName: "com.example.Data", + abilityName: "com.example.Data.MainAbility", + uri:"" + }, + }, +).then((void) => { + console.info("particleAbility startAbility"); +}); +``` + + + +## particleAbility.terminateSelf(callback: AsyncCallback\): void + +- Functionality + + Terminates this Service ability. This method uses a callback to return the result. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| -------- | -------- | -------------------- | ---- | -------------------- | +| callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| + +- Return values + + void + +- Example + +```js +import particleAbility from '@ohos.ability.particleAbility' +particleAbility.terminateSelf( + (error, result) => { + console.log('particleAbility terminateSelf errCode:' + error + 'result:' + result) + } +) +``` + + + +## particleAbility.terminateSelf(): Promise\ + +- Functionality + + Terminates this Service ability. This method uses a promise to return the result. + +- Return values + + Promise\ + +- Example + +```js +import particleAbility from '@ohos.ability.particleAbility' +particleAbility.terminateSelf().then((void) => { + console.info("particleAbility terminateSelf"); +}); +``` + + + +## particleAbility.acquireDataAbilityHelper(uri: string): DataAbilityHelper + +- Functionality + + Obtains a **dataAbilityHelper** object. + +- Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| :--- | -------- | ------ | ---- | ---------------------- | +| uri | Read-only| string | Yes| URI of the file to open.| + +- Return values + +| Type| Description| +| ----------------- | ------------------------------------------ | +| DataAbilityHelper | A utility class used to help other abilities access a Data ability.| + +- Example + +```js +import particleAbility from '@ohos.ability.particleAbility' +var uri = ""; +particleAbility.acquireDataAbilityHelper(uri) +``` + +## particleAbility.connectAbility(request: Want, options:ConnectOptions): number + +* Functionality + + Connects this ability to a specific Service ability. This method uses a callback to return the result. + +* 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.| + +- ConnectOptions + +| Name| Readable/Writable| Type| Mandatory| Description| +| ------------ | -------- | -------- | ---- | ---------------------------------- | +| onConnect | Read-only| function | Yes| Callback invoked when the connection is set up.| +| 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. + +* Example + +```javascript +import particleAbility from '@ohos.ability.particleAbility' +function onConnectCallback(element, remote){ + console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy)); +} +function onDisconnectCallback(element){ + console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId) +} +function onFailedCallback(code){ + console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code) +} +var connId = particleAbility.connectAbility( + { + bundleName: "com.ix.ServiceAbility", + abilityName: "com.ix.ServiceAbility.ServiceAbilityA", + }, + { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback, + }, +); +``` + +## particleAbility.disconnectAbility(connection: number, callback:AsyncCallback\): void + +* Functionality + + Disconnects this ability from a specific Service ability. This method uses a callback to return the result. + +* 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.| + +* Return values + + void + +* Example + +```javascript +import particleAbility from '@ohos.ability.particleAbility' +function onConnectCallback(element, remote){ + console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy)); +} +function onDisconnectCallback(element){ + console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId) +} +function onFailedCallback(code){ + console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code) +} +var connId = particleAbility.connectAbility( + { + bundleName: "com.ix.ServiceAbility", + abilityName: "com.ix.ServiceAbility.ServiceAbilityA", + }, + { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback, + }, +); +var result = particleAbility.disconnectAbility(connId, + (error,data) => { + console.log('particleAbilityTest DisConnectAbility result errCode : ' + error.code + " data: " + data) + }, +); +``` + +## particleAbility.disconnectAbility(connection: number): Promise\ + +* Functionality + + Disconnects this ability from a specific Service ability. This method uses a promise to return the result. + +* Parameters + +| Name| Readable/Writable| Type| Mandatory| Description| +| ---------- | -------- | ------ | ---- | ------------------------------ | +| connection | Read-only| number | Yes| ID of the Service ability to disconnect.| + +* Return values + + Promise\ + +* Example + +```javascript +import particleAbility from '@ohos.ability.particleAbility' +function onConnectCallback(element, remote){ + console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy)); +} +function onDisconnectCallback(element){ + console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId) +} +function onFailedCallback(code){ + console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code) +} +var connId = particleAbility.connectAbility( + { + bundleName: "com.ix.ServiceAbility", + abilityName: "com.ix.ServiceAbility.ServiceAbilityA", + }, + { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback, + }, +); +var result = particleAbility.disconnectAbility(connId).then((void) => { + console.info("particleAbilityTest disconnectAbility"); +}); +``` + +## 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 + +| Name| Readable/Writable| Type| Mandatory| Description| +| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ | +| deviceId | Read-only| string | No| ID of the device running the ability to start.| +| bundleName | Read-only| string | No| Bundle name of the ability to start. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can directly match the specified ability.| +| abilityName | Read-only| string | No| Name of the ability to start. If both **bundleName** and **abilityName** are specified in a **Want** object, the **Want** object can directly match the specified ability.| +| uri | Read-only| string | No| URI information to match. If **uri** is specified in a **Want** object, the **Want** object will match the specified URI information, including **scheme**, **schemeSpecificPart**, **authority**, and **path**.| +| type | Read-only| string | No| MIME type, for example, **text/plain** or **image/***.| +| flags | Read-only| number | No| How the **Want** object will be handled. By default, numbers are passed in. For details, see [flags](#flags).| +| action | Read-only| string | No| Action option.| +| parameters | Read-only| {[key: string]: any} | No| List of parameters in the **Want** object.| +| entities | Read-only| Array\ | No| List of entities.| + +## flags + +| Name| Value| Description| +| ------------------------------------ | ---------- | ------------------------------------------------------------ | +| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Indicates the permission to read the URI.| +| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Indicates the permission to write the URI.| +| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | Returns the result to the ability.| +| FLAG_ABILITY_CONTINUATION | 0x00000008 | Indicates whether the ability on the local device can be migrated to a remote device.| +| FLAG_NOT_OHOS_COMPONENT | 0x00000010 | Indicates that a component does not belong to OHOS.| +| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | Indicates whether to enable an ability.| +| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Indicates the permission to make the URI persistent.| +| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | Indicates the permission to verify URIs by prefix matching.| +| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | Supports cross-device startup in a distributed scheduler.| +| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | Indicates that the Service ability is started regardless of whether the host application has been started.| +| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that the migration is reversible.| +| FLAG_INSTALL_ON_DEMAND | 0x00000800 | Indicates that the specific ability will be installed if it has not been installed.| +| FLAG_INSTALL_WITH_BACKGROUND_MODE | 0x80000000 | Indicates that the specific ability will be installed in the background if it has not been installed.| +| FLAG_ABILITY_CLEAR_MISSION | 0x00008000 | Clears other operation missions. This flag can be set for the **Want** object passed to **ohos.app.Context#startAbility** and must be used together with **flag_ABILITY_NEW_MISSION**.| +| FLAG_ABILITY_NEW_MISSION | 0x10000000 | Creates a mission on the historical mission stack.| +| FLAG_ABILITY_MISSION_TOP | 0x20000000 | Starts the mission on the top of the existing mission stack; creates an ability instance if no mission exists.| + +## 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**. + +| Name| Value| Description| +| --------------- | --------------- | -------------------------- | +| BOUNDS_KEY | "abilityBounds" | Ability window size.| +| WINDOW_MODE_KEY | "windowMode" | Ability window display mode.| +| DISPLAY_ID_KEY | "displayId" | Display device ID.| + +## AbilityWindowConfiguration + +Defines the window display modes of a Page ability, for example, **featureAbility.AbilityWindowConfiguration.WINDOW_MODE_UNDEFINED**. + +| Name| Value| Description| +| --------------------------- | ---- | ---------- | +| WINDOW_MODE_UNDEFINED | 0 | The Page ability is in an undefined window display mode.| +| WINDOW_MODE_FULLSCREEN | 1 | The Page ability is in full screen mode.| +| WINDOW_MODE_SPLIT_PRIMARY | 100 | The Page ability is displayed in the primary window when it is in split-screen mode.| +| WINDOW_MODE_SPLIT_SECONDARY | 101 | The Page ability is displayed in the secondary window when it is in split-screen mode.| +| WINDOW_MODE_FLOATING | 102 | The Page ability is displayed in floating window mode.| -- GitLab