js-apis-commonEvent.md 76.5 KB
Newer Older
E
esterzhou 已提交
1
# CommonEvent
W
wusongqing 已提交
2

E
ester.zhou 已提交
3
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.
W
wusongqing 已提交
4

E
ester.zhou 已提交
5
> **NOTE**
E
ester.zhou 已提交
6 7
>
> 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.
W
wusongqing 已提交
8 9 10 11

## Modules to Import

```js
E
ester.zhou 已提交
12
import CommonEvent from '@ohos.commonEvent';
W
wusongqing 已提交
13 14
```

E
ester.zhou 已提交
15 16 17 18 19 20
## Support

Provides the event types supported by the **CommonEvent** module. The name and value indicate the macro and name of a common event, respectively.

**System capability**: SystemCapability.Notification.CommonEvent

E
ester.zhou 已提交
21
| Name | Value | Subscriber Permission | Description              |
E
ester.zhou 已提交
22 23 24 25 26 27 28 29 30 31 32
| ------------ | ------------------ | ---------------------- | -------------------- |
| 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.         |
| COMMON_EVENT_SHUTDOWN                                        | usual.event.SHUTDOWN                                        | -                                                          | Indicates the common event that the device is being shut down and the final shutdown will proceed.           |
| COMMON_EVENT_BATTERY_CHANGED                                 | usual.event.BATTERY_CHANGED                                 | -                                                          | Indicates the common event that the charging state, level, and other information about the battery have changed.         |
| COMMON_EVENT_BATTERY_LOW                                     | usual.event.BATTERY_LOW                                     | -                                                          | Indicates the common event that the battery level is low.         |
| COMMON_EVENT_BATTERY_OKAY                                    | usual.event.BATTERY_OKAY                                    | -                                                          | Indicates the common event that the battery exits the low state.   |
| COMMON_EVENT_POWER_CONNECTED                                 | usual.event.POWER_CONNECTED                                 | -                                                          | Indicates the common event that the device is connected to an external power supply.           |
| COMMON_EVENT_POWER_DISCONNECTED                              | usual.event.POWER_DISCONNECTED                              | -                                                          | Indicates the common event that the device is disconnected from the external power supply.           |
| COMMON_EVENT_SCREEN_OFF                                      | usual.event.SCREEN_OFF                                      | -                                                          | Indicates the common event that the device screen is off and the device is sleeping.           |
| COMMON_EVENT_SCREEN_ON                                       | usual.event.SCREEN_ON                                       | -                                                          | Indicates the common event that the device screen is on and the device is in interactive state. |
E
ester.zhou 已提交
33
| COMMON_EVENT_THERMAL_LEVEL_CHANGED<sup>8+<sup>                           | usual.event.THERMAL_LEVEL_CHANGED                           | -                                                          | Indicates the common event that the device's thermal level has changed. |
E
ester.zhou 已提交
34 35 36 37 38 39 40 41
| COMMON_EVENT_USER_PRESENT                                    | usual.event.USER_PRESENT                                    | -                                                          | Indicates the common event that the user unlocks the device.     |
| COMMON_EVENT_TIME_TICK                                       | usual.event.TIME_TICK                                       | -                                                          | Indicates the common event that the system time has changed.       |
| COMMON_EVENT_TIME_CHANGED                                    | usual.event.TIME_CHANGED                                    | -                                                          | Indicates the common event that the system time is set.     |
| COMMON_EVENT_DATE_CHANGED                                    | usual.event.DATE_CHANGED                                    | -                                                          | Indicates the common event that the system time has changed.       |
| COMMON_EVENT_TIMEZONE_CHANGED                                | usual.event.TIMEZONE_CHANGED                                | -                                                          | Indicates the common event that the system time zone has changed.         |
| 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.       |
E
ester.zhou 已提交
42
| 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. 
E
ester.zhou 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| 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.   |
| COMMON_EVENT_PACKAGE_CHANGED                                 | usual.event.PACKAGE_CHANGED                                 | -                                                          | Indicates the common event that an application package has been changed (for example, a component in the package has been enabled or disabled). |
| COMMON_EVENT_PACKAGE_RESTARTED                               | usual.event.PACKAGE_RESTARTED                               | -                                                          | Indicates the common event that the user has restarted the application package and killed all its processes.   |
| COMMON_EVENT_PACKAGE_DATA_CLEARED                            | usual.event.PACKAGE_DATA_CLEARED                            | -                                                          | Indicates the common event that the user has cleared the application package data.       |
| COMMON_EVENT_PACKAGE_CACHE_CLEARED<sup>9+</sup>              | usual.event.PACKAGE_CACHE_CLEARED                           | -                                                          | Indicates the common event that the user clears the application package cache.       |
| COMMON_EVENT_PACKAGES_SUSPENDED                              | usual.event.PACKAGES_SUSPENDED                              | -                                                          | Indicates the common event that application packages have been suspended.         |
| COMMON_EVENT_PACKAGES_UNSUSPENDED                            | usual.event.PACKAGES_UNSUSPENDED                            | -                                                          | Indicates the common event that application packages have not been suspended.       |
| COMMON_EVENT_MY_PACKAGE_SUSPENDED                            | usual.event.MY_PACKAGE_SUSPENDED                            | -                                                          | Indicates the common event that an application package has been suspended.         |
| COMMON_EVENT_MY_PACKAGE_UNSUSPENDED                          | usual.event.MY_PACKAGE_UNSUSPENDED                          | -                                                          | Indicates the common event that application package has not been suspended.       |
| COMMON_EVENT_UID_REMOVED                                     | usual.event.UID_REMOVED                                     | -                                                          | Indicates the common event that a user ID has been removed from the system.   |
| COMMON_EVENT_PACKAGE_FIRST_LAUNCH                            | usual.event.PACKAGE_FIRST_LAUNCH                            | -                                                          | Indicates the common event that an installed application is started for the first time.   |
| COMMON_EVENT_PACKAGE_NEEDS_VERIFICATION                      | usual.event.PACKAGE_NEEDS_VERIFICATION                      | -                                                          | Indicates the common event that an application requires system verification.        |
| COMMON_EVENT_PACKAGE_VERIFIED                                | usual.event.PACKAGE_VERIFIED                                | -                                                          | Indicates the common event that an application has been verified by the system.       |
| COMMON_EVENT_EXTERNAL_APPLICATIONS_AVAILABLE                 | usual.event.EXTERNAL_APPLICATIONS_AVAILABLE                 | -                                                          | Indicates the common event that applications installed on the external storage become available for the system.     |
| COMMON_EVENT_EXTERNAL_APPLICATIONS_UNAVAILABLE               | usual.event.EXTERNAL_APPLICATIONS_UNAVAILABLE               | -                                                          | Indicates the common event that applications installed on the external storage become unavailable for the system.       |
| COMMON_EVENT_CONFIGURATION_CHANGED                           | usual.event.CONFIGURATION_CHANGED                           | -                                                          | Indicates the common event that the device state (for example, orientation and locale) has changed.       |
| COMMON_EVENT_LOCALE_CHANGED                                  | usual.event.LOCALE_CHANGED                                  | -                                                          | Indicates the common event that the device locale has changed.     |
| COMMON_EVENT_MANAGE_PACKAGE_STORAGE                          | usual.event.MANAGE_PACKAGE_STORAGE                          | -                                                          | Indicates the common event that the device storage is insufficient.       |
| COMMON_EVENT_DRIVE_MODE                                      | common.event.DRIVE_MODE                                     | -                                                          | Indicates the common event that the system is in driving mode.     |
| COMMON_EVENT_HOME_MODE                                       | common.event.HOME_MODE                                      | -                                                          | Indicates the common event that the system is in home mode.   |
| COMMON_EVENT_OFFICE_MODE                                     | common.event.OFFICE_MODE                                    | -                                                          | Indicates the common event that the system is in office mode.     |
| COMMON_EVENT_USER_STARTED                                    | usual.event.USER_STARTED                                    | -                                                          | Indicates the common event that the user has been started.     |
| COMMON_EVENT_USER_BACKGROUND                                 | usual.event.USER_BACKGROUND                                 | -                                                          | Indicates the common event that the user has been brought to the background.     |
| COMMON_EVENT_USER_FOREGROUND                                 | usual.event.USER_FOREGROUND                                 | -                                                          | Indicates the common event that the user has been brought to the foreground.       |
69 70
| COMMON_EVENT_USER_SWITCHED                                   | usual.event.USER_SWITCHED                                   | ohos.permission.MANAGE_LOCAL_ACCOUNTS                                 | Indicates the common event that user switching is happening.     |
| COMMON_EVENT_USER_STARTING                                   | usual.event.USER_STARTING                                   | ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS                        | Indicates the common event that the user is going to be started.       |
E
ester.zhou 已提交
71
| COMMON_EVENT_USER_UNLOCKED                                   | usual.event.USER_UNLOCKED                                   | -                                                          | Indicates the common event that the credential-encrypted storage has been unlocked for the current user when the device is unlocked after being restarted.    |
72
| COMMON_EVENT_USER_STOPPING                                   | usual.event.USER_STOPPING                                   | ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS                        | Indicates the common event that the user is going to be stopped.   |
E
ester.zhou 已提交
73 74
| COMMON_EVENT_USER_STOPPED                                    | usual.event.USER_STOPPED                                    | -                                                          | Indicates the common event that the user has been stopped.   |
| COMMON_EVENT_WIFI_POWER_STATE                                | usual.event.wifi.POWER_STATE                                | -                                                          | Indicates the common event about the Wi-Fi network state, such as enabled and disabled.     |
E
ester.zhou 已提交
75 76
| COMMON_EVENT_WIFI_SCAN_FINISHED                              | usual.event.wifi.SCAN_FINISHED                              | ohos.permission.LOCATION                                     | Indicates the common event that the Wi-Fi access point has been scanned and proven to be available.      |
| COMMON_EVENT_WIFI_RSSI_VALUE                                 | usual.event.wifi.RSSI_VALUE                                 | ohos.permission.GET_WIFI_INFO                                | Indicates the common event that the Wi-Fi signal strength (RSSI) has changed.     |
E
ester.zhou 已提交
77 78
| COMMON_EVENT_WIFI_CONN_STATE                                 | usual.event.wifi.CONN_STATE                                 | -                                                          | Indicates the common event that the Wi-Fi connection state has changed.      |
| COMMON_EVENT_WIFI_HOTSPOT_STATE                              | usual.event.wifi.HOTSPOT_STATE                              | -                                                          | Indicates the common event about the Wi-Fi hotspot state, such as enabled or disabled.  |
E
ester.zhou 已提交
79
| COMMON_EVENT_WIFI_AP_STA_JOIN                                | usual.event.wifi.WIFI_HS_STA_JOIN                           | ohos.permission.GET_WIFI_INFO                                | Indicates the common event that a client has joined the Wi-Fi hotspot of the current device.      |
E
ester.zhou 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| COMMON_EVENT_WIFI_AP_STA_LEAVE                               | usual.event.wifi.WIFI_HS_STA_LEAVE                          | ohos.permission.GET_WIFI_INFO                                |Indicates the common event that a client has disconnected from the Wi-Fi hotspot of the current device.      |
| COMMON_EVENT_WIFI_MPLINK_STATE_CHANGE                        | usual.event.wifi.mplink.STATE_CHANGE                        | ohos.permission.MPLINK_CHANGE_STATE                          | Indicates the common event that the state of MPLINK (an enhanced Wi-Fi feature) has changed.    |
| COMMON_EVENT_WIFI_P2P_CONN_STATE                             | usual.event.wifi.p2p.CONN_STATE_CHANGE                      | ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION   | Indicates the common event that the Wi-Fi P2P connection state has changed.     |
| COMMON_EVENT_WIFI_P2P_STATE_CHANGED                          | usual.event.wifi.p2p.STATE_CHANGE                           | ohos.permission.GET_WIFI_INFO                                | Indicates the common event about the Wi-Fi P2P state, such as enabled and disabled.       |
| COMMON_EVENT_WIFI_P2P_PEERS_STATE_CHANGED                    | usual.event.wifi.p2p.DEVICES_CHANGE                         | ohos.permission.GET_WIFI_INFO                                | Indicates the common event about the status change of Wi-Fi P2P peer devices.    |
| COMMON_EVENT_WIFI_P2P_PEERS_DISCOVERY_STATE_CHANGED          | usual.event.wifi.p2p.PEER_DISCOVERY_STATE_CHANGE            | ohos.permission.GET_WIFI_INFO                                | Indicates the common event about the Wi-Fi P2P discovery status change.      |
| COMMON_EVENT_WIFI_P2P_CURRENT_DEVICE_STATE_CHANGED           | usual.event.wifi.p2p.CURRENT_DEVICE_CHANGE                  | ohos.permission.GET_WIFI_INFO                                | Indicates the common event about the status change of the Wi-Fi P2P local device.       |
| COMMON_EVENT_WIFI_P2P_GROUP_STATE_CHANGED                    | usual.event.wifi.p2p.GROUP_STATE_CHANGED                    | ohos.permission.GET_WIFI_INFO                                | Indicates the common event that the Wi-Fi P2P group information has changed.       |
| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_UPDATE     | usual.event.bluetooth.handsfree.ag.CONNECT_STATE_UPDATE     | ohos.permission.USE_BLUETOOTH                                | Indicates the common event about the connection state of Bluetooth handsfree communication.       |
| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CURRENT_DEVICE_UPDATE    | usual.event.bluetooth.handsfree.ag.CURRENT_DEVICE_UPDATE    | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the device connected to the Bluetooth handsfree is active.       |
| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_AUDIO_STATE_UPDATE       | usual.event.bluetooth.handsfree.ag.AUDIO_STATE_UPDATE       | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the connection state of Bluetooth A2DP has changed.       |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_UPDATE       | usual.event.bluetooth.a2dpsource.CONNECT_STATE_UPDATE       | ohos.permission.USE_BLUETOOTH                                | Indicates the common event about the connection state of Bluetooth A2DP.     |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CURRENT_DEVICE_UPDATE      | usual.event.bluetooth.a2dpsource.CURRENT_DEVICE_UPDATE      | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the device connected using Bluetooth A2DP is active.     |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_PLAYING_STATE_UPDATE       | usual.event.bluetooth.a2dpsource.PLAYING_STATE_UPDATE       | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the playing state of Bluetooth A2DP has changed.     |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsource.AVRCP_CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the AVRCP connection state of Bluetooth A2DP has changed.     |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_UPDATE         | usual.event.bluetooth.a2dpsource.CODEC_VALUE_UPDATE         | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the audio codec state of Bluetooth A2DP has changed.      |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_DISCOVERED               | usual.event.bluetooth.remotedevice.DISCOVERED               | ohos.permission.LOCATION and ohos.permission.USE_BLUETOOTH   | Indicates the common event that a remote Bluetooth device is discovered.       |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CLASS_VALUE_UPDATE       | usual.event.bluetooth.remotedevice.CLASS_VALUE_UPDATE       | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the Bluetooth class of a remote Bluetooth device has changed.       |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_CONNECTED            | usual.event.bluetooth.remotedevice.ACL_CONNECTED            | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that a low-ACL connection has been established with a remote Bluetooth device.     |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_DISCONNECTED         | usual.event.bluetooth.remotedevice.ACL_DISCONNECTED         | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that a low-ACL connection has been disconnected from a remote Bluetooth device.     |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_NAME_UPDATE              | usual.event.bluetooth.remotedevice.NAME_UPDATE              | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the friendly name of a remote Bluetooth device is retrieved for the first time or is changed since the last retrieval.       |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE               | usual.event.bluetooth.remotedevice.PAIR_STATE               | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the connection state of a remote Bluetooth device has changed.       |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_BATTERY_VALUE_UPDATE     | usual.event.bluetooth.remotedevice.BATTERY_VALUE_UPDATE     | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the battery level of a remote Bluetooth device is retrieved for the first time or is changed since the last retrieval.     |
E
ester.zhou 已提交
103
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_SDP_RESULT               | usual.event.bluetooth.remotedevice.SDP_RESULT               | -                                                          | Indicates the common event about the SDP state of a remote Bluetooth device.    |
E
ester.zhou 已提交
104 105 106 107 108 109 110 111 112 113
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_UUID_VALUE               | usual.event.bluetooth.remotedevice.UUID_VALUE               | ohos.permission.DISCOVER_BLUETOOTH                           | Indicates the common event about the UUID connection state of a remote Bluetooth device.     |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_REQ              | usual.event.bluetooth.remotedevice.PAIRING_REQ              | ohos.permission.DISCOVER_BLUETOOTH                           | Indicates the common event about the pairing request from a remote Bluetooth device.       |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_CANCEL           | usual.event.bluetooth.remotedevice.PAIRING_CANCEL           | -                                                          | Indicates the common event that Bluetooth pairing is canceled.       |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REQ              | usual.event.bluetooth.remotedevice.CONNECT_REQ              | -                                                          | Indicates the common event about the connection request from a remote Bluetooth device.       |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REPLY            | usual.event.bluetooth.remotedevice.CONNECT_REPLY            | -                                                          | Indicates the common event about the response to the connection request from a remote Bluetooth device.       |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_CANCEL           | usual.event.bluetooth.remotedevice.CONNECT_CANCEL           | -                                                          | Indicates the common event that the connection to a remote Bluetooth device has been canceled.       |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_CONNECT_STATE_UPDATE    | usual.event.bluetooth.handsfreeunit.CONNECT_STATE_UPDATE    | -                                                          | Indicates the common event that the connection state of a Bluetooth handsfree has changed.       |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AUDIO_STATE_UPDATE      | usual.event.bluetooth.handsfreeunit.AUDIO_STATE_UPDATE      | -                                                          | Indicates the common event that the audio state of a Bluetooth handsfree has changed.       |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_COMMON_EVENT         | usual.event.bluetooth.handsfreeunit.AG_COMMON_EVENT         | -                                                          | Indicates the common event that the audio gateway state of a Bluetooth handsfree has changed.       |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_CALL_STATE_UPDATE    | usual.event.bluetooth.handsfreeunit.AG_CALL_STATE_UPDATE    | -                                                          | Indicates the common event that the calling state of a Bluetooth handsfree has changed.       |
E
ester.zhou 已提交
114
| COMMON_EVENT_BLUETOOTH_HOST_STATE_UPDATE                     | usual.event.bluetooth.host.STATE_UPDATE                     | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the state of a Bluetooth adapter has been changed, for example, Bluetooth has been enabled or disabled.       |
E
ester.zhou 已提交
115
| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISCOVERABLE                 | usual.event.bluetooth.host.REQ_DISCOVERABLE                 | -                                                          | Indicates the common event about the request for the user to allow Bluetooth device scanning.     |
E
ester.zhou 已提交
116 117 118 119 120 121 122 123 124
| COMMON_EVENT_BLUETOOTH_HOST_REQ_ENABLE                       | usual.event.bluetooth.host.REQ_ENABLE                       | ohos.permission.USE_BLUETOOTH                                | Indicates the common event about the request for the user to enable Bluetooth.       |
| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISABLE                      | usual.event.bluetooth.host.REQ_DISABLE                      | ohos.permission.USE_BLUETOOTH                                | Indicates the common event about the request for the user to disable Bluetooth.     |
| COMMON_EVENT_BLUETOOTH_HOST_SCAN_MODE_UPDATE                 | usual.event.bluetooth.host.SCAN_MODE_UPDATE                 | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the Bluetooth scanning mode of a device has changed.       |
| COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_STARTED                | usual.event.bluetooth.host.DISCOVERY_STARTED                | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the Bluetooth scanning has been started on the device.       |
| COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_FINISHED               | usual.event.bluetooth.host.DISCOVERY_FINISHED               | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the Bluetooth scanning is finished on the device.       |
| COMMON_EVENT_BLUETOOTH_HOST_NAME_UPDATE                      | usual.event.bluetooth.host.NAME_UPDATE                      | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the Bluetooth adapter name of the device has changed.       |
| COMMON_EVENT_BLUETOOTH_A2DPSINK_CONNECT_STATE_UPDATE         | usual.event.bluetooth.a2dpsink.CONNECT_STATE_UPDATE         | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the connection state of Bluetooth A2DP Sink has changed.       |
| COMMON_EVENT_BLUETOOTH_A2DPSINK_PLAYING_STATE_UPDATE         | usual.event.bluetooth.a2dpsink.PLAYING_STATE_UPDATE         | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the playing state of Bluetooth A2DP Sink has changed.       |
| COMMON_EVENT_BLUETOOTH_A2DPSINK_AUDIO_STATE_UPDATE           | usual.event.bluetooth.a2dpsink.AUDIO_STATE_UPDATE           | ohos.permission.USE_BLUETOOTH                                | Indicates the common event that the audio state of Bluetooth A2DP Sink has changed.       |
E
ester.zhou 已提交
125
| COMMON_EVENT_NFC_ACTION_ADAPTER_STATE_CHANGED                | usual.event.nfc.action.ADAPTER_STATE_CHANGED                | -                                                          | Indicates the common event that the state of the device's NFC adapter has changed.    |
E
ester.zhou 已提交
126 127
| COMMON_EVENT_NFC_ACTION_RF_FIELD_ON_DETECTED                 | usual.event.nfc.action.RF_FIELD_ON_DETECTED                 | ohos.permission.MANAGE_SECURE_SETTINGS                       | Indicates the common event that the NFC RF field is detected to be in the enabled state.      |
| COMMON_EVENT_NFC_ACTION_RF_FIELD_OFF_DETECTED                | usual.event.nfc.action.RF_FIELD_OFF_DETECTED                | ohos.permission.MANAGE_SECURE_SETTINGS                       | Indicates the common event that the NFC RF field is detected to be in the disabled state.  |
E
ester.zhou 已提交
128 129 130 131
| COMMON_EVENT_DISCHARGING                                     | usual.event.DISCHARGING                                     | -                                                          | Indicates the common event that the system stops charging the battery.    |
| COMMON_EVENT_CHARGING                                        | usual.event.CHARGING                                        | -                                                          | Indicates the common event that the system starts charging the battery.   |
| COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED                        | usual.event.DEVICE_IDLE_MODE_CHANGED                        | -                                                          | Indicates the common event that the system idle mode has changed.   |
| COMMON_EVENT_POWER_SAVE_MODE_CHANGED                         | usual.event.POWER_SAVE_MODE_CHANGED                         | -                                                          | Indicates the common event that the power saving mode of the system has changed.     |
132 133
| COMMON_EVENT_USER_ADDED                                      | usual.event.USER_ADDED                                      | ohos.permission.MANAGE_LOCAL_ACCOUNTS                                 | Indicates the common event that a user has been added to the system.       |
| COMMON_EVENT_USER_REMOVED                                    | usual.event.USER_REMOVED                                    | ohos.permission.MANAGE_LOCAL_ACCOUNTS                                 | Indicates the common event that a user has been removed from the system.       |
E
ester.zhou 已提交
134 135 136
| COMMON_EVENT_ABILITY_ADDED                                   | usual.event.ABILITY_ADDED                                   | ohos.permission.LISTEN_BUNDLE_CHANGE                         | Indicates the common event that an ability has been added.    |
| COMMON_EVENT_ABILITY_REMOVED                                 | usual.event.ABILITY_REMOVED                                 | ohos.permission.LISTEN_BUNDLE_CHANGE                         | Indicates the common event that an ability has been removed.    |
| COMMON_EVENT_ABILITY_UPDATED                                 | usual.event.ABILITY_UPDATED                                 | ohos.permission.LISTEN_BUNDLE_CHANGE                         | Indicates the common event that an ability has been updated.    |
E
ester.zhou 已提交
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
| COMMON_EVENT_LOCATION_MODE_STATE_CHANGED                     | usual.event.location.MODE_STATE_CHANGED                     | -                                                          | Indicates the common event that the location mode of the system has changed.    |
| COMMON_EVENT_IVI_SLEEP                                       | common.event.IVI_SLEEP                                      | -                                                          | Indicates the common event that the in-vehicle infotainment (IVI) system of a vehicle is sleeping.       |
| COMMON_EVENT_IVI_PAUSE                                       | common.event.IVI_PAUSE                                      | -                                                          | Indicates the common event that the IVI system of a vehicle has entered sleep mode and the playing application is instructed to stop playback.   |
| COMMON_EVENT_IVI_STANDBY                                     | common.event.IVI_STANDBY                                    | -                                                          | Indicates the common event that a third-party application is instructed to pause the current work.    |
| COMMON_EVENT_IVI_LASTMODE_SAVE                               | common.event.IVI_LASTMODE_SAVE                              | -                                                          | Indicates the common event that a third-party application is instructed to save its last mode.     |
| COMMON_EVENT_IVI_VOLTAGE_ABNORMAL                            | common.event.IVI_VOLTAGE_ABNORMAL                           | -                                                          | Indicates the common event that the voltage of the vehicle's power system is abnormal.    |
| COMMON_EVENT_IVI_HIGH_TEMPERATURE                            | common.event.IVI_HIGH_TEMPERATURE                           | -                                                          | Indicates the common event that the temperature of the IVI system is high.    |
| COMMON_EVENT_IVI_EXTREME_TEMPERATURE                         | common.event.IVI_EXTREME_TEMPERATURE                        | -                                                          | Indicates the common event that the temperature of the IVI system is extremely high.    |
| COMMON_EVENT_IVI_TEMPERATURE_ABNORMAL                        | common.event.IVI_TEMPERATURE_ABNORMAL                       | -                                                          | Indicates the common event that the IVI system has an extreme temperature.    |
| COMMON_EVENT_IVI_VOLTAGE_RECOVERY                            | common.event.IVI_VOLTAGE_RECOVERY                           | -                                                          | Indicates the common event that the voltage of the vehicle's power system is restored to normal.    |
| COMMON_EVENT_IVI_TEMPERATURE_RECOVERY                        | common.event.IVI_TEMPERATURE_RECOVERY                       | -                                                          | Indicates the common event that the temperature of the IVI system is restored to normal.    |
| COMMON_EVENT_IVI_ACTIVE                                      | common.event.IVI_ACTIVE                                     | -                                                          | Indicates the common event that the battery service is active.       |
|COMMON_EVENT_USB_STATE<sup>9+</sup>                           | usual.event.hardware.usb.action.USB_STATE                   | -                                                          | Indicates the common event that the USB device status has changed.    |
|COMMON_EVENT_USB_PORT_CHANGED<sup>9+</sup>                    | usual.event.hardware.usb.action.USB_PORT_CHANGED            | -                                                          | Indicates the common event that the USB port status of the user device has changed.         |
| COMMON_EVENT_USB_DEVICE_ATTACHED                             | usual.event.hardware.usb.action.USB_DEVICE_ATTACHED         | -                                                          | Indicates the common event that a USB device has been attached when the user device functions as a USB host.      |
E
ester.zhou 已提交
152
| COMMON_EVENT_USB_DEVICE_DETACHED                             | usual.event.hardware.usb.action.USB_DEVICE_DETACHED         | -                                                          | Indicates the common event that a USB device has been detached when the user device functions as a USB host.      | 
E
ester.zhou 已提交
153 154 155 156 157 158 159 160
| COMMON_EVENT_USB_ACCESSORY_ATTACHED                          | usual.event.hardware.usb.action.USB_ACCESSORY_ATTACHED      | -                                                          | Indicates the common event that a USB accessory was attached.      |
| COMMON_EVENT_USB_ACCESSORY_DETACHED                          | usual.event.hardware.usb.action.USB_ACCESSORY_DETACHED      | -                                                          | Indicates the common event that a USB accessory was detached.    |
| COMMON_EVENT_DISK_REMOVED                                    | usual.event.data.DISK_REMOVED                               | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was removed.    |
| COMMON_EVENT_DISK_UNMOUNTED                                  | usual.event.data.DISK_UNMOUNTED                             | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was unmounted.    |
| COMMON_EVENT_DISK_MOUNTED                                    | usual.event.data.DISK_MOUNTED                               | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was mounted.    |
| COMMON_EVENT_DISK_BAD_REMOVAL                                | usual.event.data.DISK_BAD_REMOVAL                           | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was removed without being unmounted.      |
| COMMON_EVENT_DISK_UNMOUNTABLE                                | usual.event.data.DISK_UNMOUNTABLE                           | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device becomes unmountable.    |
| COMMON_EVENT_DISK_EJECT                                      | usual.event.data.DISK_EJECT                                 | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was ejected.      |
E
ester.zhou 已提交
161 162 163 164 165
| COMMON_EVENT_VOLUME_REMOVED<sup>9+<sup>                                  | usual.event.data.VOLUME_REMOVED                             | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was removed.    |
| COMMON_EVENT_VOLUME_UNMOUNTED<sup>9+<sup>                                | usual.event.data.VOLUME_UNMOUNTED                           | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was unmounted.    |
| COMMON_EVENT_VOLUME_MOUNTED<sup>9+<sup>                                  | usual.event.data.VOLUME_MOUNTED                             | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was mounted.    |
| COMMON_EVENT_VOLUME_BAD_REMOVAL<sup>9+<sup>                              | usual.event.data.VOLUME_BAD_REMOVAL                         | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was removed without being unmounted.      |
| COMMON_EVENT_VOLUME_EJECT<sup>9+<sup>                                    | usual.event.data.VOLUME_EJECT                               | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was ejected.      |
E
ester.zhou 已提交
166 167 168
| COMMON_EVENT_VISIBLE_ACCOUNTS_UPDATED                        | usual.event.data.VISIBLE_ACCOUNTS_UPDATED                   | ohos.permission.GET_APP_ACCOUNTS                             | Indicates the common event that the account visibility changed.       |
| 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.     |
E
ester.zhou 已提交
169
| COMMON_EVENT_AIRPLANE_MODE_CHANGED                           | usual.event.AIRPLANE_MODE                                   | -                                                          | Indicates the common event that the airplane mode of the device has changed.     |
X
xingyanan 已提交
170
| COMMON_EVENT_SPLIT_SCREEN<sup>8+<sup>                                    | usual.event.SPLIT_SCREEN                                    | -                        | Indicates the common event of screen splitting.     |
E
ester.zhou 已提交
171 172
| 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.     |
E
ester.zhou 已提交
173 174


