The **CommonEvent** module provides common event capabilities, including the capabilities to publish, subscribe to, and unsubscribe from common events, as well obtaining and setting the common event result code and result data.
The **CommonEvent** module provides common event capabilities, including the capabilities to publish, subscribe to, and unsubscribe from common events, as well obtaining and setting the common event result code and result data.
> **NOTE**
> **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.
> - The APIs provided by this module are no longer maintained since API version 9. You are advised to use [@ohos.commonEventManager](js-apis-commonEventManager.md).
> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
## Modules to Import
...
@@ -14,7 +15,7 @@ import CommonEvent from '@ohos.commonEvent';
...
@@ -14,7 +15,7 @@ import CommonEvent from '@ohos.commonEvent';
## Support
## Support
Provides the event types supported by the **CommonEvent** module. The name and value indicate the macro and name of a common event, respectively.
The table below lists the event types supported by the **CommonEvent** module. The name and value indicate the macro and name of a common event, respectively.
@@ -167,8 +168,8 @@ Provides the event types supported by the **CommonEvent** module. The name and v
...
@@ -167,8 +168,8 @@ Provides the event types supported by the **CommonEvent** module. The name and v
| COMMON_EVENT_ACCOUNT_DELETED | usual.event.data.ACCOUNT_DELETED | ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS | Indicates the common event that the account was deleted. |
| COMMON_EVENT_ACCOUNT_DELETED | usual.event.data.ACCOUNT_DELETED | ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS | Indicates the common event that the account was deleted. |
| COMMON_EVENT_FOUNDATION_READY | usual.event.data.FOUNDATION_READY | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the foundation is ready. |
| COMMON_EVENT_FOUNDATION_READY | usual.event.data.FOUNDATION_READY | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the foundation is ready. |
| COMMON_EVENT_AIRPLANE_MODE_CHANGED | usual.event.AIRPLANE_MODE | - | Indicates the common event that the airplane mode of the device has changed. |
| COMMON_EVENT_AIRPLANE_MODE_CHANGED | usual.event.AIRPLANE_MODE | - | Indicates the common event that the airplane mode of the device has changed. |
| COMMON_EVENT_SPLIT_SCREEN<sup>8+<sup> | usual.event.SPLIT_SCREEN | - | Indicates the common event of screen splitting. |
| COMMON_EVENT_SPLIT_SCREEN<sup>8+<sup> | usual.event.SPLIT_SCREEN | - | Indicates the common event of screen splitting. |
| COMMON_EVENT_SLOT_CHANGE<sup>9+<sup> | usual.event.SLOT_CHANGE | ohos.permission.NOTIFICATION_CONTROLLER | Indicates the common event that the notification slot has changed. |
| COMMON_EVENT_SLOT_CHANGE<sup>9+<sup> | usual.event.SLOT_CHANGE | ohos.permission.NOTIFICATION_CONTROLLER | Indicates the common event that the notification slot has been updated. |
| COMMON_EVENT_SPN_INFO_CHANGED <sup>9+<sup> | usual.event.SPN_INFO_CHANGED | - | Indicates the common event that the SPN displayed has been updated. |
| COMMON_EVENT_SPN_INFO_CHANGED <sup>9+<sup> | usual.event.SPN_INFO_CHANGED | - | Indicates the common event that the SPN displayed has been updated. |
| COMMON_EVENT_QUICK_FIX_APPLY_RESULT <sup>9+<sup> | usual.event.QUICK_FIX_APPLY_RESULT | - | Indicates the common event that a quick fix is applied to the application. |
| COMMON_EVENT_QUICK_FIX_APPLY_RESULT <sup>9+<sup> | usual.event.QUICK_FIX_APPLY_RESULT | - | Indicates the common event that a quick fix is applied to the application. |
...
@@ -192,7 +193,7 @@ Publishes a common event. This API uses an asynchronous callback to return the r
...
@@ -192,7 +193,7 @@ Publishes a common event. This API uses an asynchronous callback to return the r
| code | Yes | No | number | Result code of the common event. |
| code | number | Yes | No | Result code of the common event. |
| data | Yes | No | string | Custom result data of the common event.|
| data | string | Yes | No | Custom result data of the common event.|
| subscriberPermissions | Yes | No | Array\<string> | Permissions required for subscribers to receive the common event. |
| subscriberPermissions | Array\<string> | Yes | No | Permissions required for subscribers to receive the common event. |
| isOrdered | Yes | No | boolean | Whether the common event is an ordered one. |
| isOrdered | boolean | Yes | No | Whether the common event is an ordered one. |
| isSticky | Yes | No | boolean | Whether the common event is a sticky 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 | Yes | No | {[key: string]: any} | Additional information about the common event. |
| parameters | {[key: string]: any} | Yes | No | Additional information about the common event. |
| events | Yes | No | Array\<string> | Name of the common event to publish. |
| events | Array\<string> | Yes | No | Name of the common event to publish. |
| publisherPermission | Yes | No | string | Permissions required for publishers to publish the common event. |
| publisherPermission | string | Yes | No | Permissions required for publishers to publish the common event. |
| publisherDeviceId | Yes | No | string | Device ID. The value must be the ID of an existing device on the same network. |
| publisherDeviceId | string | Yes | No | Device ID. The value must be the ID of an existing device on the same network. |
| userId | Yes | No | number | 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.|
| 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 | Yes | No | number | Subscriber priority. The value ranges from -100 to 1000. |
| priority | number | Yes | No | Subscriber priority. The value ranges from -100 to +1000. |