diff --git a/en/application-dev/reference/apis/commonEvent-definitions.md b/en/application-dev/reference/apis/commonEvent-definitions.md index b7cfc06174bbd90c193b1e98d4aa5330597a4b8f..39aa5fa3df076dde861d8020f0066f0dadd6b800 100644 --- a/en/application-dev/reference/apis/commonEvent-definitions.md +++ b/en/application-dev/reference/apis/commonEvent-definitions.md @@ -59,7 +59,7 @@ Indicates that the device screen is on and the device is in interactive state. - Required subscriber permissions: none -## COMMON_EVENT_THERMAL_LEVEL_CHANGED8+ +## COMMON_EVENT_THERMAL_LEVEL_CHANGED8+ Indicates that the device's thermal level has changed. - Value: **usual.event.THERMAL_LEVEL_CHANGED** - Required subscriber permissions: none @@ -810,7 +810,7 @@ Indicates that a USB device has been detached from the device functioning as a U ## COMMON_EVENT_DISK_BAD_REMOVAL (Reserved, not supported yet) Indicates that an external storage device was removed without being unmounted. -- Value: usual.event.data.DISK_BAD_REMOVAL +- Value: **usual.event.data.DISK_BAD_REMOVAL** - Required subscriber permissions: ohos.permission.STORAGE_MANAGER @@ -826,33 +826,33 @@ Indicates that a USB device has been detached from the device functioning as a U - Required subscriber permissions: ohos.permission.STORAGE_MANAGER -## COMMON_EVENT_VOLUME_REMOVED9+ +## COMMON_EVENT_VOLUME_REMOVED9+ Indicates that an external storage device was removed. - Value: **usual.event.data.VOLUME_REMOVED** - Required subscriber permissions: ohos.permission.STORAGE_MANAGER -## COMMON_EVENT_VOLUME_UNMOUNTED9+ +## COMMON_EVENT_VOLUME_UNMOUNTED9+ Indicates that an external storage device was unmounted. - Value: **usual.event.data.VOLUME_UNMOUNTED** - Required subscriber permissions: ohos.permission.STORAGE_MANAGER -## COMMON_EVENT_VOLUME_MOUNTED9+ +## COMMON_EVENT_VOLUME_MOUNTED9+ Indicates that an external storage device was mounted. - Value: **usual.event.data.VOLUME_MOUNTED** - Required subscriber permissions: ohos.permission.STORAGE_MANAGER -## COMMON_EVENT_VOLUME_BAD_REMOVAL9+ +## COMMON_EVENT_VOLUME_BAD_REMOVAL9+ Indicates that an external storage device was removed without being unmounted. - Value: **usual.event.data.VOLUME_BAD_REMOVAL** - Required subscriber permissions: ohos.permission.STORAGE_MANAGER -## COMMON_EVENT_VOLUME_EJECT9+ +## COMMON_EVENT_VOLUME_EJECT9+ Indicates that an external storage device was ejected (at the software level). -- Value: usual.event.data.VOLUME_EJECT +- **Value: usual.event.data.VOLUME_EJECT** - Required subscriber permissions: ohos.permission.STORAGE_MANAGER @@ -880,25 +880,30 @@ Indicates that the airplane mode of the device has changed. - Required subscriber permissions: none -## COMMON_EVENT_SPLIT_SCREEN8+ +## COMMON_EVENT_SPLIT_SCREEN8+ Indicates that the screen has been split. - Value: **usual.event.SPLIT_SCREEN** - Required subscriber permissions: none -## COMMON_EVENT_SLOT_CHANGE9+ +## COMMON_EVENT_SLOT_CHANGE9+ Indicates that the notification slot has been updated. - Value: **usual.event.SLOT_CHANGE** - Required subscriber permissions: ohos.permission.NOTIFICATION_CONTROLLER -## COMMON_EVENT_SPN_INFO_CHANGED9+ +## COMMON_EVENT_SPN_INFO_CHANGED9+ Indicates that the SPN displayed has been updated. - Value: **usual.event.SPN_INFO_CHANGED** - Required subscriber permissions: none -## COMMON_EVENT_QUICK_FIX_APPLY_RESULT9+ +## COMMON_EVENT_QUICK_FIX_APPLY_RESULT9+ Indicates the result of applying a quick fix to the application. - Value: **usual.event.QUICK_FIX_APPLY_RESULT** - Required subscriber permissions: none + +## COMMON_EVENT_USER_INFO_UPDATED9+ +Indicates that the user information has been updated. +- Value: **usual.event.USER_INFO_UPDATED** +- Required subscriber permissions: none diff --git a/en/application-dev/reference/apis/commonEventManager-definitions.md b/en/application-dev/reference/apis/commonEventManager-definitions.md index 3701910204a1a924986d9d6ff8ae144886cc5856..0670b6ca701ef78962deea0085dfbe2db1cbe863 100644 --- a/en/application-dev/reference/apis/commonEventManager-definitions.md +++ b/en/application-dev/reference/apis/commonEventManager-definitions.md @@ -59,7 +59,7 @@ Indicates that the device screen is on and the device is in interactive state. - Required subscriber permissions: none -## COMMON_EVENT_THERMAL_LEVEL_CHANGED8+ +## COMMON_EVENT_THERMAL_LEVEL_CHANGED8+ Indicates that the device's thermal level has changed. - Value: **usual.event.THERMAL_LEVEL_CHANGED** - Required subscriber permissions: none @@ -658,6 +658,10 @@ Indicates that the system starts charging the battery. - Value: **usual.event.CHARGING** - Required subscriber permissions: none +## COMMON_EVENT_CHARGE_TYPE_CHANGED +Indicates that the system charging type has changed. This event is available only for system applications. +- Value: **usual.event.CHARGE_TYPE_CHANGED** +- Required subscriber permissions: none ## COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED (Reserved, not supported yet) Indicates that the system idle mode has changed. @@ -845,31 +849,31 @@ Indicates that a USB device has been detached from the device functioning as a U - Required subscriber permissions: ohos.permission.STORAGE_MANAGER -## COMMON_EVENT_VOLUME_REMOVED9+ +## COMMON_EVENT_VOLUME_REMOVED9+ Indicates that an external storage device was removed. - Value: **usual.event.data.VOLUME_REMOVED** - Required subscriber permissions: ohos.permission.STORAGE_MANAGER -## COMMON_EVENT_VOLUME_UNMOUNTED9+ +## COMMON_EVENT_VOLUME_UNMOUNTED9+ Indicates that an external storage device was unmounted. - Value: **usual.event.data.VOLUME_UNMOUNTED** - Required subscriber permissions: ohos.permission.STORAGE_MANAGER -## COMMON_EVENT_VOLUME_MOUNTED9+ +## COMMON_EVENT_VOLUME_MOUNTED9+ Indicates that an external storage device was mounted. - Value: **usual.event.data.VOLUME_MOUNTED** - Required subscriber permissions: ohos.permission.STORAGE_MANAGER -## COMMON_EVENT_VOLUME_BAD_REMOVAL9+ +## COMMON_EVENT_VOLUME_BAD_REMOVAL9+ Indicates that an external storage device was removed without being unmounted. - Value: **usual.event.data.VOLUME_BAD_REMOVAL** - Required subscriber permissions: ohos.permission.STORAGE_MANAGER -## COMMON_EVENT_VOLUME_EJECT9+ +## COMMON_EVENT_VOLUME_EJECT9+ Indicates that an external storage device was ejected (at the software level). - Value: usual.event.data.VOLUME_EJECT - Required subscriber permissions: ohos.permission.STORAGE_MANAGER @@ -905,23 +909,23 @@ Indicates that the screen has been split. - Required subscriber permissions: ohos.permission.RECEIVER_SPLIT_SCREEN -## COMMON_EVENT_SLOT_CHANGE9+ +## COMMON_EVENT_SLOT_CHANGE9+ Indicates that the notification slot has been updated. - Value: **usual.event.SLOT_CHANGE** - Required subscriber permissions: ohos.permission.NOTIFICATION_CONTROLLER -## COMMON_EVENT_SPN_INFO_CHANGED9+ +## COMMON_EVENT_SPN_INFO_CHANGED9+ Indicates that the SPN displayed has been updated. - Value: **usual.event.SPN_INFO_CHANGED** - Required subscriber permissions: none -## COMMON_EVENT_QUICK_FIX_APPLY_RESULT9+ +## COMMON_EVENT_QUICK_FIX_APPLY_RESULT9+ Indicates the result of applying a quick fix to the application. - Value: **usual.event.QUICK_FIX_APPLY_RESULT** - Required subscriber permissions: none -## COMMON_EVENT_HTTP_PROXY_CHANGE10+ +## COMMON_EVENT_HTTP_PROXY_CHANGE10+ Indicates that the HTTP proxy configuration has changed. - Value: **usual.event.HTTP_PROXY_CHANGE** - Required subscriber permissions: none diff --git a/en/application-dev/reference/apis/js-apis-commonEvent.md b/en/application-dev/reference/apis/js-apis-commonEvent.md index 613913c3635b0f4d4c235e02428faf9a18b9f4b0..1496c18abf062e412dcc36368d046992b7f95c69 100644 --- a/en/application-dev/reference/apis/js-apis-commonEvent.md +++ b/en/application-dev/reference/apis/js-apis-commonEvent.md @@ -67,7 +67,7 @@ Publishes a common event with given attributes. This API uses an asynchronous ca | Name | Type | Mandatory| Description | | -------- | ---------------------- | ---- | ---------------------- | | event | string | Yes | Name of the common event to publish. | -| options | [CommonEventPublishData](#commoneventpublishdata) | Yes | Attributes of the common event to publish.| +| options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | Yes | Attributes of the common event to publish.| | callback | syncCallback\ | Yes | Callback used to return the result. | **Example** @@ -76,8 +76,8 @@ Publishes a common event with given attributes. This API uses an asynchronous ca ```ts // Attributes of a common event. let options = { - code: 0, // Initial code of the common event. - data: "initial data";// Initial data of the common event. + 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. } @@ -151,7 +151,7 @@ Publishes a common event with given attributes to a specific user. This API uses | -------- | ---------------------- | ---- | ---------------------- | | event | string | Yes | Name of the common event to publish. | | userId | number | Yes| User ID.| -| options | [CommonEventPublishData](#commoneventpublishdata) | Yes | Attributes of the common event to publish.| +| options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | Yes | Attributes of the common event to publish.| | callback | AsyncCallback\ | Yes | Callback used to return the result. | **Example** @@ -194,8 +194,8 @@ Creates a subscriber. This API uses an asynchronous callback to return the resul | Name | Type | Mandatory| Description | | ------------- | ------------------------------------------------------------ | ---- | -------------------------- | -| subscribeInfo | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | Yes | Subscriber information. | -| callback | AsyncCallback\<[CommonEventSubscriber](#commoneventsubscriber)> | Yes | Callback used to return the result.| +| subscribeInfo | [CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md) | Yes | Subscriber information. | +| callback | AsyncCallback\<[CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md)> | Yes | Callback used to return the result.| **Example** @@ -236,12 +236,12 @@ Creates a subscriber. This API uses a promise to return the result. | Name | Type | Mandatory| Description | | ------------- | ----------------------------------------------------- | ---- | -------------- | -| subscribeInfo | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | Yes | Subscriber information.| +| subscribeInfo | [CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md) | Yes | Subscriber information.| **Return value** | Type | Description | | --------------------------------------------------------- | ---------------- | -| Promise\<[CommonEventSubscriber](#commoneventsubscriber)> | Promise used to return the subscriber object.| +| Promise\<[CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md)> | Promise used to return the subscriber object.| **Example** @@ -276,8 +276,8 @@ Subscribes to common events. This API uses an asynchronous callback to return th | Name | Type | Mandatory| Description | | ---------- | ---------------------------------------------------- | ---- | -------------------------------- | -| subscriber | [CommonEventSubscriber](#commoneventsubscriber) | Yes | Subscriber object. | -| callback | AsyncCallback\<[CommonEventData](#commoneventdata)> | Yes | Callback used to return the result.| +| subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md) | Yes | Subscriber object. | +| callback | AsyncCallback\<[CommonEventData](./js-apis-inner-commonEvent-commonEventData.md)> | Yes | Callback used to return the result.| **Example** @@ -299,11 +299,12 @@ function subscribeCB(err, data) { } // Callback for subscriber creation. -function createCB(err, subscriber) { +function createCB(err, commonEventSubscriber) { if (err.code) { console.error(`createSubscriber failed, code is ${err.code}`); } else { console.info("createSubscriber"); + subscriber = commonEventSubscriber; // Subscribe to a common event. CommonEvent.subscribe(subscriber, subscribeCB); } @@ -327,7 +328,7 @@ Unsubscribes from common events. This API uses an asynchronous callback to retur | Name | Type | Mandatory| Description | | ---------- | ----------------------------------------------- | ---- | ------------------------ | -| subscriber | [CommonEventSubscriber](#commoneventsubscriber) | Yes | Subscriber object. | +| subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md) | Yes | Subscriber object. | | callback | AsyncCallback\ | No | Callback used to return the result.| **Example** @@ -376,800 +377,3 @@ CommonEvent.createSubscriber(subscribeInfo, createCB); // Unsubscribe from the common event. CommonEvent.unsubscribe(subscriber, unsubscribeCB); ``` - -## CommonEventSubscriber - -### getCode - -```ts -getCode(callback: AsyncCallback): void -``` - -Obtains the code of this common event. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ---------------------- | ---- | ------------------ | -| callback | AsyncCallback\ | Yes | Common event code.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for result code obtaining of an ordered common event. -function getCodeCB(err, Code) { - if (err.code) { - console.error(`getCode failed, code is ${err.code}`); - } else { - console.info("getCode " + JSON.stringify(Code)); - } -} -subscriber.getCode(getCodeCB); -``` - -### getCode - -```ts -getCode(): Promise -``` - -Obtains the code of this common event. This API uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ---------------- | -------------------- | -| Promise\ | Common event code.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.getCode().then((code) => { - console.info("getCode " + JSON.stringify(code)); -}).catch((err) => { - console.error(`getCode failed, code is ${err.code}`); -}); -``` - -### setCode - -```ts -setCode(code: number, callback: AsyncCallback): void -``` - -Sets the code for this common event. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ---------------------- | -| code | number | Yes | Common event code. | -| callback | AsyncCallback\ | Yes | Callback used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for result code setting of an ordered common event. -function setCodeCB(err) { - if (err.code) { - console.error(`setCode failed, code is ${err.code}`); - } else { - console.info("setCode"); - } -} -subscriber.setCode(1, setCodeCB); -``` - -### setCode - -```ts -setCode(code: number): Promise -``` - -Sets the code for this common event. This API uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name| Type | Mandatory| Description | -| ------ | ------ | ---- | ------------------ | -| code | number | Yes | Common event code.| - -**Return value** - -| Type | Description | -| ---------------- | -------------------- | -| Promise\ | Promise used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.setCode(1).then(() => { - console.info("setCode"); -}).catch((err) => { - console.error(`setCode failed, code is ${err.code}`); -}); -``` - -### getData - -```ts -getData(callback: AsyncCallback): void -``` - -Obtains the data of this common event. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ---------------------- | ---- | -------------------- | -| callback | AsyncCallback\ | Yes | Common event data.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for result data obtaining of an ordered common event. -function getDataCB(err, data) { - if (err.code) { - console.error(`getData failed, code is ${err.code}`); - } else { - console.info("getData " + JSON.stringify(data)); - } -} - -subscriber.getData(getDataCB); -``` - -### getData - -```ts -getData(): Promise -``` - -Obtains the data of this common event. This API uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ---------------- | ------------------ | -| Promise\ | Common event data.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.getData().then((data) => { - console.info("getData " + JSON.stringify(data)); -}).catch((err) => { - console.error(`getData failed, code is ${err.code}`); -}); -``` - -### setData - -```ts -setData(data: string, callback: AsyncCallback): void -``` - -Sets the data for this common event. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------- | -| data | string | Yes | Common event data. | -| callback | AsyncCallback\ | Yes | Callback used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for result data setting of an ordered common event -function setDataCB(err) { - if (err.code) { - console.error(`sendData failed, code is ${err.code}`); - } else { - console.info("setData"); - } -} -subscriber.setData("publish_data_changed", setDataCB); -``` - -### setData - -```ts -setData(data: string): Promise -``` - -Sets the data for this common event. This API uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name| Type | Mandatory| Description | -| ------ | ------ | ---- | -------------------- | -| data | string | Yes | Common event data.| - -**Return value** - -| Type | Description | -| ---------------- | -------------------- | -| Promise\ | Promise used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.setData("publish_data_changed").then(() => { - console.info("setData"); -}).catch((err) => { - console.error(`setData failed, code is ${err.code}`); -}); -``` - -### setCodeAndData - -```ts -setCodeAndData(code: number, data: string, callback:AsyncCallback): void -``` - -Sets the code and data for this common event. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ---------------------- | -| code | number | Yes | Common event code. | -| data | string | Yes | Common event data. | -| callback | AsyncCallback\ | Yes | Callback used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for result code and result data setting of an ordered common event. -function setCodeDataCB(err) { - if (err.code) { - console.error(`setCodeAndData failed, code is ${err.code}`); - } else { - console.info("setCodeDataCallback"); - } -} - -subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCB); -``` - -### setCodeAndData - -```ts -setCodeAndData(code: number, data: string): Promise -``` - -Sets the code and data for this common event. This API uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name| Type | Mandatory| Description | -| ------ | ------ | ---- | -------------------- | -| code | number | Yes | Common event code.| -| data | string | Yes | Common event data.| - -**Return value** - -| Type | Description | -| ---------------- | -------------------- | -| Promise\ | Promise used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.setCodeAndData(1, "publish_data_changed").then(() => { - console.info("setCodeAndData"); -}).catch((err) => { - console.error(`setCodeAndData failed, code is ${err.code}`); -}); -``` - -### isOrderedCommonEvent - -```ts -isOrderedCommonEvent(callback: AsyncCallback): void -``` - -Checks whether this common event is an ordered one. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | ---------------------------------- | -| callback | AsyncCallback\ | Yes | Returns **true** if the common event is an ordered one; returns **false** otherwise.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for checking whether the current common event is an ordered one. -function isOrderedCB(err, isOrdered) { - if (err.code) { - console.error(`isOrderedCommonEvent failed, code is ${err.code}`); - } else { - console.info("isOrdered " + JSON.stringify(isOrdered)); - } -} -subscriber.isOrderedCommonEvent(isOrderedCB); -``` - -### isOrderedCommonEvent - -```ts -isOrderedCommonEvent(): Promise -``` - -Checks whether this common event is an ordered one. This API uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ----------------- | -------------------------------- | -| Promise\ | Returns **true** if the common event is an ordered one; returns **false** otherwise.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.isOrderedCommonEvent().then((isOrdered) => { - console.info("isOrdered " + JSON.stringify(isOrdered)); -}).catch((err) => { - console.error(`isOrderedCommonEvent failed, code is ${err.code}`); -}); -``` - -### isStickyCommonEvent - -```ts -isStickyCommonEvent(callback: AsyncCallback): void -``` - -Checks whether this common event is a sticky one. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | ---------------------------------- | -| callback | AsyncCallback\ | Yes | Returns **true** if the common event is a sticky one; returns **false** otherwise.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for checking whether the current common event is a sticky one. -function isStickyCB(err, isSticky) { - if (err.code) { - console.error(`isStickyCommonEvent failed, code is ${err.code}`); - } else { - console.info("isSticky " + JSON.stringify(isSticky)); - } -} -subscriber.isStickyCommonEvent(isStickyCB); -``` - -### isStickyCommonEvent - -```ts -isStickyCommonEvent(): Promise -``` - -Checks whether this common event is a sticky one. This API uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ----------------- | -------------------------------- | -| Promise\ | Returns **true** if the common event is a sticky one; returns **false** otherwise.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.isStickyCommonEvent().then((isSticky) => { - console.info("isSticky " + JSON.stringify(isSticky)); -}).catch((err) => { - console.error(`isSticky failed, code is ${err.code}`); -}); -``` - -### abortCommonEvent - -```ts -abortCommonEvent(callback: AsyncCallback): void -``` - -Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------- | -| callback | AsyncCallback\ | Yes | Callback used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for common event aborting. -function abortCB(err) { - if (err.code) { - console.error(`abortCommonEvent failed, code is ${err.code}`); - } else { - console.info("abortCommonEvent"); - } -} - -subscriber.abortCommonEvent(abortCB); -``` - -### abortCommonEvent - -```ts -abortCommonEvent(): Promise -``` - -Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API takes effect only for ordered common events. It uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ---------------- | -------------------- | -| Promise\ | Promise used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.abortCommonEvent().then(() => { - console.info("abortCommonEvent"); -}).catch((err) => { - console.error(`abortCommonEvent failed, code is ${err.code}`); -}); -``` - -### clearAbortCommonEvent - -```ts -clearAbortCommonEvent(callback: AsyncCallback): void -``` - -Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------- | -| callback | AsyncCallback\ | Yes | Callback used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for clearing the aborted state of the current common event. -function clearAbortCB(err) { - if (err.code) { - console.error(`clearAbortCommonEvent failed, code is ${err.code}`); - } else { - console.info("clearAbortCommonEvent"); - } -} - -subscriber.clearAbortCommonEvent(clearAbortCB); -``` - -### clearAbortCommonEvent - -```ts -clearAbortCommonEvent(): Promise -``` - -Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ---------------- | -------------------- | -| Promise\ | Promise used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.clearAbortCommonEvent().then(() => { - console.info("clearAbortCommonEvent"); -}).catch((err) => { - console.error(`clearAbortCommonEvent failed, code is ${err.code}`); -}); -``` - -### getAbortCommonEvent - -```ts -getAbortCommonEvent(callback: AsyncCallback): void -``` - -Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | ---------------------------------- | -| callback | AsyncCallback\ | Yes | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for checking whether the current common event is in the aborted state. -function getAbortCB(err, abortEvent) { - if (err.code) { - console.error(`getAbortCommonEvent failed, code is ${err.code}`); - } else { - console.info("abortEvent " + abortEvent) - } -} - -subscriber.getAbortCommonEvent(getAbortCB); -``` - -### getAbortCommonEvent - -```ts -getAbortCommonEvent(): Promise -``` - -Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ----------------- | ---------------------------------- | -| Promise\ | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.getAbortCommonEvent().then((abortCommonEvent) => { - console.info("abortCommonEvent " + JSON.stringify(abortCommonEvent)); -}).catch((err) => { - console.error(`getAbortCommonEvent failed, code is ${err.code}`); -}); -``` - -### getSubscribeInfo - -```ts -getSubscribeInfo(callback: AsyncCallback): void -``` - -Obtains the subscriber information. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ---------------------- | -| callback | AsyncCallback\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Yes | Promise used to return the subscriber information.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for subscriber information obtaining. -function getCB(err, subscribeInfo) { - if (err.code) { - console.error(`getSubscribeInfo failed, code is ${err.code}`); - } else { - console.info("SubscribeInfo " + JSON.stringify(subscribeInfo)); - } -} - -subscriber.getSubscribeInfo(getCB); -``` - -### getSubscribeInfo - -```ts -getSubscribeInfo(): Promise -``` - -Obtains the subscriber information. This API uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ------------------------------------------------------------ | ---------------------- | -| Promise\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Promise used to return the subscriber information.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.getSubscribeInfo().then((subscribeInfo) => { - console.info("subscribeInfo " + JSON.stringify(subscribeInfo)); -}).catch((err) => { - console.error(`getSubscribeInfo failed, code is ${err.code}`); -}); -``` - -### finishCommonEvent9+ - -```ts -finishCommonEvent(callback: AsyncCallback): void -``` - -Finishes this common event. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------------------- | -| callback | AsyncCallback\ | Yes | Callback returned after the ordered common event is finished.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for ordered common event finishing. -function finishCB(err) { - if (err.code) { - console.error(`finishCommonEvent failed, code is ${err.code}`); - } else { - console.info("FinishCommonEvent"); - } -} - -subscriber.finishCommonEvent(finishCB); -``` - -### finishCommonEvent9+ - -```ts -finishCommonEvent(): Promise -``` - -Finishes this common event. This API takes effect only for ordered common events. It uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ---------------- | -------------------- | -| Promise\ | Promise used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.finishCommonEvent().then(() => { - console.info("FinishCommonEvent"); -}).catch((err) => { - console.error(`finishCommonEvent failed, code is ${err.code}`); -}); -``` - -## CommonEventData - -Describes the common event data body. - -**System capability**: SystemCapability.Notification.CommonEvent - -| Name | Type | Readable| Writable| Description | -| ---------- |-------------------- | ---- | ---- | ------------------------------------------------------- | -| event | string | Yes | No | Name of the common event that is being received. | -| bundleName | string | Yes | No | Bundle name. | -| code | number | Yes | No | Result code of the common event, which is used to transfer data of the int type. | -| data | string | Yes | No | Custom result data of the common event, which is used to transfer data of the string type.| -| parameters | {[key: string]: any} | Yes | No | Additional information about the common event. | - - -## CommonEventPublishData - -Describes the data body published by a common event, including the common event content and attributes. - -**System capability**: SystemCapability.Notification.CommonEvent - -| Name | Type | Readable| Writable| Description | -| --------------------- | -------------------- | ---- | ---- | ---------------------------- | -| bundleName | string | Yes | No | Bundle name. | -| code | number | Yes | No | Result code of the common event. | -| data | string | Yes | No | Custom result data of the common event.| -| subscriberPermissions | Array\ | Yes | No | Permissions required for subscribers to receive the common event. | -| isOrdered | boolean | Yes | No | Whether the common event is an ordered one. | -| isSticky | boolean | Yes | No | Whether the common event is a sticky one. Only system applications and system services are allowed to send sticky events.| -| parameters | {[key: string]: any} | Yes | No | Additional information about the common event. | - -## CommonEventSubscribeInfo - -Provides the subscriber information. - -**System capability**: SystemCapability.Notification.CommonEvent - -| Name | Type | Readable| Writable| Description | -| ------------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | -| events | Array\ | Yes | No | Name of the common event to publish. | -| publisherPermission | string | Yes | No | Permissions required for publishers to publish the common event. | -| publisherDeviceId | string | Yes | No | Device ID. The value must be the ID of an existing device on the same network. | -| userId | number | Yes | 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 | number | Yes | No | Subscriber priority. The value ranges from -100 to +1000. | diff --git a/en/application-dev/reference/apis/js-apis-commonEventManager.md b/en/application-dev/reference/apis/js-apis-commonEventManager.md index bdcc1af2a479d300303a8d9f851f07c81c3e7d5a..8f150f4bbf02a8c11f81beddecd2e7edf89ab431 100644 --- a/en/application-dev/reference/apis/js-apis-commonEventManager.md +++ b/en/application-dev/reference/apis/js-apis-commonEventManager.md @@ -74,7 +74,7 @@ Publishes a common event with given attributes. This API uses an asynchronous ca | Name | Type | Mandatory| Description | | -------- | ---------------------- | ---- | ---------------------- | | event | string | Yes | Name of the common event to publish. | -| options | [CommonEventPublishData](#commoneventpublishdata) | Yes | Attributes of the common event to publish.| +| options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | Yes | Attributes of the common event to publish.| | callback | syncCallback\ | Yes | Callback used to return the result. | **Error codes** @@ -87,7 +87,7 @@ For details about the error codes, see [Event Error Codes](../errorcodes/errorco // Attributes of a common event. let options = { code: 0, // Initial code of the common event. - data: "initial data";// Initial data of the common event. + data: "initial data",// Initial data of the common event. isOrdered: true // The common event is an ordered one. } @@ -173,7 +173,7 @@ Publishes a common event with given attributes to a specific user. This API uses | -------- | ---------------------- | ---- | ---------------------- | | event | string | Yes | Name of the common event to publish. | | userId | number | Yes| User ID.| -| options | [CommonEventPublishData](#commoneventpublishdata) | Yes | Attributes of the common event to publish.| +| options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | Yes | Attributes of the common event to publish.| | callback | AsyncCallback\ | Yes | Callback used to return the result. | **Error codes** @@ -187,7 +187,7 @@ For details about the error codes, see [Event Error Codes](../errorcodes/errorco // Attributes of a common event. let options = { code: 0, // Initial code of the common event. - data: "initial data";// Initial data of the common event. + data: "initial data",// Initial data of the common event. } // Callback for common event publication. @@ -224,8 +224,8 @@ Creates a subscriber. This API uses an asynchronous callback to return the resul | Name | Type | Mandatory| Description | | ------------- | ------------------------------------------------------------ | ---- | -------------------------- | -| subscribeInfo | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | Yes | Subscriber information. | -| callback | AsyncCallback\<[CommonEventSubscriber](#commoneventsubscriber)> | Yes | Callback used to return the result.| +| subscribeInfo | [CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md) | Yes | Subscriber information. | +| callback | AsyncCallback\<[CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md)> | Yes | Callback used to return the result.| **Example** @@ -270,12 +270,12 @@ Creates a subscriber. This API uses a promise to return the result. | Name | Type | Mandatory| Description | | ------------- | ----------------------------------------------------- | ---- | -------------- | -| subscribeInfo | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | Yes | Subscriber information.| +| subscribeInfo | [CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md) | Yes | Subscriber information.| **Return value** | Type | Description | | --------------------------------------------------------- | ---------------- | -| Promise\<[CommonEventSubscriber](#commoneventsubscriber)> | Promise used to return the subscriber object.| +| Promise\<[CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md)> | Promise used to return the subscriber object.| **Example** @@ -311,8 +311,8 @@ Subscribes to common events. This API uses an asynchronous callback to return th | Name | Type | Mandatory| Description | | ---------- | ---------------------------------------------------- | ---- | -------------------------------- | -| subscriber | [CommonEventSubscriber](#commoneventsubscriber) | Yes | Subscriber object. | -| callback | AsyncCallback\<[CommonEventData](#commoneventdata)> | Yes | Callback used to return the result.| +| subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md) | Yes | Subscriber object. | +| callback | AsyncCallback\<[CommonEventData](./js-apis-inner-commonEvent-commonEventData.md)> | Yes | Callback used to return the result.| **Example** @@ -335,9 +335,10 @@ function SubscribeCB(err, data) { } // Callback for subscriber creation. -function createCB(err, subscriber) { +function createCB(err, commonEventSubscriber) { if(!err) { console.info("createSubscriber"); + subscriber = commonEventSubscriber; // Subscribe to a common event. try { CommonEventManager.subscribe(subscriber, SubscribeCB); @@ -371,7 +372,7 @@ Unsubscribes from common events. This API uses an asynchronous callback to retur | Name | Type | Mandatory| Description | | ---------- | ----------------------------------------------- | ---- | ------------------------ | -| subscriber | [CommonEventSubscriber](#commoneventsubscriber) | Yes | Subscriber object. | +| subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md) | Yes | Subscriber object. | | callback | AsyncCallback\ | No | Callback used to return the result.| **Example** @@ -391,11 +392,12 @@ function subscribeCB(err, data) { } } // Callback for subscriber creation. -function createCB(err, subscriber) { +function createCB(err, commonEventSubscriber) { if (err) { console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`); } else { console.info("createSubscriber"); + subscriber = commonEventSubscriber; // Subscribe to a common event. try { CommonEventManager.subscribe(subscriber, subscribeCB); @@ -426,785 +428,3 @@ try { console.error(`unsubscribe failed, code is ${err.code}, message is ${err.message}`); } ``` - -## CommonEventSubscriber - -### getCode - -```ts -getCode(callback: AsyncCallback): void -``` - -Obtains the code of this common event. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ---------------------- | ---- | ------------------ | -| callback | AsyncCallback\ | Yes | Common event code.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for code obtaining of an ordered common event. -function getCodeCB(err, code) { - if (err.code) { - console.error(`getCode failed, code is ${err.code}, message is ${err.message}`); - } else { - console.info("getCode " + JSON.stringify(code)); - } -} -subscriber.getCode(getCodeCB); -``` - -### getCode - -```ts -getCode(): Promise -``` - -Obtains the code of this common event. This API uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ---------------- | -------------------- | -| Promise\ | Common event code.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.getCode().then((code) => { - console.info("getCode " + JSON.stringify(code)); -}).catch((err) => { - console.error(`getCode failed, code is ${err.code}, message is ${err.message}`); -}); -``` - -### setCode - -```ts -setCode(code: number, callback: AsyncCallback): void -``` - -Sets the code for this common event. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ---------------------- | -| code | number | Yes | Common event code. | -| callback | AsyncCallback\ | Yes | Callback used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for code setting of an ordered common event. -function setCodeCB(err) { - if (err.code) { - console.error(`setCode failed, code is ${err.code}, message is ${err.message}`); - } else { - console.info("setCode"); - } -} -subscriber.setCode(1, setCodeCB); -``` - -### setCode - -```ts -setCode(code: number): Promise -``` - -Sets the code for this common event. This API uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name| Type | Mandatory| Description | -| ------ | ------ | ---- | ------------------ | -| code | number | Yes | Common event code.| - -**Return value** - -| Type | Description | -| ---------------- | -------------------- | -| Promise\ | Promise used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.setCode(1).then(() => { - console.info("setCode"); -}).catch((err) => { - console.error(`setCode failed, code is ${err.code}, message is ${err.message}`); -}); -``` - -### getData - -```ts -getData(callback: AsyncCallback): void -``` - -Obtains the data of this common event. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ---------------------- | ---- | -------------------- | -| callback | AsyncCallback\ | Yes | Common event data.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for data obtaining of an ordered common event. -function getDataCB(err, data) { - if (err.code) { - console.error(`getData failed, code is ${err.code}, message is ${err.message}`); - } else { - console.info("getData " + JSON.stringify(data)); - } -} -subscriber.getData(getDataCB); -``` - -### getData - -```ts -getData(): Promise -``` - -Obtains the data of this common event. This API uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ---------------- | ------------------ | -| Promise\ | Common event data.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.getData().then((data) => { - console.info("getData " + JSON.stringify(data)); -}).catch((err) => { - console.error(`getData failed, code is ${err.code}, message is ${err.message}`); -}); -``` - -### setData - -setData(data: string, callback: AsyncCallback\): void - -Sets the data for this common event. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------- | -| data | string | Yes | Common event data. | -| callback | AsyncCallback\ | Yes | Callback used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for result data setting of an ordered common event -function setDataCB(err) { - if (err.code) { - console.error(`setCode failed, code is ${err.code}, message is ${err.message}`); - } else { - console.info("setData"); - } -} -subscriber.setData("publish_data_changed", setDataCB); -``` - -### setData - -```ts -setData(data: string): Promise -``` - -Sets the data for this common event. This API uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name| Type | Mandatory| Description | -| ------ | ------ | ---- | -------------------- | -| data | string | Yes | Common event data.| - -**Return value** - -| Type | Description | -| ---------------- | -------------------- | -| Promise\ | Promise used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.setData("publish_data_changed").then(() => { - console.info("setData"); -}).catch((err) => { - console.error(`setCode failed, code is ${err.code}, message is ${err.message}`); -}); -``` - -### setCodeAndData - -```ts -setCodeAndData(code: number, data: string, callback:AsyncCallback): void -``` - -Sets the code and data for this common event. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ---------------------- | -| code | number | Yes | Common event code. | -| data | string | Yes | Common event data. | -| callback | AsyncCallback\ | Yes | Callback used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for code and data setting of an ordered common event. -function setCodeDataCB(err) { - if (err.code) { - console.error(`setCodeAndData failed, code is ${err.code}, message is ${err.message}`); - } else { - console.info("setCodeDataCallback"); - } -} -subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCB); -``` - -### setCodeAndData - -```ts -setCodeAndData(code: number, data: string): Promise -``` - -Sets the code and data for this common event. This API uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name| Type | Mandatory| Description | -| ------ | ------ | ---- | -------------------- | -| code | number | Yes | Common event code.| -| data | string | Yes | Common event data.| - -**Return value** - -| Type | Description | -| ---------------- | -------------------- | -| Promise\ | Promise used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.setCodeAndData(1, "publish_data_changed").then(() => { - console.info("setCodeAndData"); -}).catch((err) => { - console.error(`setCodeAndData failed, code is ${err.code}, message is ${err.message}`); -}); -``` - -### isOrderedCommonEvent - -```ts -isOrderedCommonEvent(callback: AsyncCallback): void -``` - -Checks whether this common event is an ordered one. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | ---------------------------------- | -| callback | AsyncCallback\ | Yes | Callback used to return the result. The value **true** means that the common event is an ordered one; and **false** means the opposite.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for checking whether the current common event is an ordered one. -function isOrderedCB(err, isOrdered) { - if (err.code) { - console.error(`isOrderedCommonEvent failed, code is ${err.code}, message is ${err.message}`); - } else { - console.info("isOrdered " + JSON.stringify(isOrdered)); - } -} -subscriber.isOrderedCommonEvent(isOrderedCB); -``` - -### isOrderedCommonEvent - -```ts -isOrderedCommonEvent(): Promise -``` - -Checks whether this common event is an ordered one. This API uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ----------------- | -------------------------------- | -| Promise\ | Promise used to return the result. The value **true** means that the common event is an ordered one; and **false** means the opposite.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.isOrderedCommonEvent().then((isOrdered) => { - console.info("isOrdered " + JSON.stringify(isOrdered)); -}).catch((err) => { - console.error(`isOrdered failed, code is ${err.code}, message is ${err.message}`); -}); -``` - -### isStickyCommonEvent - -```ts -isStickyCommonEvent(callback: AsyncCallback): void -``` - -Checks whether this common event is a sticky one. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | ---------------------------------- | -| callback | AsyncCallback\ | Yes | Callback used to return the result. The value **true** means that the common event is a sticky one; and **false** means the opposite.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for checking whether the current common event is a sticky one. -function isStickyCB(err, isSticky) { - if (err.code) { - console.error(`isStickyCommonEvent failed, code is ${err.code}, message is ${err.message}`); - } else { - console.info("isSticky " + JSON.stringify(isSticky)); - } -} -subscriber.isStickyCommonEvent(isStickyCB); -``` - -### isStickyCommonEvent - -```ts -isStickyCommonEvent(): Promise -``` - -Checks whether this common event is a sticky one. This API uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ----------------- | -------------------------------- | -| Promise\ | Promise used to return the result. The value **true** means that the common event is a sticky one; and **false** means the opposite.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.isStickyCommonEvent().then((isSticky) => { - console.info("isSticky " + JSON.stringify(isSticky)); -}).catch((err) => { - console.error(`isSticky failed, code is ${err.code}, message is ${err.message}`); -}); -``` - -### abortCommonEvent - -```ts -abortCommonEvent(callback: AsyncCallback): void -``` - -Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------- | -| callback | AsyncCallback\ | Yes | Callback used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for common event aborting. -function abortCB(err) { - if (err.code) { - console.error(`abortCommonEvent failed, code is ${err.code}, message is ${err.message}`); - } else { - console.info("abortCommonEvent"); - } -} -subscriber.abortCommonEvent(abortCB); -``` - -### abortCommonEvent - -```ts -abortCommonEvent(): Promise -``` - -Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API takes effect only for ordered common events. It uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ---------------- | -------------------- | -| Promise\ | Promise used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.abortCommonEvent().then(() => { - console.info("abortCommonEvent"); -}).catch((err) => { - console.error(`abortCommonEvent failed, code is ${err.code}, message is ${err.message}`); -}); -``` - -### clearAbortCommonEvent - -```ts -clearAbortCommonEvent(callback: AsyncCallback): void -``` - -Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------- | -| callback | AsyncCallback\ | Yes | Callback used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for clearing the aborted state of the current common event. -function clearAbortCB(err) { - if (err.code) { - console.error(`clearAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`); - } else { - console.info("clearAbortCommonEvent"); - } -} -subscriber.clearAbortCommonEvent(clearAbortCB); -``` - -### clearAbortCommonEvent - -```ts -clearAbortCommonEvent(): Promise -``` - -Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ---------------- | -------------------- | -| Promise\ | Promise used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.clearAbortCommonEvent().then(() => { - console.info("clearAbortCommonEvent"); -}).catch((err) => { - console.error(`clearAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`); -}); -``` - -### getAbortCommonEvent - -```ts -getAbortCommonEvent(callback: AsyncCallback): void -``` - -Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | ---------------------------------- | -| callback | AsyncCallback\ | Yes | Callback used to return the result. The value **true** means that the ordered common event is in the aborted state; and **false** means the opposite.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for checking whether the current common event is in the aborted state. -function getAbortCB(err, abortEvent) { - if (err.code) { - console.error(`getAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`); - } else { - console.info("abortCommonEvent " + abortEvent) - } -} -subscriber.getAbortCommonEvent(getAbortCB); -``` - -### getAbortCommonEvent - -```ts -getAbortCommonEvent(): Promise -``` - -Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ----------------- | ---------------------------------- | -| Promise\ | Promise used to return the result. The value **true** means that the ordered common event is in the aborted state; and **false** means the opposite.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.getAbortCommonEvent().then((abortEvent) => { - console.info("abortCommonEvent " + JSON.stringify(abortEvent)); -}).catch((err) => { - console.error(`getAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`); -}); -``` - -### getSubscribeInfo - -```ts -getSubscribeInfo(callback: AsyncCallback): void -``` - -Obtains the subscriber information. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ---------------------- | -| callback | AsyncCallback\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Yes | Callback used to return the subscriber information.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for subscriber information obtaining. -function getCB(err, subscribeInfo) { - if (err.code) { - console.error(`getSubscribeInfo failed, code is ${err.code}, message is ${err.message}`); - } else { - console.info("subscribeInfo " + JSON.stringify(subscribeInfo)); - } -} -subscriber.getSubscribeInfo(getCB); -``` - -### getSubscribeInfo - -```ts -getSubscribeInfo(): Promise -``` - -Obtains the subscriber information. This API uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ------------------------------------------------------------ | ---------------------- | -| Promise\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Promise used to return the subscriber information.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.getSubscribeInfo().then((subscribeInfo) => { - console.info("subscribeInfo " + JSON.stringify(subscribeInfo)); -}).catch((err) => { - console.error(`getSubscribeInfo failed, code is ${err.code}, message is ${err.message}`); -}); -``` - -### finishCommonEvent9+ - -```ts -finishCommonEvent(callback: AsyncCallback): void -``` - -Finishes this common event. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | -------------------------------- | -| callback | AsyncCallback\ | Yes | Callback returned after the ordered common event is finished.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -// Callback for ordered common event finishing. -function finishCB(err) { - if (err.code) { - console.error(`finishCommonEvent failed, code is ${err.code}, message is ${err.message}`); -} else { - console.info("FinishCommonEvent"); -} - -subscriber.finishCommonEvent(finishCB); -``` - -### finishCommonEvent9+ - -```ts -finishCommonEvent(): Promise -``` - -Finishes this common event. This API takes effect only for ordered common events. It uses a promise to return the result. - -**System capability**: SystemCapability.Notification.CommonEvent - -**Return value** - -| Type | Description | -| ---------------- | -------------------- | -| Promise\ | Promise used to return the result.| - -**Example** - -```ts -let subscriber; // Subscriber object successfully created. - -subscriber.finishCommonEvent().then(() => { - console.info("FinishCommonEvent"); -}).catch((err) => { - console.error(`finishCommonEvent failed, code is ${err.code}, message is ${err.message}`); -}); -``` - -## CommonEventData - -**System capability**: SystemCapability.Notification.CommonEvent - -| Name | Type | Readable| Writable| Description | -| ---------- |-------------------- | ---- | ---- | ------------------------------------------------------- | -| event | string | Yes | No | Name of the common event that is being received. | -| bundleName | string | Yes | No | Bundle name. | -| code | number | Yes | No | Code of the common event, which is used to transfer data of the int type. | -| data | string | Yes | No | Custom data of the common event, which is used to transfer data of the string type.| -| parameters | {[key: string]: any} | Yes | No | Additional information about the common event. | - - -## CommonEventPublishData - -**System capability**: SystemCapability.Notification.CommonEvent - -| Name | Type | Readable| Writable| Description | -| --------------------- | -------------------- | ---- | ---- | ---------------------------- | -| bundleName | string | Yes | No | Bundle name. | -| code | number | Yes | No | Code of the common event. | -| data | string | Yes | No | Custom data of the common event.| -| subscriberPermissions | Array\ | Yes | No | Permissions required for subscribers to receive the common event. | -| isOrdered | boolean | Yes | No | Whether the common event is an ordered one. | -| isSticky | boolean | Yes | No | Whether the common event is a sticky one. Only system applications and system services are allowed to send sticky events.| -| parameters | {[key: string]: any} | Yes | No | Additional information about the common event. | - -## CommonEventSubscribeInfo - -**System capability**: SystemCapability.Notification.CommonEvent - -| Name | Type | Readable| Writable| Description | -| ------------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | -| events | Array\ | Yes | No | Name of the common event to publish. | -| publisherPermission | string | Yes | No | Permissions required for publishers to publish the common event. | -| publisherDeviceId | string | Yes | No | Device ID. The value must be the ID of an existing device on the same network. | -| userId | number | Yes | 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 | number | Yes | No | Subscriber priority. The value ranges from -100 to +1000. | diff --git a/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventData.md b/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventData.md new file mode 100644 index 0000000000000000000000000000000000000000..a73c80d7c5fa09e19f901b3c947f445eb61989e1 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventData.md @@ -0,0 +1,11 @@ +# CommonEventData + +**System capability**: SystemCapability.Notification.CommonEvent + +| Name | Type | Readable| Writable| Description | +| ---------- |-------------------- | ---- | ---- | ------------------------------------------------------- | +| event | string | Yes | No | Name of the common event that is being received. | +| bundleName | string | Yes | No | Bundle name. | +| code | number | Yes | No | Result code of the common event, which is used to transfer data of the int type. | +| data | string | Yes | No | Custom result data of the common event, which is used to transfer data of the string type.| +| parameters | {[key: string]: any} | Yes | No | Additional information about the common event. | diff --git a/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventPublishData.md b/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventPublishData.md new file mode 100644 index 0000000000000000000000000000000000000000..94963860fe1b57a6abfd6fff6fdba38816a63294 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventPublishData.md @@ -0,0 +1,13 @@ +# CommonEventPublishData + +**System capability**: SystemCapability.Notification.CommonEvent + +| Name | Type | Readable| Writable| Description | +| --------------------- | -------------------- | ---- | ---- | ---------------------------- | +| bundleName | string | Yes | No | Bundle name. | +| code | number | Yes | No | Result code of the common event. | +| data | string | Yes | No | Custom result data of the common event.| +| subscriberPermissions | Array\ | Yes | No | Permissions required for subscribers to receive the common event. | +| isOrdered | boolean | Yes | No | Whether the common event is an ordered one. | +| isSticky | boolean | Yes | No | Whether the common event is a sticky one. Only system applications and system services are allowed to send sticky events.| +| parameters | {[key: string]: any} | Yes | No | Additional information about the common event. | diff --git a/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscribeInfo.md b/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscribeInfo.md new file mode 100644 index 0000000000000000000000000000000000000000..2b9db9ec46f479d5d0607c33f07601b1ef721446 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscribeInfo.md @@ -0,0 +1,11 @@ +# CommonEventSubscribeInfo + +**System capability**: SystemCapability.Notification.CommonEvent + +| Name | Type | Readable| Writable| Description | +| ------------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | +| events | Array\ | Yes | No | Name of the common event to publish. | +| publisherPermission | string | Yes | No | Permissions required for publishers to publish the common event. | +| publisherDeviceId | string | Yes | No | Device ID. The value must be the ID of a device on the same network. | +| userId | number | Yes | No | User ID. The value must be an existing user ID in the system. If this parameter is not specified, the default value, which is the ID of the current user, will be used. | +| priority | number | Yes | No | Subscriber priority. The value ranges from –100 to +1000. | diff --git a/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscriber.md b/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscriber.md new file mode 100644 index 0000000000000000000000000000000000000000..18eeac506b75dc96b27b56b9369070215ff8892a --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscriber.md @@ -0,0 +1,742 @@ +# CommonEventSubscriber + +## getCode + +```ts +getCode(callback: AsyncCallback): void +``` + +Obtains the code of this common event. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ------------------ | +| callback | AsyncCallback\ | Yes | Common event code.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +// Callback for result code obtaining of an ordered common event. +function getCodeCB(err, code) { + if (err.code) { + console.error(`getCode failed, code is ${err.code}, message is ${err.message}`); + } else { + console.info("getCode " + JSON.stringify(code)); + } +} +subscriber.getCode(getCodeCB); +``` + +## getCode + +```ts +getCode(): Promise +``` + +Obtains the code of this common event. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Return value** + +| Type | Description | +| ---------------- | -------------------- | +| Promise\ | Common event code.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +subscriber.getCode().then((code) => { + console.info("getCode " + JSON.stringify(code)); +}).catch((err) => { + console.error(`getCode failed, code is ${err.code}, message is ${err.message}`); +}); +``` + +## setCode + +```ts +setCode(code: number, callback: AsyncCallback): void +``` + +Sets the code for this common event. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------------------- | +| code | number | Yes | Common event code. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +// Callback for result code setting of an ordered common event. +function setCodeCB(err) { + if (err.code) { + console.error(`setCode failed, code is ${err.code}, message is ${err.message}`); + } else { + console.info("setCode"); + } +} +subscriber.setCode(1, setCodeCB); +``` + +## setCode + +```ts +setCode(code: number): Promise +``` + +Sets the code for this common event. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------ | +| code | number | Yes | Common event code.| + +**Return value** + +| Type | Description | +| ---------------- | -------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +subscriber.setCode(1).then(() => { + console.info("setCode"); +}).catch((err) => { + console.error(`setCode failed, code is ${err.code}, message is ${err.message}`); +}); +``` + +## getData + +```ts +getData(callback: AsyncCallback): void +``` + +Obtains the data of this common event. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes | Common event data.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +// Callback for result data obtaining of an ordered common event. +function getDataCB(err, data) { + if (err.code) { + console.error(`getData failed, code is ${err.code}, message is ${err.message}`); + } else { + console.info("getData " + JSON.stringify(data)); + } +} +subscriber.getData(getDataCB); +``` + +## getData + +```ts +getData(): Promise +``` + +Obtains the data of this common event. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Return value** + +| Type | Description | +| ---------------- | ------------------ | +| Promise\ | Common event data.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +subscriber.getData().then((data) => { + console.info("getData " + JSON.stringify(data)); +}).catch((err) => { + console.error(`getData failed, code is ${err.code}, message is ${err.message}`); +}); +``` + +## setData + +setData(data: string, callback: AsyncCallback\): void + +Sets the data for this common event. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | -------------------- | +| data | string | Yes | Common event data. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +// Callback for result data setting of an ordered common event +function setDataCB(err) { + if (err.code) { + console.error(`setCode failed, code is ${err.code}, message is ${err.message}`); + } else { + console.info("setData"); + } +} +subscriber.setData("publish_data_changed", setDataCB); +``` + +## setData + +```ts +setData(data: string): Promise +``` + +Sets the data for this common event. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------- | +| data | string | Yes | Common event data.| + +**Return value** + +| Type | Description | +| ---------------- | -------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +subscriber.setData("publish_data_changed").then(() => { + console.info("setData"); +}).catch((err) => { + console.error(`setCode failed, code is ${err.code}, message is ${err.message}`); +}); +``` + +## setCodeAndData + +```ts +setCodeAndData(code: number, data: string, callback:AsyncCallback): void +``` + +Sets the code and data for this common event. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------------------- | +| code | number | Yes | Common event code. | +| data | string | Yes | Common event data. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +// Callback for code and data setting of an ordered common event. +function setCodeDataCB(err) { + if (err.code) { + console.error(`setCodeAndData failed, code is ${err.code}, message is ${err.message}`); + } else { + console.info("setCodeDataCallback"); + } +} +subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCB); +``` + +## setCodeAndData + +```ts +setCodeAndData(code: number, data: string): Promise +``` + +Sets the code and data for this common event. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------- | +| code | number | Yes | Common event code.| +| data | string | Yes | Common event data.| + +**Return value** + +| Type | Description | +| ---------------- | -------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +subscriber.setCodeAndData(1, "publish_data_changed").then(() => { + console.info("setCodeAndData"); +}).catch((err) => { + console.error(`setCodeAndData failed, code is ${err.code}, message is ${err.message}`); +}); +``` + +## isOrderedCommonEvent + +```ts +isOrderedCommonEvent(callback: AsyncCallback): void +``` + +Checks whether this common event is an ordered one. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | ---------------------------------- | +| callback | AsyncCallback\ | Yes | Returns **true** if the common event is an ordered one; returns **false** otherwise.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +// Callback for checking whether the current common event is an ordered one. +function isOrderedCB(err, isOrdered) { + if (err.code) { + console.error(`isOrderedCommonEvent failed, code is ${err.code}, message is ${err.message}`); + } else { + console.info("isOrdered " + JSON.stringify(isOrdered)); + } +} +subscriber.isOrderedCommonEvent(isOrderedCB); +``` + +## isOrderedCommonEvent + +```ts +isOrderedCommonEvent(): Promise +``` + +Checks whether this common event is an ordered one. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Return value** + +| Type | Description | +| ----------------- | -------------------------------- | +| Promise\ | Returns **true** if the common event is an ordered one; returns **false** otherwise.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +subscriber.isOrderedCommonEvent().then((isOrdered) => { + console.info("isOrdered " + JSON.stringify(isOrdered)); +}).catch((err) => { + console.error(`isOrdered failed, code is ${err.code}, message is ${err.message}`); +}); +``` + +## isStickyCommonEvent + +```ts +isStickyCommonEvent(callback: AsyncCallback): void +``` + +Checks whether this common event is a sticky one. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | ---------------------------------- | +| callback | AsyncCallback\ | Yes | Returns **true** if the common event is a sticky one; returns **false** otherwise.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +// Callback for checking whether the current common event is a sticky one. +function isStickyCB(err, isSticky) { + if (err.code) { + console.error(`isStickyCommonEvent failed, code is ${err.code}, message is ${err.message}`); + } else { + console.info("isSticky " + JSON.stringify(isSticky)); + } +} +subscriber.isStickyCommonEvent(isStickyCB); +``` + +## isStickyCommonEvent + +```ts +isStickyCommonEvent(): Promise +``` + +Checks whether this common event is a sticky one. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Return value** + +| Type | Description | +| ----------------- | -------------------------------- | +| Promise\ | Returns **true** if the common event is a sticky one; returns **false** otherwise.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +subscriber.isStickyCommonEvent().then((isSticky) => { + console.info("isSticky " + JSON.stringify(isSticky)); +}).catch((err) => { + console.error(`isSticky failed, code is ${err.code}, message is ${err.message}`); +}); +``` + +## abortCommonEvent + +```ts +abortCommonEvent(callback: AsyncCallback): void +``` + +Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +// Callback for common event aborting. +function abortCB(err) { + if (err.code) { + console.error(`abortCommonEvent failed, code is ${err.code}, message is ${err.message}`); + } else { + console.info("abortCommonEvent"); + } +} +subscriber.abortCommonEvent(abortCB); +``` + +## abortCommonEvent + +```ts +abortCommonEvent(): Promise +``` + +Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API takes effect only for ordered common events. It uses a promise to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Return value** + +| Type | Description | +| ---------------- | -------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +subscriber.abortCommonEvent().then(() => { + console.info("abortCommonEvent"); +}).catch((err) => { + console.error(`abortCommonEvent failed, code is ${err.code}, message is ${err.message}`); +}); +``` + +## clearAbortCommonEvent + +```ts +clearAbortCommonEvent(callback: AsyncCallback): void +``` + +Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +// Callback for clearing the aborted state of the current common event. +function clearAbortCB(err) { + if (err.code) { + console.error(`clearAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`); + } else { + console.info("clearAbortCommonEvent"); + } +} +subscriber.clearAbortCommonEvent(clearAbortCB); +``` + +## clearAbortCommonEvent + +```ts +clearAbortCommonEvent(): Promise +``` + +Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses a promise to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Return value** + +| Type | Description | +| ---------------- | -------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +subscriber.clearAbortCommonEvent().then(() => { + console.info("clearAbortCommonEvent"); +}).catch((err) => { + console.error(`clearAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`); +}); +``` + +## getAbortCommonEvent + +```ts +getAbortCommonEvent(callback: AsyncCallback): void +``` + +Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | ---------------------------------- | +| callback | AsyncCallback\ | Yes | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +// Callback for checking whether the current common event is in the aborted state. +function getAbortCB(err, abortEvent) { + if (err.code) { + console.error(`getAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`); + } else { + console.info("abortCommonEvent " + abortEvent) + } +} +subscriber.getAbortCommonEvent(getAbortCB); +``` + +## getAbortCommonEvent + +```ts +getAbortCommonEvent(): Promise +``` + +Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses a promise to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Return value** + +| Type | Description | +| ----------------- | ---------------------------------- | +| Promise\ | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +subscriber.getAbortCommonEvent().then((abortEvent) => { + console.info("abortCommonEvent " + JSON.stringify(abortEvent)); +}).catch((err) => { + console.error(`getAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`); +}); +``` + +## getSubscribeInfo + +```ts +getSubscribeInfo(callback: AsyncCallback): void +``` + +Obtains the subscriber information. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ---------------------- | +| callback | AsyncCallback\<[CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md)> | Yes | Callback used to return the subscriber information.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +// Callback for subscriber information obtaining. +function getCB(err, subscribeInfo) { + if (err.code) { + console.error(`getSubscribeInfo failed, code is ${err.code}, message is ${err.message}`); + } else { + console.info("subscribeInfo " + JSON.stringify(subscribeInfo)); + } +} +subscriber.getSubscribeInfo(getCB); +``` + +## getSubscribeInfo + +```ts +getSubscribeInfo(): Promise +``` + +Obtains the subscriber information. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Return value** + +| Type | Description | +| ------------------------------------------------------------ | ---------------------- | +| Promise\<[CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md)> | Promise used to return the subscriber information.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +subscriber.getSubscribeInfo().then((subscribeInfo) => { + console.info("subscribeInfo " + JSON.stringify(subscribeInfo)); +}).catch((err) => { + console.error(`getSubscribeInfo failed, code is ${err.code}, message is ${err.message}`); +}); +``` + +## finishCommonEvent9+ + +```ts +finishCommonEvent(callback: AsyncCallback): void +``` + +Finishes this common event. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | -------------------------------- | +| callback | AsyncCallback\ | Yes | Callback returned after the ordered common event is finished.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +// Callback for ordered common event finishing. +function finishCB(err) { + if (err.code) { + console.error(`finishCommonEvent failed, code is ${err.code}, message is ${err.message}`); +} else { + console.info("FinishCommonEvent"); +} + +subscriber.finishCommonEvent(finishCB); +``` + +## finishCommonEvent9+ + +```ts +finishCommonEvent(): Promise +``` + +Finishes this common event. This API takes effect only for ordered common events. It uses a promise to return the result. + +**System capability**: SystemCapability.Notification.CommonEvent + +**Return value** + +| Type | Description | +| ---------------- | -------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```ts +let subscriber; // Subscriber object successfully created. + +subscriber.finishCommonEvent().then(() => { + console.info("FinishCommonEvent"); +}).catch((err) => { + console.error(`finishCommonEvent failed, code is ${err.code}, message is ${err.message}`); +}); +```