W
wusongqing 已提交
175
## CommonEvent.publish
W
wusongqing 已提交
176

W
wusongqing 已提交
177
publish(event: string, callback: AsyncCallback\<void>): void
W
wusongqing 已提交
178

E
esterzhou 已提交
179
Publishes a common event. This API uses a callback to return the result.
W
wusongqing 已提交
180

E
esterzhou 已提交
181
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
182

W
wusongqing 已提交
183
**Parameters**
W
wusongqing 已提交
184

E
ester.zhou 已提交
185 186 187 188
| Name    | Type                | Mandatory| Description                  |
| -------- | -------------------- | ---- | ---------------------- |
| event    | string               | Yes  | Name of the common event to publish.|
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
189

W
wusongqing 已提交
190
**Example**
W
wusongqing 已提交
191 192

```js
E
ester.zhou 已提交
193
// Callback for common event publication
W
wusongqing 已提交
194
function PublishCallBack(err) {
E
ester.zhou 已提交
195 196 197 198 199
	if (err.code) {
        console.error("publish failed " + JSON.stringify(err));
    } else {
        console.info("publish");
    }
W
wusongqing 已提交
200
}
E
ester.zhou 已提交
201

W
wusongqing 已提交
202
// Publish a common event.
E
ester.zhou 已提交
203
CommonEvent.publish("event", PublishCallBack);
W
wusongqing 已提交
204 205 206 207
```



