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**<br>
> **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.
...
...
@@ -18,7 +18,7 @@ Provides the event types supported by the **CommonEvent** module. The name and v
| COMMON_EVENT_BOOT_COMPLETED | usual.event.BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the user has finished booting and the system has been loaded. |
| COMMON_EVENT_LOCKED_BOOT_COMPLETED | usual.event.LOCKED_BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the user has finished booting and the system has been loaded but the screen is still locked. |
...
...
@@ -39,7 +39,7 @@ Provides the event types supported by the **CommonEvent** module. The name and v
| COMMON_EVENT_CLOSE_SYSTEM_DIALOGS | usual.event.CLOSE_SYSTEM_DIALOGS | - | Indicates the common event that a user closes a temporary system dialog box. |
| COMMON_EVENT_PACKAGE_ADDED | usual.event.PACKAGE_ADDED | - | Indicates the common event that a new application package has been installed on the device. |
| COMMON_EVENT_PACKAGE_REPLACED | usual.event.PACKAGE_REPLACED | - | Indicates the common event that a later version of an installed application package has replaced the previous one on the device. |
| COMMON_EVENT_MY_PACKAGE_REPLACED | usual.event.MY_PACKAGE_REPLACED | - | Indicates the common event that a later version of your application package has replaced the previous one. |
| COMMON_EVENT_MY_PACKAGE_REPLACED | usual.event.MY_PACKAGE_REPLACED | - | Indicates the common event that a later version of your application package has replaced the previous one.
| COMMON_EVENT_PACKAGE_REMOVED | usual.event.PACKAGE_REMOVED | - | Indicates the common event that an installed application has been uninstalled from the device with the application data retained. |
| COMMON_EVENT_BUNDLE_REMOVED | usual.event.BUNDLE_REMOVED | - | Indicates the common event that an installed bundle has been uninstalled from the device with the application data retained. |
| COMMON_EVENT_PACKAGE_FULLY_REMOVED | usual.event.PACKAGE_FULLY_REMOVED | - | Indicates the common event that an installed application, including both the application data and code, has been completely uninstalled from the device. |
...
...
@@ -173,7 +173,7 @@ Provides the event types supported by the **CommonEvent** module. The name and v
| 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 | ohos.permission.RECEIVER_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_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. |
## CommonEvent.publish
...
...
@@ -186,10 +186,10 @@ Publishes a common event. This API uses a callback to return the result.
**Parameters**
| Name | Readable/Writable| Type | Mandatory| Description |
| events | Read only | Array\<string> | Yes | Name of the common event to publish. |
| publisherPermission | Read only | string | No | Permissions required for publishers to publish the common event. |
| publisherDeviceId | Read only | string | No | Device ID. The value must be the ID of an existing device on the same network. |
| userId | Read only | number | No | User ID. The default value is the ID of the current user. If this parameter is specified, the value must be an existing user ID in the system.|
| priority | Read only | number | No | Subscriber priority. The value ranges from -100 to 1000. |
| events | Yes | No | Array\<string> | Name of the common event to publish. |
| publisherPermission | Yes | No | string | 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. |
| 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.|
| priority | Yes | No | number | Subscriber priority. The value ranges from -100 to 1000. |
Generally, only system applications have the permission to subscribe to and unsubscribe from notifications.
> **NOTE**<br>
> **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.
...
...
@@ -24,10 +24,10 @@ Publishes a notification. This API uses an asynchronous callback to return the r
**Parameters**
| Name | Readable| Writable| Type | Mandatory| Description |
| slotType | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| callback | Yes | No | AsyncCallback\<[NotificationSlot](#notificationslot)\> | Yes | Callback used to return the result. |
| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| callback | AsyncCallback\<[NotificationSlot](#notificationslot)\> | Yes | Callback used to return the result. |
**Example**
...
...
@@ -523,9 +529,9 @@ Obtains a notification slot of the specified type. This API uses a promise to re
**Parameters**
| Name | Readable| Writable| Type | Mandatory| Description |
| slotType | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
**Return value**
...
...
@@ -554,9 +560,9 @@ Obtains all notification slots. This API uses an asynchronous callback to return
**Parameters**
| Name | Readable| Writable| Type | Mandatory| Description |
| slotType | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result. |
| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Example**
...
...
@@ -632,9 +638,9 @@ Removes a notification slot of the specified type. This API uses a promise to re
**Parameters**
| Name | Readable| Writable| Type | Mandatory| Description |
| slotType | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
**Example**
...
...
@@ -657,9 +663,9 @@ Removes all notification slots. This API uses an asynchronous callback to return
**Parameters**
| Name | Readable| Writable| Type | Mandatory| Description |
| enable | boolean | Yes | Whether to sync notifications to devices where the application is not installed. The value **true** means to sync notifications to devices where the application is not installed, and **false** means the opposite.|
| enable | boolean | Yes | Whether the feature is enabled.<br>**true**: enabled<br>**false**: disabled |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example**
...
...
@@ -3061,17 +3073,17 @@ Sets whether to sync notifications to devices where the application is not insta
| enable | boolean | Yes | Whether to sync notifications to devices where the application is not installed. The value **true** means to sync notifications to devices where the application is not installed, and **false** means the opposite.|
| enable | boolean | Yes | Whether the feature is enabled.<br>**true**: enabled<br>**false**: disabled |
Checks whether notifications are synced to devices where the application is not installed. This API uses an asynchronous callback to return the result.
Obtains whether notifications are synced to devices where the application is not installed. This API uses an asynchronous callback to return the result.
| callback | AsyncCallback\<boolean\>| Yes | Callback used to return the result. The value **true** means that notifications are synced to devices where the application is not installed, and **false** means the opposite.|
| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.<br>**true**: Notifications are synced to devices where the application is not installed.<br>**false**: Notifications are not synced to devices where the application is not installed.|
| Promise\<boolean\> | Promise used to return the result. The value **true** means that notifications are synced to devices where the application is not installed, and **false** means the opposite.|
| Promise\<boolean\> | Promise used to return the result.<br>**true**: Notifications are synced to devices where the application is not installed.<br>**false**: Notifications are not synced to devices where the application is not installed.|
| badgeIconStyle | Yes | Yes | number | No | Notification badge type. |
| showDeliveryTime | Yes | Yes | boolean | No | Whether to display the time when the notification is delivered. |
| actionButtons | Yes | Yes | Array\<[NotificationActionButton](#notificationactionbutton)\> | No | Buttons in the notification. Up to two buttons are allowed. |
| smallIcon | Yes | Yes | PixelMap | No | Small notification icon. |
| largeIcon | Yes | Yes | PixelMap | No | Large notification icon. |
| creatorBundleName | Yes | No | string | No | Name of the bundle that creates the notification. |
| creatorUid | Yes | No | number | No | UID used for creating the notification. |
| creatorPid | Yes | No | number | No | PID used for creating the notification. |
| creatorUserId<sup>8+</sup>| Yes | No | number | No | ID of the user who creates the notification. |
| hashCode | Yes | No | string | No | Unique ID of the notification. |
| classification | Yes | Yes | string | No | Notification category.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| groupName<sup>8+</sup>| Yes | Yes | string | No | Group notification name. |
| isRemoveAllowed<sup>8+</sup> | Yes | No | boolean | No | Whether the notification can be removed.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| source<sup>8+</sup> | Yes | No | number | No | Notification source.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| distributedOption<sup>8+</sup> | Yes | Yes | [DistributedOptions](#distributedoptions8) | No | Option of distributed notification. |
| deviceId<sup>8+</sup> | Yes | No | string | No | Device ID of the notification source.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| notificationFlags<sup>8+</sup> | Yes | No | [NotificationFlags](#notificationflags8) | No | Notification flags. |
| removalWantAgent<sup>9+</sup> | Yes | Yes | WantAgent | No | **WantAgent** instance to which the notification will be redirected when it is removed. |
| badgeNumber<sup>9+</sup> | Yes | Yes | number | No | Number of notifications displayed on the application icon. |
| showDeliveryTime | Yes | Yes | boolean | Whether to display the time when the notification is delivered. |
| actionButtons | Yes | Yes | Array\<[NotificationActionButton](#notificationactionbutton)\> | Buttons in the notification. Up to two buttons are allowed. |
| creatorBundleName | Yes | No | string | Name of the bundle that creates the notification. |
| creatorUid | Yes | No | number | UID used for creating the notification. |
| creatorPid | Yes | No | number | PID used for creating the notification. |
| creatorUserId<sup>8+</sup>| Yes | No | number | ID of the user who creates the notification. |
| hashCode | Yes | No | string | Unique ID of the notification. |
| classification | Yes | Yes | string | Notification category.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| isRemoveAllowed<sup>8+</sup> | Yes | No | boolean | Whether the notification can be removed.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| source<sup>8+</sup> | Yes | No | number | Notification source.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| deviceId<sup>8+</sup> | Yes | No | string | Device ID of the notification source.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| isDistributed | Yes | Yes | boolean | No | Whether the notification is a distributed notification. |
| supportDisplayDevices | Yes | Yes | Array\<string> | Yes | Types of the devices to which the notification can be synchronized. |
| supportOperateDevices | Yes | Yes | Array\<string> | No | Devices on which notification can be enabled. |
| remindType | Yes | No | number | No | Notification reminder type.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| isDistributed | Yes | Yes | boolean | Whether the notification is a distributed notification. |
| supportDisplayDevices | Yes | Yes | Array\<string> | Types of the devices to which the notification can be synchronized. |
| supportOperateDevices | Yes | Yes | Array\<string> | Devices on which notification can be enabled. |
| remindType | Yes | No | number | Notification reminder type.<br>**System API**: This is a system API and cannot be called by third-party applications. |