W
wusongqing 已提交
208
## CommonEvent.publish
W
wusongqing 已提交
209

W
wusongqing 已提交
210
publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\<void>): void
W
wusongqing 已提交
211

E
esterzhou 已提交
212
Publishes a common event with given attributes. This API uses a callback to return the result.
W
wusongqing 已提交
213

E
esterzhou 已提交
214
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
215

W
wusongqing 已提交
216
**Parameters**
W
wusongqing 已提交
217

E
ester.zhou 已提交
218 219 220 221 222
| 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.|
| callback | syncCallback\<void>   | Yes  | Callback used to return the result. |
W
wusongqing 已提交
223

W
wusongqing 已提交
224
**Example**
W
wusongqing 已提交
225 226 227 228 229


```js
// Attributes of a common event.
var options = {
E
ester.zhou 已提交
230 231
	code: 0,			 // Result code of the common event.
	data: "initial data";// Result data of the common event.
E
ester.zhou 已提交
232
	isOrdered: true	 // The common event is an ordered one.
W
wusongqing 已提交
233
}
E
ester.zhou 已提交
234

W
wusongqing 已提交
235 236
// Callback for common event publication
function PublishCallBack(err) {
E
ester.zhou 已提交
237 238 239 240 241
	if (err.code) {
        console.error("publish failed " + JSON.stringify(err));
    } else {
        console.info("publish");
    }
W
wusongqing 已提交
242
}
E
ester.zhou 已提交
243

W
wusongqing 已提交
244
// Publish a common event.
E
ester.zhou 已提交
245
CommonEvent.publish("event", options, PublishCallBack);
W
wusongqing 已提交
246 247 248 249
```



E
esterzhou 已提交
250
## CommonEvent.publishAsUser<sup>8+</sup>
E
ester.zhou 已提交
251 252 253

publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): void

E
esterzhou 已提交
254
Publishes a common event to a specific user. This API uses a callback to return the result.
E
ester.zhou 已提交
255

E
esterzhou 已提交
256
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
257

E
ester.zhou 已提交
258 259
**System API**: This is a system API and cannot be called by third-party applications.

E
ester.zhou 已提交
260 261
**Parameters**

E
ester.zhou 已提交
262 263 264 265 266
| Name    | Type                | Mandatory| Description                              |
| -------- | -------------------- | ---- | ---------------------------------- |
| event    | string               | Yes  | Name of the common event to publish.            |
| userId   | number               | Yes  | User ID.|
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.            |
E
ester.zhou 已提交
267 268 269 270

**Example**

```js
E
ester.zhou 已提交
271
// Callback for common event publication
E
ester.zhou 已提交
272 273
function PublishAsUserCallBack(err) {
	if (err.code) {
E
ester.zhou 已提交
274
        console.error("publishAsUser failed " + JSON.stringify(err));
E
ester.zhou 已提交
275 276 277 278
    } else {
        console.info("publishAsUser");
    }
}
E
ester.zhou 已提交
279

E
ester.zhou 已提交
280 281
// Specify the user to whom the common event will be published.
var userId = 100;
E
ester.zhou 已提交
282

E
ester.zhou 已提交
283
// Publish a common event.
E
ester.zhou 已提交
284
CommonEvent.publishAsUser("event", userId, PublishAsUserCallBack);
E
ester.zhou 已提交
285 286 287 288
```



E
esterzhou 已提交
289
## CommonEvent.publishAsUser<sup>8+</sup>
E
ester.zhou 已提交
290 291 292

publishAsUser(event: string, userId: number, options: CommonEventPublishData, callback: AsyncCallback\<void>): void

E
esterzhou 已提交
293
Publishes a common event with given attributes to a specific user. This API uses a callback to return the result.
E
ester.zhou 已提交
294

E
esterzhou 已提交
295
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
296

E
ester.zhou 已提交
297 298
**System API**: This is a system API and cannot be called by third-party applications.

E
ester.zhou 已提交
299 300
**Parameters**

E
ester.zhou 已提交
301 302 303 304 305 306
| Name    | Type                  | Mandatory| Description                  |
| -------- | ---------------------- | ---- | ---------------------- |
| 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.|
| callback | AsyncCallback\<void>   | Yes  | Callback used to return the result. |
E
ester.zhou 已提交
307 308 309 310 311 312 313

**Example**


```js
// Attributes of a common event.
var options = {
E
ester.zhou 已提交
314 315
	code: 0,			 // Result code of the common event.
	data: "initial data";// Result data of the common event
E
ester.zhou 已提交
316
}
E
ester.zhou 已提交
317

E
ester.zhou 已提交
318 319 320
// Callback for common event publication
function PublishAsUserCallBack(err) {
	if (err.code) {
E
ester.zhou 已提交
321
        console.error("publishAsUser failed " + JSON.stringify(err));
E
ester.zhou 已提交
322 323 324 325
    } else {
        console.info("publishAsUser");
    }
}
E
ester.zhou 已提交
326

E
ester.zhou 已提交
327 328
// Specify the user to whom the common event will be published.
var userId = 100;
E
ester.zhou 已提交
329

E
ester.zhou 已提交
330
// Publish a common event.
E
ester.zhou 已提交
331
CommonEvent.publishAsUser("event", userId, options, PublishAsUserCallBack);
E
ester.zhou 已提交
332 333 334 335
```



W
wusongqing 已提交
336
## CommonEvent.createSubscriber
W
wusongqing 已提交
337

W
wusongqing 已提交
338
createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback\<CommonEventSubscriber>): void
W
wusongqing 已提交
339

E
esterzhou 已提交
340
Creates a subscriber. This API uses a callback to return the result.
W
wusongqing 已提交
341

E
esterzhou 已提交
342
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
343

W
wusongqing 已提交
344
**Parameters**
W
wusongqing 已提交
345

E
ester.zhou 已提交
346 347 348 349
| Name         | Type                                                        | Mandatory| Description                      |
| ------------- | ------------------------------------------------------------ | ---- | -------------------------- |
| subscribeInfo | [CommonEventSubscribeInfo](#commoneventsubscribeinfo)        | Yes  | Subscriber information.            |
| callback      | AsyncCallback\<[CommonEventSubscriber](#commoneventsubscriber)> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
350

W
wusongqing 已提交
351
**Example**
W
wusongqing 已提交
352 353 354 355


```js
var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
E
ester.zhou 已提交
356

E
ester.zhou 已提交
357
// Subscriber information.
W
wusongqing 已提交
358 359 360
var subscribeInfo = {
	events: ["event"]
};
E
ester.zhou 已提交
361

E
ester.zhou 已提交
362
// Callback for subscriber creation.
E
ester.zhou 已提交
363 364 365 366 367 368 369
function CreateSubscriberCallBack(err, commonEventSubscriber) {
    if (err.code) {
        console.error("createSubscriber failed " + JSON.stringify(err));
    } else {
        console.info("createSubscriber");
        subscriber = commonEventSubscriber;
    }
W
wusongqing 已提交
370
}
E
ester.zhou 已提交
371

W
wusongqing 已提交
372 373 374 375 376 377
// Create a subscriber.
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack);
```



W
wusongqing 已提交
378
## CommonEvent.createSubscriber
W
wusongqing 已提交
379

W
wusongqing 已提交
380
createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\<CommonEventSubscriber>
W
wusongqing 已提交
381

E
esterzhou 已提交
382
Creates a subscriber. This API uses a promise to return the result.
W
wusongqing 已提交
383

E
esterzhou 已提交
384
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
385

W
wusongqing 已提交
386
**Parameters**
W
wusongqing 已提交
387

E
ester.zhou 已提交
388 389 390
| Name         | Type                                                 | Mandatory| Description          |
| ------------- | ----------------------------------------------------- | ---- | -------------- |
| subscribeInfo | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | Yes  | Subscriber information.|
W
wusongqing 已提交
391

W
wusongqing 已提交
392
**Return value**
E
ester.zhou 已提交
393
| Type                                                     | Description            |
W
wusongqing 已提交
394
| --------------------------------------------------------- | ---------------- |
W
wusongqing 已提交
395
| Promise\<[CommonEventSubscriber](#commoneventsubscriber)> | Promise used to return the subscriber object.|
W
wusongqing 已提交
396

W
wusongqing 已提交
397
**Example**
W
wusongqing 已提交
398 399 400

```js
var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
E
ester.zhou 已提交
401

E
ester.zhou 已提交
402
// Subscriber information.
W
wusongqing 已提交
403 404 405
var subscribeInfo = {
	events: ["event"]
};
E
ester.zhou 已提交
406

W
wusongqing 已提交
407
// Create a subscriber.
E
ester.zhou 已提交
408 409 410 411 412
CommonEvent.createSubscriber(subscribeInfo).then((commonEventSubscriber) => {
    console.info("createSubscriber");
    subscriber = commonEventSubscriber;
}).catch((err) => {
    console.error("createSubscriber failed " + JSON.stringify(err));
W
wusongqing 已提交
413 414 415 416 417
});
```



W
wusongqing 已提交
418
## CommonEvent.subscribe
W
wusongqing 已提交
419

W
wusongqing 已提交
420
subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEventData>): void
W
wusongqing 已提交
421

E
esterzhou 已提交
422
Subscribes to common events. This API uses a callback to return the result.
W
wusongqing 已提交
423

E
esterzhou 已提交
424
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
425

W
wusongqing 已提交
426
**Parameters**
W
wusongqing 已提交
427

E
ester.zhou 已提交
428 429 430 431
| Name      | Type                                               | Mandatory| Description                            |
| ---------- | ---------------------------------------------------- | ---- | -------------------------------- |
| subscriber | [CommonEventSubscriber](#commoneventsubscriber)     | Yes  | Subscriber object.                |
| callback   | AsyncCallback\<[CommonEventData](#commoneventdata)> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
432

W
wusongqing 已提交
433
**Example**
W
wusongqing 已提交
434 435 436

```js
var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
E
ester.zhou 已提交
437

E
ester.zhou 已提交
438
// Subscriber information.
W
wusongqing 已提交
439 440 441 442
var subscribeInfo = {
    events: ["event"]
};

E
ester.zhou 已提交
443
// Callback for common event subscription.
W
wusongqing 已提交
444
function SubscribeCallBack(err, data) {
E
ester.zhou 已提交
445 446 447 448 449
    if (err.code) {
        console.error("subscribe failed " + JSON.stringify(err));
    } else {
        console.info("subscribe " + JSON.stringify(data));
    }
W
wusongqing 已提交
450 451
}

E
ester.zhou 已提交
452
// Callback for subscriber creation.
E
ester.zhou 已提交
453 454 455 456 457 458 459 460 461
function CreateSubscriberCallBack(err, commonEventSubscriber) {
    if (err.code) {
        console.error("createSubscriber failed " + JSON.stringify(err));
    } else {
        console.info("createSubscriber");
        subscriber = commonEventSubscriber;
        // Subscribe to a common event.
        CommonEvent.subscribe(subscriber, SubscribeCallBack);
    }
W
wusongqing 已提交
462 463 464 465 466 467
}

// Create a subscriber.
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack);
```

E
ester.zhou 已提交
468

W
wusongqing 已提交
469

W
wusongqing 已提交
470
## CommonEvent.unsubscribe
W
wusongqing 已提交
471

W
wusongqing 已提交
472
unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>): void
W
wusongqing 已提交
473

E
esterzhou 已提交
474
Unsubscribes from common events. This API uses a callback to return the result.
W
wusongqing 已提交
475

E
esterzhou 已提交
476
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
477

W
wusongqing 已提交
478
**Parameters**
W
wusongqing 已提交
479

E
ester.zhou 已提交
480 481 482 483
| Name      | Type                                            | Mandatory| Description                    |
| ---------- | ----------------------------------------------- | ---- | ------------------------ |
| subscriber | [CommonEventSubscriber](#commoneventsubscriber) | Yes  | Subscriber object.        |
| callback   | AsyncCallback\<void>                            | No  | Callback used to return the result.|
W
wusongqing 已提交
484

W
wusongqing 已提交
485
**Example**
W
wusongqing 已提交
486 487 488

```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
E
ester.zhou 已提交
489

E
ester.zhou 已提交
490
// Subscriber information.
W
wusongqing 已提交
491 492 493
var subscribeInfo = {
	events: ["event"]
};
E
ester.zhou 已提交
494

E
ester.zhou 已提交
495
// Callback for common event subscription.
W
wusongqing 已提交
496
function SubscribeCallBack(err, data) {
E
ester.zhou 已提交
497 498 499 500 501
    if (err.code) {
        console.info("subscribe failed " + JSON.stringify(err));
    } else {
        console.info("subscribe " + JSON.stringify(data));
    }
W
wusongqing 已提交
502
}
E
ester.zhou 已提交
503

E
ester.zhou 已提交
504
// Callback for subscriber creation.
E
ester.zhou 已提交
505 506 507 508 509 510 511 512 513
function CreateSubscriberCallBack(err, commonEventSubscriber) {
    if (err.code) {
        console.info("createSubscriber failed " + JSON.stringify(err));
    } else {
        console.info("createSubscriber");
        subscriber = commonEventSubscriber;
        // Subscribe to a common event.
        CommonEvent.subscribe(subscriber, SubscribeCallBack);
    }
W
wusongqing 已提交
514
}
E
ester.zhou 已提交
515

E
ester.zhou 已提交
516
// Callback for common event unsubscription.
W
wusongqing 已提交
517
function UnsubscribeCallBack(err) {
E
ester.zhou 已提交
518 519 520 521 522
	if (err.code) {
        console.info("unsubscribe failed " + JSON.stringify(err));
    } else {
        console.info("unsubscribe");
    }
W
wusongqing 已提交
523
}
E
ester.zhou 已提交
524

W
wusongqing 已提交
525 526
// Create a subscriber.
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack);
E
ester.zhou 已提交
527

W
wusongqing 已提交
528 529 530 531
// Unsubscribe from the common event.
CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack);
```

W
wusongqing 已提交
532
## CommonEventSubscriber
W
wusongqing 已提交
533

W
wusongqing 已提交
534
### getCode
W
wusongqing 已提交
535

W
wusongqing 已提交
536
getCode(callback: AsyncCallback\<number>): void
W
wusongqing 已提交
537

E
esterzhou 已提交
538
Obtains the result code of this common event. This API uses a callback to return the result.
W
wusongqing 已提交
539

E
esterzhou 已提交
540
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
541

W
wusongqing 已提交
542
**Parameters**
W
wusongqing 已提交
543

E
ester.zhou 已提交
544
| Name  | Type                  | Mandatory| Description              |
W
wusongqing 已提交
545
| -------- | ---------------------- | ---- | ------------------ |
E
ester.zhou 已提交
546
| callback | AsyncCallback\<number> | Yes  | Callback used to return the result code.|
W
wusongqing 已提交
547

W
wusongqing 已提交
548
**Example**
W
wusongqing 已提交
549

W
wusongqing 已提交
550
```js
E
esterzhou 已提交
551
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
552

E
ester.zhou 已提交
553
// Callback for result code obtaining of an ordered common event.
E
ester.zhou 已提交
554 555 556 557 558 559
function getCodeCallback(err, Code) {
    if (err.code) {
        console.error("getCode failed " + JSON.stringify(err));
    } else {
        console.info("getCode " + JSON.stringify(Code));
    }
W
wusongqing 已提交
560 561 562
}
subscriber.getCode(getCodeCallback);
```
W
wusongqing 已提交
563

W
wusongqing 已提交
564
### getCode
W
wusongqing 已提交
565

W
wusongqing 已提交
566
getCode(): Promise\<number>
W
wusongqing 已提交
567

E
esterzhou 已提交
568
Obtains the result code of this common event. This API uses a promise to return the result.
W
wusongqing 已提交
569

E
esterzhou 已提交
570
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
571

W
wusongqing 已提交
572
**Return value**
W
wusongqing 已提交
573

E
ester.zhou 已提交
574
| Type            | Description                |
W
wusongqing 已提交
575
| ---------------- | -------------------- |
E
ester.zhou 已提交
576
| Promise\<number> | Promise used to return the result.|
W
wusongqing 已提交
577

W
wusongqing 已提交
578
**Example**
W
wusongqing 已提交
579

W
wusongqing 已提交
580
```js
E
esterzhou 已提交
581
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
582 583 584 585 586

subscriber.getCode().then((Code) => {
    console.info("getCode " + JSON.stringify(Code));
}).catch((err) => {
    console.error("getCode failed " + JSON.stringify(err));
W
wusongqing 已提交
587 588
});
```
W
wusongqing 已提交
589

W
wusongqing 已提交
590
### setCode
W
wusongqing 已提交
591

W
wusongqing 已提交
592
setCode(code: number, callback: AsyncCallback\<void>): void
W
wusongqing 已提交
593

E
esterzhou 已提交
594
Sets the result code for this common event. This API uses a callback to return the result.
W
wusongqing 已提交
595

E
esterzhou 已提交
596
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
597

W
wusongqing 已提交
598
**Parameters**
W
wusongqing 已提交
599

E
ester.zhou 已提交
600
| Name  | Type                | Mandatory| Description                  |
W
wusongqing 已提交
601
| -------- | -------------------- | ---- | ---------------------- |
E
ester.zhou 已提交
602 603
| code     | number               | Yes  | Result code of the common event.  |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
604

W
wusongqing 已提交
605
**Example**
W
wusongqing 已提交
606

W
wusongqing 已提交
607
```js
E
esterzhou 已提交
608
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
609

E
ester.zhou 已提交
610
// Callback for result code setting of an ordered common event.
W
wusongqing 已提交
611
function setCodeCallback(err) {
E
ester.zhou 已提交
612 613 614 615 616
    if (err.code) {
        console.error("setCode failed " + JSON.stringify(err));
    } else {
        console.info("setCode");
    }
W
wusongqing 已提交
617 618 619
}
subscriber.setCode(1, setCodeCallback);
```
W
wusongqing 已提交
620

W
wusongqing 已提交
621
### setCode
W
wusongqing 已提交
622

W
wusongqing 已提交
623
setCode(code: number): Promise\<void>
W
wusongqing 已提交
624

E
esterzhou 已提交
625
Sets the result code for this common event. This API uses a promise to return the result.
W
wusongqing 已提交
626

E
esterzhou 已提交
627
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
628

W
wusongqing 已提交
629
**Parameters**
W
wusongqing 已提交
630

E
ester.zhou 已提交
631
| Name| Type  | Mandatory| Description              |
W
wusongqing 已提交
632
| ------ | ------ | ---- | ------------------ |
E
ester.zhou 已提交
633 634 635 636 637 638
| code   | number | Yes  | Result code of the common event.|

**Return value**

| Type            | Description                |
| ---------------- | -------------------- |
E
ester.zhou 已提交
639
| Promise\<void>   | Promise used to return the result.|
W
wusongqing 已提交
640

W
wusongqing 已提交
641
**Example**
W
wusongqing 已提交
642

W
wusongqing 已提交
643
```js
E
esterzhou 已提交
644
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
645

W
wusongqing 已提交
646
subscriber.setCode(1).then(() => {
E
ester.zhou 已提交
647 648 649
    console.info("setCode");
}).catch((err) => {
    console.error("setCode failed " + JSON.stringify(err));
W
wusongqing 已提交
650 651
});
```
W
wusongqing 已提交
652

W
wusongqing 已提交
653
### getData
W
wusongqing 已提交
654

W
wusongqing 已提交
655
getData(callback: AsyncCallback\<string>): void
W
wusongqing 已提交
656

E
esterzhou 已提交
657
Obtains the result data of this common event. This API uses a callback to return the result.
W
wusongqing 已提交
658

E
esterzhou 已提交
659
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
660

W
wusongqing 已提交
661
**Parameters**
W
wusongqing 已提交
662

E
ester.zhou 已提交
663
| Name  | Type                  | Mandatory| Description                |
W
wusongqing 已提交
664
| -------- | ---------------------- | ---- | -------------------- |
E
ester.zhou 已提交
665
| callback | AsyncCallback\<string> | Yes  | Result data of the common event.|
W
wusongqing 已提交
666

W
wusongqing 已提交
667
**Example**
W
wusongqing 已提交
668

W
wusongqing 已提交
669
```js
E
esterzhou 已提交
670
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
671

E
ester.zhou 已提交
672
// Callback for result data obtaining of an ordered common event.
E
ester.zhou 已提交
673 674 675 676 677 678
function getDataCallback(err, Data) {
    if (err.code) {
        console.error("getData failed " + JSON.stringify(err));
    } else {
        console.info("getData " + JSON.stringify(Data));
    }
W
wusongqing 已提交
679 680 681
}
subscriber.getData(getDataCallback);
```
W
wusongqing 已提交
682

W
wusongqing 已提交
683
### getData
W
wusongqing 已提交
684

W
wusongqing 已提交
685
getData(): Promise\<string>
W
wusongqing 已提交
686

E
esterzhou 已提交
687
Obtains the result data of this common event. This API uses a promise to return the result.
W
wusongqing 已提交
688

E
esterzhou 已提交
689
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
690

W
wusongqing 已提交
691
**Return value**
W
wusongqing 已提交
692

E
ester.zhou 已提交
693
| Type            | Description              |
W
wusongqing 已提交
694
| ---------------- | ------------------ |
E
ester.zhou 已提交
695
| Promise\<string> | Result data of the common event.|
W
wusongqing 已提交
696

W
wusongqing 已提交
697
**Example**
W
wusongqing 已提交
698

W
wusongqing 已提交
699
```js
E
esterzhou 已提交
700
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
701 702 703 704 705

subscriber.getData().then((Data) => {
    console.info("getData " + JSON.stringify(Data));
}).catch((err) => {
    console.error("getData failed " + JSON.stringify(err));
W
wusongqing 已提交
706 707
});
```
W
wusongqing 已提交
708

W
wusongqing 已提交
709
### setData
W
wusongqing 已提交
710

W
wusongqing 已提交
711
setData(data: string, callback: AsyncCallback\<void>): void
W
wusongqing 已提交
712

E
esterzhou 已提交
713
Sets the result data for this common event. This API uses a callback to return the result.
W
wusongqing 已提交
714

E
esterzhou 已提交
715
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
716

W
wusongqing 已提交
717
**Parameters**
W
wusongqing 已提交
718

E
ester.zhou 已提交
719
| Name  | Type                | Mandatory| Description                |
W
wusongqing 已提交
720
| -------- | -------------------- | ---- | -------------------- |
E
ester.zhou 已提交
721 722
| data     | string               | Yes  | Result data of the common event.  |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
723

W
wusongqing 已提交
724
**Example**
W
wusongqing 已提交
725

W
wusongqing 已提交
726
```js
E
esterzhou 已提交
727
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
728

W
wusongqing 已提交
729 730
// Callback for result data setting of an ordered common event
function setDataCallback(err) {
E
ester.zhou 已提交
731 732 733 734 735
    if (err.code) {
        console.error("setData failed " + JSON.stringify(err));
    } else {
        console.info("setData");
    }
W
wusongqing 已提交
736 737 738
}
subscriber.setData("publish_data_changed", setDataCallback);
```
W
wusongqing 已提交
739

W
wusongqing 已提交
740
### setData
W
wusongqing 已提交
741

W
wusongqing 已提交
742
setData(data: string): Promise\<void>
W
wusongqing 已提交
743

E
esterzhou 已提交
744
Sets the result data for this common event. This API uses a promise to return the result.
W
wusongqing 已提交
745

E
esterzhou 已提交
746
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
747

W
wusongqing 已提交
748
**Parameters**
W
wusongqing 已提交
749

E
ester.zhou 已提交
750
| Name| Type  | Mandatory| Description                |
W
wusongqing 已提交
751
| ------ | ------ | ---- | -------------------- |
E
ester.zhou 已提交
752 753 754 755 756 757
| data   | string | Yes  | Result data of the common event.|

**Return value**

| Type            | Description                |
| ---------------- | -------------------- |
E
ester.zhou 已提交
758
| Promise\<void>   | Promise used to return the result.|
W
wusongqing 已提交
759

W
wusongqing 已提交
760
**Example**
W
wusongqing 已提交
761

W
wusongqing 已提交
762
```js
E
esterzhou 已提交
763
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
764

W
wusongqing 已提交
765
subscriber.setData("publish_data_changed").then(() => {
E
ester.zhou 已提交
766 767 768
    console.info("setData");
}).catch((err) => {
    console.error("setData failed " + JSON.stringify(err));
W
wusongqing 已提交
769 770
});
```
W
wusongqing 已提交
771

W
wusongqing 已提交
772
### setCodeAndData
W
wusongqing 已提交
773

W
wusongqing 已提交
774
setCodeAndData(code: number, data: string, callback:AsyncCallback\<void>): void
W
wusongqing 已提交
775

E
esterzhou 已提交
776
Sets the result code and result data for this common event. This API uses a callback to return the result.
W
wusongqing 已提交
777

E
esterzhou 已提交
778
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
779

W
wusongqing 已提交
780
**Parameters**
W
wusongqing 已提交
781

E
ester.zhou 已提交
782
| Name  | Type                | Mandatory| Description                  |
W
wusongqing 已提交
783
| -------- | -------------------- | ---- | ---------------------- |
E
ester.zhou 已提交
784 785 786
| code     | number               | Yes  | Result code of the common event.  |
| data     | string               | Yes  | Result data of the common event.  |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
787

W
wusongqing 已提交
788
**Example**
W
wusongqing 已提交
789

W
wusongqing 已提交
790
```js
E
esterzhou 已提交
791
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
792

E
ester.zhou 已提交
793
// Callback for result code and result data setting of an ordered common event.
W
wusongqing 已提交
794
function setCodeDataCallback(err) {
E
ester.zhou 已提交
795 796 797 798 799
    if (err.code) {
        console.error("setCodeAndData failed " + JSON.stringify(err));
    } else {
        console.info("setCodeDataCallback");
    }
W
wusongqing 已提交
800 801 802
}
subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCallback);
```
W
wusongqing 已提交
803

W
wusongqing 已提交
804
### setCodeAndData
W
wusongqing 已提交
805

W
wusongqing 已提交
806
setCodeAndData(code: number, data: string): Promise\<void>
W
wusongqing 已提交
807

E
esterzhou 已提交
808
Sets the result code and result data for this common event. This API uses a promise to return the result.
W
wusongqing 已提交
809

E
esterzhou 已提交
810
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
811

W
wusongqing 已提交
812
**Parameters**
W
wusongqing 已提交
813

E
ester.zhou 已提交
814
| Name| Type  | Mandatory| Description                |
W
wusongqing 已提交
815
| ------ | ------ | ---- | -------------------- |
E
ester.zhou 已提交
816
| code   | number | Yes  | Result code of the common event.|
E
ester.zhou 已提交
817 818 819 820 821 822 823
| data   | string | Yes  | Result data of the common event.|

**Return value**

| Type            | Description                |
| ---------------- | -------------------- |
| Promise\<void>   | Promise used to return the result.|
W
wusongqing 已提交
824

W
wusongqing 已提交
825
**Example**
W
wusongqing 已提交
826

W
wusongqing 已提交
827
```js
E
esterzhou 已提交
828
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
829

W
wusongqing 已提交
830
subscriber.setCodeAndData(1, "publish_data_changed").then(() => {
E
ester.zhou 已提交
831 832 833
    console.info("setCodeAndData");
}).catch((err) => {
    console.info("setCodeAndData failed " + JSON.stringify(err));
W
wusongqing 已提交
834 835
});
```
W
wusongqing 已提交
836

W
wusongqing 已提交
837
### isOrderedCommonEvent
W
wusongqing 已提交
838

W
wusongqing 已提交
839
isOrderedCommonEvent(callback: AsyncCallback\<boolean>): void
W
wusongqing 已提交
840

E
esterzhou 已提交
841
Checks whether this common event is an ordered one. This API uses a callback to return the result.
W
wusongqing 已提交
842

E
esterzhou 已提交
843
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
844

W
wusongqing 已提交
845
**Parameters**
W
wusongqing 已提交
846

E
ester.zhou 已提交
847
| Name  | Type                   | Mandatory| Description                              |
W
wusongqing 已提交
848
| -------- | ----------------------- | ---- | ---------------------------------- |
E
ester.zhou 已提交
849
| callback | AsyncCallback\<boolean> | Yes  | Returns **true** if the common event is an ordered one; returns **false** otherwise.|
W
wusongqing 已提交
850

W
wusongqing 已提交
851
**Example**
W
wusongqing 已提交
852

W
wusongqing 已提交
853
```js
E
esterzhou 已提交
854
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
855

E
ester.zhou 已提交
856
// Callback for checking whether the current common event is an ordered one.
E
ester.zhou 已提交
857 858 859 860 861 862
function isOrderedCallback(err, isOrdered) {
    if (err.code) {
        console.error("isOrderedCommonEvent failed " + JSON.stringify(err));
    } else {
        console.info("isOrdered " + JSON.stringify(isOrdered));
    }
W
wusongqing 已提交
863 864 865
}
subscriber.isOrderedCommonEvent(isOrderedCallback);
```
W
wusongqing 已提交
866

W
wusongqing 已提交
867
### isOrderedCommonEvent
W
wusongqing 已提交
868

W
wusongqing 已提交
869
isOrderedCommonEvent(): Promise\<boolean>
W
wusongqing 已提交
870

E
esterzhou 已提交
871
Checks whether this common event is an ordered one. This API uses a promise to return the result.
W
wusongqing 已提交
872

E
esterzhou 已提交
873
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
874

W
wusongqing 已提交
875
**Return value**
W
wusongqing 已提交
876

E
ester.zhou 已提交
877
| Type             | Description                            |
W
wusongqing 已提交
878 879
| ----------------- | -------------------------------- |
| Promise\<boolean> | Returns **true** if the common event is an ordered one; returns **false** otherwise.|
W
wusongqing 已提交
880

W
wusongqing 已提交
881
**Example**
W
wusongqing 已提交
882

W
wusongqing 已提交
883
```js
E
esterzhou 已提交
884
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
885 886 887 888 889

subscriber.isOrderedCommonEvent().then((isOrdered) => {
    console.info("isOrdered " + JSON.stringify(isOrdered));
}).catch((err) => {
    console.error("isOrdered failed " + JSON.stringify(err));
W
wusongqing 已提交
890 891
});
```
W
wusongqing 已提交
892

E
ester.zhou 已提交
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911
### isStickyCommonEvent

isStickyCommonEvent(callback: AsyncCallback\<boolean>): void

Checks whether this common event is a sticky one. This API uses a callback to return the result.

**System capability**: SystemCapability.Notification.CommonEvent

**Parameters**

| Name  | Type                   | Mandatory| Description                              |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | Yes  | Returns **true** if the common event is a sticky one; returns **false** otherwise.|

**Example**

```js
var subscriber;	// Subscriber object successfully created.

E
ester.zhou 已提交
912
// Callback for checking whether the current common event is a sticky one.
E
ester.zhou 已提交
913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
function isStickyCallback(err, isSticky) {
    if (err.code) {
        console.error("isStickyCommonEvent failed " + JSON.stringify(err));
    } else {
        console.info("isSticky " + JSON.stringify(isSticky));
    }
}
subscriber.isStickyCommonEvent(isStickyCallback);
```

### isStickyCommonEvent

isStickyCommonEvent(): Promise\<boolean>

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\<boolean> | Returns **true** if the common event is a sticky one; returns **false** otherwise.|

**Example**

```js
var subscriber;	// Subscriber object successfully created.

subscriber.isStickyCommonEvent().then((isSticky) => {
    console.info("isSticky " + JSON.stringify(isSticky));
}).catch((err) => {
    console.error("isSticky failed " + JSON.stringify(err));
});
```

W
wusongqing 已提交
949
### abortCommonEvent
W
wusongqing 已提交
950

W
wusongqing 已提交
951
abortCommonEvent(callback: AsyncCallback\<void>): void
W
wusongqing 已提交
952

E
esterzhou 已提交
953
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 callback to return the result.
W
wusongqing 已提交
954

E
esterzhou 已提交
955
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
956

W
wusongqing 已提交
957
**Parameters**
W
wusongqing 已提交
958

E
ester.zhou 已提交
959
| Name  | Type                | Mandatory| Description                |
W
wusongqing 已提交
960
| -------- | -------------------- | ---- | -------------------- |
E
ester.zhou 已提交
961
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
962

W
wusongqing 已提交
963
**Example**
W
wusongqing 已提交
964

W
wusongqing 已提交
965
```js
E
esterzhou 已提交
966
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
967

E
ester.zhou 已提交
968
// Callback for common event aborting.
W
wusongqing 已提交
969
function abortCallback(err) {
E
ester.zhou 已提交
970 971 972 973 974
    if (err.code) {
        console.error("abortCommonEvent failed " + JSON.stringify(err));
    } else {
        console.info("abortCommonEvent");
    }
W
wusongqing 已提交
975 976 977
}
subscriber.abortCommonEvent(abortCallback);
```
W
wusongqing 已提交
978

W
wusongqing 已提交
979
### abortCommonEvent
W
wusongqing 已提交
980

W
wusongqing 已提交
981
abortCommonEvent(): Promise\<void>
W
wusongqing 已提交
982

E
esterzhou 已提交
983
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.
W
wusongqing 已提交
984

E
esterzhou 已提交
985
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
986

E
ester.zhou 已提交
987 988 989 990 991 992
**Return value**

| Type            | Description                |
| ---------------- | -------------------- |
| Promise\<void>   | Promise used to return the result.|

W
wusongqing 已提交
993
**Example**
W
wusongqing 已提交
994

W
wusongqing 已提交
995
```js
E
esterzhou 已提交
996
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
997

W
wusongqing 已提交
998
subscriber.abortCommonEvent().then(() => {
E
ester.zhou 已提交
999 1000 1001
    console.info("abortCommonEvent");
}).catch((err) => {
    console.error("abortCommonEvent failed " + JSON.stringify(err));
W
wusongqing 已提交
1002 1003
});
```
W
wusongqing 已提交
1004

W
wusongqing 已提交
1005
### clearAbortCommonEvent
W
wusongqing 已提交
1006

W
wusongqing 已提交
1007
clearAbortCommonEvent(callback: AsyncCallback\<void>): void
W
wusongqing 已提交
1008

E
esterzhou 已提交
1009
Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses a callback to return the result.
W
wusongqing 已提交
1010

E
esterzhou 已提交
1011
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
1012

W
wusongqing 已提交
1013
**Parameters**
W
wusongqing 已提交
1014

E
ester.zhou 已提交
1015
| Name  | Type                | Mandatory| Description                |
W
wusongqing 已提交
1016
| -------- | -------------------- | ---- | -------------------- |
E
ester.zhou 已提交
1017
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
1018

W
wusongqing 已提交
1019
**Example**
W
wusongqing 已提交
1020

W
wusongqing 已提交
1021
```js
E
esterzhou 已提交
1022
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
1023

E
ester.zhou 已提交
1024
// Callback for clearing the aborted state of the current common event.
W
wusongqing 已提交
1025
function clearAbortCallback(err) {
E
ester.zhou 已提交
1026 1027 1028 1029 1030
    if (err.code) {
        console.error("clearAbortCommonEvent failed " + JSON.stringify(err));
    } else {
        console.info("clearAbortCommonEvent");
    }
W
wusongqing 已提交
1031 1032 1033
}
subscriber.clearAbortCommonEvent(clearAbortCallback);
```
W
wusongqing 已提交
1034

W
wusongqing 已提交
1035
### clearAbortCommonEvent
W
wusongqing 已提交
1036

W
wusongqing 已提交
1037
clearAbortCommonEvent(): Promise\<void>
W
wusongqing 已提交
1038

E
esterzhou 已提交
1039
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.
W
wusongqing 已提交
1040

E
esterzhou 已提交
1041
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
1042

E
ester.zhou 已提交
1043 1044 1045 1046 1047 1048
**Return value**

| Type            | Description                |
| ---------------- | -------------------- |
| Promise\<void>   | Promise used to return the result.|

W
wusongqing 已提交
1049
**Example**
W
wusongqing 已提交
1050

W
wusongqing 已提交
1051
```js
E
esterzhou 已提交
1052
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
1053

W
wusongqing 已提交
1054
subscriber.clearAbortCommonEvent().then(() => {
E
ester.zhou 已提交
1055 1056 1057
    console.info("clearAbortCommonEvent");
}).catch((err) => {
    console.error("clearAbortCommonEvent failed " + JSON.stringify(err));
W
wusongqing 已提交
1058 1059
});
```
W
wusongqing 已提交
1060

W
wusongqing 已提交
1061
### getAbortCommonEvent
W
wusongqing 已提交
1062

W
wusongqing 已提交
1063
getAbortCommonEvent(callback: AsyncCallback\<boolean>): void
W
wusongqing 已提交
1064

E
esterzhou 已提交
1065
Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses a callback to return the result.
W
wusongqing 已提交
1066

E
esterzhou 已提交
1067
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
1068

W
wusongqing 已提交
1069
**Parameters**
W
wusongqing 已提交
1070

E
ester.zhou 已提交
1071
| Name  | Type                   | Mandatory| Description                              |
W
wusongqing 已提交
1072
| -------- | ----------------------- | ---- | ---------------------------------- |
E
ester.zhou 已提交
1073
| callback | AsyncCallback\<boolean> | Yes  | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.|
W
wusongqing 已提交
1074

W
wusongqing 已提交
1075
**Example**
W
wusongqing 已提交
1076

W
wusongqing 已提交
1077
```js
E
esterzhou 已提交
1078
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
1079

E
ester.zhou 已提交
1080
// Callback for checking whether the current common event is in the aborted state.
E
ester.zhou 已提交
1081 1082 1083 1084 1085 1086
function getAbortCallback(err, AbortCommonEvent) {
    if (err.code) {
        console.error("getAbortCommonEvent failed " + JSON.stringify(err));
    } else {
        console.info("AbortCommonEvent " + AbortCommonEvent)
    }
W
wusongqing 已提交
1087 1088 1089
}
subscriber.getAbortCommonEvent(getAbortCallback);
```
W
wusongqing 已提交
1090

W
wusongqing 已提交
1091
### getAbortCommonEvent
W
wusongqing 已提交
1092

E
ester.zhou 已提交
1093
getAbortCommonEvent(): Promise\<boolean>
W
wusongqing 已提交
1094

E
esterzhou 已提交
1095
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.
W
wusongqing 已提交
1096

E
esterzhou 已提交
1097
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
1098

W
wusongqing 已提交
1099
**Return value**
W
wusongqing 已提交
1100

E
ester.zhou 已提交
1101
| Type             | Description                              |
W
wusongqing 已提交
1102 1103
| ----------------- | ---------------------------------- |
| Promise\<boolean> | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.|
W
wusongqing 已提交
1104

W
wusongqing 已提交
1105
**Example**
W
wusongqing 已提交
1106

W
wusongqing 已提交
1107
```js
E
esterzhou 已提交
1108
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
1109 1110 1111 1112 1113

subscriber.getAbortCommonEvent().then((AbortCommonEvent) => {
    console.info("AbortCommonEvent " + JSON.stringify(AbortCommonEvent));
}).catch((err) => {
    console.error("getAbortCommonEvent failed " + JSON.stringify(err));
W
wusongqing 已提交
1114 1115
});
```
W
wusongqing 已提交
1116

W
wusongqing 已提交
1117
### getSubscribeInfo
W
wusongqing 已提交
1118

W
wusongqing 已提交
1119
getSubscribeInfo(callback: AsyncCallback\<CommonEventSubscribeInfo>): void
W
wusongqing 已提交
1120

E
esterzhou 已提交
1121
Obtains the subscriber information. This API uses a callback to return the result.
W
wusongqing 已提交
1122

E
esterzhou 已提交
1123
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
1124

W
wusongqing 已提交
1125
**Parameters**
W
wusongqing 已提交
1126

E
ester.zhou 已提交
1127
| Name  | Type                                                        | Mandatory| Description                  |
W
wusongqing 已提交
1128
| -------- | ------------------------------------------------------------ | ---- | ---------------------- |
E
ester.zhou 已提交
1129
| callback | AsyncCallback\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Yes  | Promise used to return the subscriber information.|
W
wusongqing 已提交
1130

W
wusongqing 已提交
1131
**Example**
W
wusongqing 已提交
1132

W
wusongqing 已提交
1133
```js
E
esterzhou 已提交
1134
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
1135

E
ester.zhou 已提交
1136
// Callback for subscriber information obtaining.
E
ester.zhou 已提交
1137 1138 1139 1140 1141 1142
function getSubscribeInfoCallback(err, SubscribeInfo) {
    if (err.code) {
        console.error("getSubscribeInfo failed " + JSON.stringify(err));
    } else {
        console.info("SubscribeInfo " + JSON.stringify(SubscribeInfo));
    }
W
wusongqing 已提交
1143 1144 1145
}
subscriber.getSubscribeInfo(getSubscribeInfoCallback);
```
W
wusongqing 已提交
1146

W
wusongqing 已提交
1147
### getSubscribeInfo
W
wusongqing 已提交
1148

W
wusongqing 已提交
1149
getSubscribeInfo(): Promise\<CommonEventSubscribeInfo>
W
wusongqing 已提交
1150

E
esterzhou 已提交
1151
Obtains the subscriber information. This API uses a promise to return the result.
W
wusongqing 已提交
1152

E
esterzhou 已提交
1153
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
1154

W
wusongqing 已提交
1155
**Return value**
W
wusongqing 已提交
1156

E
ester.zhou 已提交
1157
| Type                                                        | Description                  |
W
wusongqing 已提交
1158
| ------------------------------------------------------------ | ---------------------- |
W
wusongqing 已提交
1159
| Promise\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Promise used to return the subscriber information.|
W
wusongqing 已提交
1160

W
wusongqing 已提交
1161
**Example**
W
wusongqing 已提交
1162

W
wusongqing 已提交
1163
```js
E
esterzhou 已提交
1164
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
1165 1166 1167 1168 1169

subscriber.getSubscribeInfo().then((SubscribeInfo) => {
    console.info("SubscribeInfo " + JSON.stringify(SubscribeInfo));
}).catch((err) => {
    console.error("getSubscribeInfo failed " + JSON.stringify(err));
W
wusongqing 已提交
1170 1171
});
```
E
ester.zhou 已提交
1172

E
ester.zhou 已提交
1173
### finishCommonEvent<sup>9+</sup>
E
ester.zhou 已提交
1174 1175 1176

finishCommonEvent(callback: AsyncCallback\<void\>): void

E
ester.zhou 已提交
1177
Finishes this ordered common event. This API uses a callback to return the result.
E
ester.zhou 已提交
1178 1179 1180 1181 1182 1183 1184

**System capability**: SystemCapability.Notification.CommonEvent

**Parameters**

| Name  | Type                 | Mandatory| Description                             |
| -------- | -------------------- | ---- | -------------------------------- |
E
ester.zhou 已提交
1185
| callback | AsyncCallback\<void> | Yes  | Callback returned after the ordered common event is finished.|
E
ester.zhou 已提交
1186 1187 1188 1189 1190 1191

**Example**

```js
var subscriber; // Subscriber object successfully created.

E
ester.zhou 已提交
1192
// Callback for ordered common event finishing.
E
ester.zhou 已提交
1193
function finishCommonEventCallback(err) {
E
ester.zhou 已提交
1194
  if (err.code) {
E
ester.zhou 已提交
1195 1196 1197 1198
    console.error("finishCommonEvent failed " + JSON.stringify(err));
} else {
    console.info("FinishCommonEvent");
}
E
ester.zhou 已提交
1199 1200 1201 1202
}
subscriber.finishCommonEvent(finishCommonEventCallback);
```

E
ester.zhou 已提交
1203
### finishCommonEvent<sup>9+</sup>
E
ester.zhou 已提交
1204 1205 1206

finishCommonEvent(): Promise\<void\>

E
ester.zhou 已提交
1207
Finishes this ordered common event. This API uses a promise to return the result.
E
ester.zhou 已提交
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221

**System capability**: SystemCapability.Notification.CommonEvent

**Return value**

| Type            | Description                |
| ---------------- | -------------------- |
| Promise\<void>   | Promise used to return the result.|

**Example**

```js
var subscriber;	// Subscriber object successfully created.

E
ester.zhou 已提交
1222 1223 1224 1225 1226
subscriber.finishCommonEvent().then(() => {
    console.info("FinishCommonEvent");
}).catch((err) => {
    console.error("finishCommonEvent failed " + JSON.stringify(err));
});
E
ester.zhou 已提交
1227 1228 1229 1230 1231 1232
```

## CommonEventData

**System capability**: SystemCapability.Notification.CommonEvent

E
ester.zhou 已提交
1233 1234 1235 1236 1237 1238 1239
| Name      | Readable| Writable| Type                | Description                                                   |
| ---------- | ---- | ---- | -------------------- | ------------------------------------------------------- |
| event      | Yes | No | string               | Name of the common event that is being received.                             |
| bundleName | Yes | No | string               | Bundle name.                                             |
| code       | Yes | No | number               | Result code of the common event, which is used to transfer data of the int type.          |
| data       | Yes | No | string               | Custom result data of the common event, which is used to transfer data of the string type.|
| parameters | Yes | No | {[key: string]: any} | Additional information about the common event.                                 |
E
ester.zhou 已提交
1240 1241 1242 1243 1244 1245


## CommonEventPublishData

**System capability**: SystemCapability.Notification.CommonEvent

E
ester.zhou 已提交
1246 1247 1248 1249 1250 1251 1252 1253 1254
| Name                 | Readable| Writable| Type                | Description                        |
| --------------------- | ---- | ---- | -------------------- | ---------------------------- |
| bundleName            | Yes | No | string               | Bundle name.                  |
| code                  | Yes | No | number               | Result code of the common event.      |
| data                  | Yes | No | string               | Custom result data of the common event.|
| subscriberPermissions | Yes | No | Array\<string>       | Permissions required for subscribers to receive the common event.            |
| isOrdered             | Yes | No | boolean              | Whether the common event is an ordered one.          |
| isSticky              | Yes | No | boolean              | Whether the common event is a sticky one.          |
| parameters            | Yes | No | {[key: string]: any} | Additional information about the common event.      |
E
ester.zhou 已提交
1255 1256 1257 1258 1259

## CommonEventSubscribeInfo

**System capability**: SystemCapability.Notification.CommonEvent

E
ester.zhou 已提交
1260 1261 1262 1263 1264 1265 1266
| Name               | Readable| Writable| Type          | Description                                                        |
| ------------------- | ---- | ---- | -------------- | ------------------------------------------------------------ |
| 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.                    |