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

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

## Required Permissions

E
ester.zhou 已提交
8
| Common Event Macro     | Common Event Name         | Subscriber Permissions    |
W
wusongqing 已提交
9
| ------------ | ------------------ | ---------------------- |
W
wusongqing 已提交
10
| COMMON_EVENT_BOOT_COMPLETED                                  | usual.event.BOOT_COMPLETED                                  | ohos.permission.RECEIVER_STARTUP_COMPLETED                   |
E
esterzhou 已提交
11
| COMMON_EVENT_LOCKED_BOOT_COMPLETED                           | usual.event.LOCKED_BOOT_COMPLETED                           | ohos.permission.RECEIVER_STARTUP_COMPLETED                   |
E
ester.zhou 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| COMMON_EVENT_SHUTDOWN                                        | usual.event.SHUTDOWN                                        | -                                                          |
| COMMON_EVENT_BATTERY_CHANGED                                 | usual.event.BATTERY_CHANGED                                 | -                                                          |
| COMMON_EVENT_BATTERY_LOW                                     | usual.event.BATTERY_LOW                                     | -                                                          |
| COMMON_EVENT_BATTERY_OKAY                                    | usual.event.BATTERY_OKAY                                    | -                                                          |
| COMMON_EVENT_POWER_CONNECTED                                 | usual.event.POWER_CONNECTED                                 | -                                                          |
| COMMON_EVENT_POWER_DISCONNECTED                              | usual.event.POWER_DISCONNECTED                              | -                                                          |
| COMMON_EVENT_SCREEN_OFF                                      | usual.event.SCREEN_OFF                                      | -                                                          |
| COMMON_EVENT_SCREEN_ON                                       | usual.event.SCREEN_ON                                       | -                                                          |
| COMMON_EVENT_THERMAL_LEVEL_CHANGED                           | usual.event.THERMAL_LEVEL_CHANGED                           | -                                                          |
| COMMON_EVENT_USER_PRESENT                                    | usual.event.USER_PRESENT                                    | -                                                          |
| COMMON_EVENT_TIME_TICK                                       | usual.event.TIME_TICK                                       | -                                                          |
| COMMON_EVENT_TIME_CHANGED                                    | usual.event.TIME_CHANGED                                    | -                                                          |
| COMMON_EVENT_DATE_CHANGED                                    | usual.event.DATE_CHANGED                                    | -                                                          |
| COMMON_EVENT_TIMEZONE_CHANGED                                | usual.event.TIMEZONE_CHANGED                                | -                                                          |
| COMMON_EVENT_CLOSE_SYSTEM_DIALOGS                            | usual.event.CLOSE_SYSTEM_DIALOGS                            | -                                                          |
| COMMON_EVENT_PACKAGE_ADDED                                   | usual.event.PACKAGE_ADDED                                   | -                                                          |
| COMMON_EVENT_PACKAGE_REPLACED                                | usual.event.PACKAGE_REPLACED                                | -                                                          |
| COMMON_EVENT_MY_PACKAGE_REPLACED                             | usual.event.MY_PACKAGE_REPLACED                             | -                                                          |
| COMMON_EVENT_PACKAGE_REMOVED                                 | usual.event.PACKAGE_REMOVED                                 | -                                                          |
| COMMON_EVENT_BUNDLE_REMOVED                                  | usual.event.BUNDLE_REMOVED                                  | -                                                          |
| COMMON_EVENT_PACKAGE_FULLY_REMOVED                           | usual.event.PACKAGE_FULLY_REMOVED                           | -                                                          |
| COMMON_EVENT_PACKAGE_CHANGED                                 | usual.event.PACKAGE_CHANGED                                 | -                                                          |
| COMMON_EVENT_PACKAGE_RESTARTED                               | usual.event.PACKAGE_RESTARTED                               | -                                                          |
| COMMON_EVENT_PACKAGE_DATA_CLEARED                            | usual.event.PACKAGE_DATA_CLEARED                            | -                                                          |
| COMMON_EVENT_PACKAGES_SUSPENDED                              | usual.event.PACKAGES_SUSPENDED                              | -                                                          |
| COMMON_EVENT_PACKAGES_UNSUSPENDED                            | usual.event.PACKAGES_UNSUSPENDED                            | -                                                          |
| COMMON_EVENT_MY_PACKAGE_SUSPENDED                            | usual.event.MY_PACKAGE_SUSPENDED                            | -                                                          |
| COMMON_EVENT_MY_PACKAGE_UNSUSPENDED                          | usual.event.MY_PACKAGE_UNSUSPENDED                          | -                                                          |
| COMMON_EVENT_UID_REMOVED                                     | usual.event.UID_REMOVED                                     | -                                                          |
| COMMON_EVENT_PACKAGE_FIRST_LAUNCH                            | usual.event.PACKAGE_FIRST_LAUNCH                            | -                                                          |
| COMMON_EVENT_PACKAGE_NEEDS_VERIFICATION                      | usual.event.PACKAGE_NEEDS_VERIFICATION                      | -                                                          |
| COMMON_EVENT_PACKAGE_VERIFIED                                | usual.event.PACKAGE_VERIFIED                                | -                                                          |
| COMMON_EVENT_EXTERNAL_APPLICATIONS_AVAILABLE                 | usual.event.EXTERNAL_APPLICATIONS_AVAILABLE                 | -                                                          |
| COMMON_EVENT_EXTERNAL_APPLICATIONS_UNAVAILABLE               | usual.event.EXTERNAL_APPLICATIONS_UNAVAILABLE               | -                                                          |
| COMMON_EVENT_CONFIGURATION_CHANGED                           | usual.event.CONFIGURATION_CHANGED                           | -                                                          |
| COMMON_EVENT_LOCALE_CHANGED                                  | usual.event.LOCALE_CHANGED                                  | -                                                          |
| COMMON_EVENT_MANAGE_PACKAGE_STORAGE                          | usual.event.MANAGE_PACKAGE_STORAGE                          | -                                                          |
| COMMON_EVENT_DRIVE_MODE                                      | common.event.DRIVE_MODE                                     | -                                                          |
| COMMON_EVENT_HOME_MODE                                       | common.event.HOME_MODE                                      | -                                                          |
| COMMON_EVENT_OFFICE_MODE                                     | common.event.OFFICE_MODE                                    | -                                                          |
| COMMON_EVENT_USER_STARTED                                    | usual.event.USER_STARTED                                    | -                                                          |
| COMMON_EVENT_USER_BACKGROUND                                 | usual.event.USER_BACKGROUND                                 | -                                                          |
| COMMON_EVENT_USER_FOREGROUND                                 | usual.event.USER_FOREGROUND                                 | -                                                          |
W
wusongqing 已提交
55
| COMMON_EVENT_USER_SWITCHED                                   | usual.event.USER_SWITCHED                                   | ohos.permission.MANAGE_USERS                                 |
E
esterzhou 已提交
56
| COMMON_EVENT_USER_STARTING                                   | usual.event.USER_STARTING                                   | ohos.permission.INTERACT_ACROSS_USERS                        |
E
ester.zhou 已提交
57
| COMMON_EVENT_USER_UNLOCKED                                   | usual.event.USER_UNLOCKED                                   | -                                                          |
E
esterzhou 已提交
58
| COMMON_EVENT_USER_STOPPING                                   | usual.event.USER_STOPPING                                   | ohos.permission.INTERACT_ACROSS_USERS                        |
E
ester.zhou 已提交
59 60 61 62 63 64
| COMMON_EVENT_USER_STOPPED                                    | usual.event.USER_STOPPED                                    | -                                                          |
| COMMON_EVENT_HWID_LOGIN                                      | common.event.HWID_LOGIN                                     | -                                                          |
| COMMON_EVENT_HWID_LOGOUT                                     | common.event.HWID_LOGOUT                                    | -                                                          |
| COMMON_EVENT_HWID_TOKEN_INVALID                              | common.event.HWID_TOKEN_INVALID                             | -                                                          |
| COMMON_EVENT_HWID_LOGOFF                                     | common.event.HWID_LOGOFF                                    | -                                                          |
| COMMON_EVENT_WIFI_POWER_STATE                                | usual.event.wifi.POWER_STATE                                | -                                                          |
W
wusongqing 已提交
65 66
| COMMON_EVENT_WIFI_SCAN_FINISHED                              | usual.event.wifi.SCAN_FINISHED                              | ohos.permission.LOCATION                                     |
| COMMON_EVENT_WIFI_RSSI_VALUE                                 | usual.event.wifi.RSSI_VALUE                                 | ohos.permission.GET_WIFI_INFO                                |
E
ester.zhou 已提交
67 68
| COMMON_EVENT_WIFI_CONN_STATE                                 | usual.event.wifi.CONN_STATE                                 | -                                                          |
| COMMON_EVENT_WIFI_HOTSPOT_STATE                              | usual.event.wifi.HOTSPOT_STATE                              | -                                                          |
W
wusongqing 已提交
69 70
| COMMON_EVENT_WIFI_AP_STA_JOIN                                | usual.event.wifi.WIFI_HS_STA_JOIN                           | ohos.permission.GET_WIFI_INFO                                |
| COMMON_EVENT_WIFI_AP_STA_LEAVE                               | usual.event.wifi.WIFI_HS_STA_LEAVE                          | ohos.permission.GET_WIFI_INFO                                |
E
esterzhou 已提交
71
| COMMON_EVENT_WIFI_MPLINK_STATE_CHANGE                        | usual.event.wifi.mplink.STATE_CHANGE                        | ohos.permission.MPLINK_CHANGE_STATE                          |
W
wusongqing 已提交
72 73 74 75 76 77
| COMMON_EVENT_WIFI_P2P_CONN_STATE                             | usual.event.wifi.p2p.CONN_STATE_CHANGE                      | ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION   |
| COMMON_EVENT_WIFI_P2P_STATE_CHANGED                          | usual.event.wifi.p2p.STATE_CHANGE                           | ohos.permission.GET_WIFI_INFO                                |
| COMMON_EVENT_WIFI_P2P_PEERS_STATE_CHANGED                    | usual.event.wifi.p2p.DEVICES_CHANGE                         | ohos.permission.GET_WIFI_INFO                                |
| COMMON_EVENT_WIFI_P2P_PEERS_DISCOVERY_STATE_CHANGED          | usual.event.wifi.p2p.PEER_DISCOVERY_STATE_CHANGE            | ohos.permission.GET_WIFI_INFO                                |
| COMMON_EVENT_WIFI_P2P_CURRENT_DEVICE_STATE_CHANGED           | usual.event.wifi.p2p.CURRENT_DEVICE_CHANGE                  | ohos.permission.GET_WIFI_INFO                                |
| COMMON_EVENT_WIFI_P2P_GROUP_STATE_CHANGED                    | usual.event.wifi.p2p.GROUP_STATE_CHANGED                    | ohos.permission.GET_WIFI_INFO                                |
E
esterzhou 已提交
78 79 80 81 82 83
| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_UPDATE     | usual.event.bluetooth.handsfree.ag.CONNECT_STATE_UPDATE     | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CURRENT_DEVICE_UPDATE    | usual.event.bluetooth.handsfree.ag.CURRENT_DEVICE_UPDATE    | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_AUDIO_STATE_UPDATE       | usual.event.bluetooth.handsfree.ag.AUDIO_STATE_UPDATE       | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_UPDATE       | usual.event.bluetooth.a2dpsource.CONNECT_STATE_UPDATE       | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CURRENT_DEVICE_UPDATE      | usual.event.bluetooth.a2dpsource.CURRENT_DEVICE_UPDATE      | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_PLAYING_STATE_UPDATE       | usual.event.bluetooth.a2dpsource.PLAYING_STATE_UPDATE       | ohos.permission.USE_BLUETOOTH                                |
W
wusongqing 已提交
84
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsource.AVRCP_CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH                                |
E
esterzhou 已提交
85
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_UPDATE         | usual.event.bluetooth.a2dpsource.CODEC_VALUE_UPDATE         | ohos.permission.USE_BLUETOOTH                                |
E
ester.zhou 已提交
86
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_DISCOVERED               | usual.event.bluetooth.remotedevice.DISCOVERED               | ohos.permission.LOCATION and ohos.permission.USE_BLUETOOTH   |
E
esterzhou 已提交
87 88 89 90 91 92
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CLASS_VALUE_UPDATE       | usual.event.bluetooth.remotedevice.CLASS_VALUE_UPDATE       | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_CONNECTED            | usual.event.bluetooth.remotedevice.ACL_CONNECTED            | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_DISCONNECTED         | usual.event.bluetooth.remotedevice.ACL_DISCONNECTED         | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_NAME_UPDATE              | usual.event.bluetooth.remotedevice.NAME_UPDATE              | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE               | usual.event.bluetooth.remotedevice.PAIR_STATE               | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_BATTERY_VALUE_UPDATE     | usual.event.bluetooth.remotedevice.BATTERY_VALUE_UPDATE     | ohos.permission.USE_BLUETOOTH                                |
E
ester.zhou 已提交
93
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_SDP_RESULT               | usual.event.bluetooth.remotedevice.SDP_RESULT               | -                                                          |
E
esterzhou 已提交
94 95
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_UUID_VALUE               | usual.event.bluetooth.remotedevice.UUID_VALUE               | ohos.permission.DISCOVER_BLUETOOTH                           |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_REQ              | usual.event.bluetooth.remotedevice.PAIRING_REQ              | ohos.permission.DISCOVER_BLUETOOTH                           |
E
ester.zhou 已提交
96 97 98 99 100 101 102 103
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_CANCEL           | usual.event.bluetooth.remotedevice.PAIRING_CANCEL           | -                                                          |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REQ              | usual.event.bluetooth.remotedevice.CONNECT_REQ              | -                                                          |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REPLY            | usual.event.bluetooth.remotedevice.CONNECT_REPLY            | -                                                          |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_CANCEL           | usual.event.bluetooth.remotedevice.CONNECT_CANCEL           | -                                                          |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_CONNECT_STATE_UPDATE    | usual.event.bluetooth.handsfreeunit.CONNECT_STATE_UPDATE    | -                                                          |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AUDIO_STATE_UPDATE      | usual.event.bluetooth.handsfreeunit.AUDIO_STATE_UPDATE      | -                                                          |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_COMMON_EVENT         | usual.event.bluetooth.handsfreeunit.AG_COMMON_EVENT         | -                                                          |
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_CALL_STATE_UPDATE    | usual.event.bluetooth.handsfreeunit.AG_CALL_STATE_UPDATE    | -                                                          |
E
esterzhou 已提交
104
| COMMON_EVENT_BLUETOOTH_HOST_STATE_UPDATE                     | usual.event.bluetooth.host.STATE_UPDATE                     | ohos.permission.USE_BLUETOOTH                                |
E
ester.zhou 已提交
105
| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISCOVERABLE                 | usual.event.bluetooth.host.REQ_DISCOVERABLE                 | -                                                          |
E
esterzhou 已提交
106 107 108 109 110 111 112 113 114
| COMMON_EVENT_BLUETOOTH_HOST_REQ_ENABLE                       | usual.event.bluetooth.host.REQ_ENABLE                       | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISABLE                      | usual.event.bluetooth.host.REQ_DISABLE                      | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_HOST_SCAN_MODE_UPDATE                 | usual.event.bluetooth.host.SCAN_MODE_UPDATE                 | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_STARTED                | usual.event.bluetooth.host.DISCOVERY_STARTED                | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_FINISHED               | usual.event.bluetooth.host.DISCOVERY_FINISHED               | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_HOST_NAME_UPDATE                      | usual.event.bluetooth.host.NAME_UPDATE                      | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_A2DPSINK_CONNECT_STATE_UPDATE         | usual.event.bluetooth.a2dpsink.CONNECT_STATE_UPDATE         | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_A2DPSINK_PLAYING_STATE_UPDATE         | usual.event.bluetooth.a2dpsink.PLAYING_STATE_UPDATE         | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_A2DPSINK_AUDIO_STATE_UPDATE           | usual.event.bluetooth.a2dpsink.AUDIO_STATE_UPDATE           | ohos.permission.USE_BLUETOOTH                                |
E
ester.zhou 已提交
115
| COMMON_EVENT_NFC_ACTION_ADAPTER_STATE_CHANGED                | usual.event.nfc.action.ADAPTER_STATE_CHANGED                | -                                                          |
E
esterzhou 已提交
116 117
| COMMON_EVENT_NFC_ACTION_RF_FIELD_ON_DETECTED                 | usual.event.nfc.action.RF_FIELD_ON_DETECTED                 | ohos.permission.MANAGE_SECURE_SETTINGS                       |
| COMMON_EVENT_NFC_ACTION_RF_FIELD_OFF_DETECTED                | usual.event.nfc.action.RF_FIELD_OFF_DETECTED                | ohos.permission.MANAGE_SECURE_SETTINGS                       |
E
ester.zhou 已提交
118 119 120 121
| COMMON_EVENT_DISCHARGING                                     | usual.event.DISCHARGING                                     | -                                                          |
| COMMON_EVENT_CHARGING                                        | usual.event.CHARGING                                        | -                                                          |
| COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED                        | usual.event.DEVICE_IDLE_MODE_CHANGED                        | -                                                          |
| COMMON_EVENT_POWER_SAVE_MODE_CHANGED                         | usual.event.POWER_SAVE_MODE_CHANGED                         | -                                                          |
W
wusongqing 已提交
122 123
| COMMON_EVENT_USER_ADDED                                      | usual.event.USER_ADDED                                      | ohos.permission.MANAGE_USERS                                 |
| COMMON_EVENT_USER_REMOVED                                    | usual.event.USER_REMOVED                                    | ohos.permission.MANAGE_USERS                                 |
E
esterzhou 已提交
124 125 126
| COMMON_EVENT_ABILITY_ADDED                                   | usual.event.ABILITY_ADDED                                   | ohos.permission.LISTEN_BUNDLE_CHANGE                         |
| COMMON_EVENT_ABILITY_REMOVED                                 | usual.event.ABILITY_REMOVED                                 | ohos.permission.LISTEN_BUNDLE_CHANGE                         |
| COMMON_EVENT_ABILITY_UPDATED                                 | usual.event.ABILITY_UPDATED                                 | ohos.permission.LISTEN_BUNDLE_CHANGE                         |
E
ester.zhou 已提交
127 128 129 130 131 132 133 134 135 136 137 138
| COMMON_EVENT_LOCATION_MODE_STATE_CHANGED                     | usual.event.location.MODE_STATE_CHANGED                     | -                                                          |
| COMMON_EVENT_IVI_SLEEP                                       | common.event.IVI_SLEEP                                      | -                                                          |
| COMMON_EVENT_IVI_PAUSE                                       | common.event.IVI_PAUSE                                      | -                                                          |
| COMMON_EVENT_IVI_STANDBY                                     | common.event.IVI_STANDBY                                    | -                                                          |
| COMMON_EVENT_IVI_LASTMODE_SAVE                               | common.event.IVI_LASTMODE_SAVE                              | -                                                          |
| COMMON_EVENT_IVI_VOLTAGE_ABNORMAL                            | common.event.IVI_VOLTAGE_ABNORMAL                           | -                                                          |
| COMMON_EVENT_IVI_HIGH_TEMPERATURE                            | common.event.IVI_HIGH_TEMPERATURE                           | -                                                          |
| COMMON_EVENT_IVI_EXTREME_TEMPERATURE                         | common.event.IVI_EXTREME_TEMPERATURE                        | -                                                          |
| COMMON_EVENT_IVI_TEMPERATURE_ABNORMAL                        | common.event.IVI_TEMPERATURE_ABNORMAL                       | -                                                          |
| COMMON_EVENT_IVI_VOLTAGE_RECOVERY                            | common.event.IVI_VOLTAGE_RECOVERY                           | -                                                          |
| COMMON_EVENT_IVI_TEMPERATURE_RECOVERY                        | common.event.IVI_TEMPERATURE_RECOVERY                       | -                                                          |
| COMMON_EVENT_IVI_ACTIVE                                      | common.event.IVI_ACTIVE                                     | -                                                          |
139 140
|COMMON_EVENT_USB_STATE<sup>9+</sup>                           | usual.event.hardware.usb.action.USB_STATE                   | -                                                          |
|COMMON_EVENT_USB_PORT_CHANGED<sup>9+</sup>                    | usual.event.hardware.usb.action.USB_PORT_CHANGED            | -                                                          |
E
ester.zhou 已提交
141 142 143 144
| COMMON_EVENT_USB_DEVICE_ATTACHED                             | usual.event.hardware.usb.action.USB_DEVICE_ATTACHED         | -                                                          |
| COMMON_EVENT_USB_DEVICE_DETACHED                             | usual.event.hardware.usb.action.USB_DEVICE_DETACHED         | -                                                          |
| COMMON_EVENT_USB_ACCESSORY_ATTACHED                          | usual.event.hardware.usb.action.USB_ACCESSORY_ATTACHED      | -                                                          |
| COMMON_EVENT_USB_ACCESSORY_DETACHED                          | usual.event.hardware.usb.action.USB_ACCESSORY_DETACHED      | -                                                          |
W
wusongqing 已提交
145 146 147 148
| COMMON_EVENT_DISK_REMOVED                                    | usual.event.data.DISK_REMOVED                               | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_DISK_UNMOUNTED                                  | usual.event.data.DISK_UNMOUNTED                             | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_DISK_MOUNTED                                    | usual.event.data.DISK_MOUNTED                               | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_DISK_BAD_REMOVAL                                | usual.event.data.DISK_BAD_REMOVAL                           | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
E
esterzhou 已提交
149
| COMMON_EVENT_DISK_UNMOUNTABLE                                | usual.event.data.DISK_UNMOUNTABLE                           | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
W
wusongqing 已提交
150
| COMMON_EVENT_DISK_EJECT                                      | usual.event.data.DISK_EJECT                                 | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
E
esterzhou 已提交
151 152 153 154 155 156 157 158
| COMMON_EVENT_VOLUME_REMOVED                                  | usual.event.data.VOLUME_REMOVED                             | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_VOLUME_UNMOUNTED                                | usual.event.data.VOLUME_UNMOUNTED                           | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_VOLUME_MOUNTED                                  | usual.event.data.VOLUME_MOUNTED                             | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_VOLUME_BAD_REMOVAL                              | usual.event.data.VOLUME_BAD_REMOVAL                         | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_VOLUME_EJECT                                    | usual.event.data.VOLUME_EJECT                               | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
| COMMON_EVENT_VISIBLE_ACCOUNTS_UPDATED                        | usual.event.data.VISIBLE_ACCOUNTS_UPDATED                   | ohos.permission.GET_APP_ACCOUNTS                             |
| COMMON_EVENT_ACCOUNT_DELETED                                 | usual.event.data.ACCOUNT_DELETED                            | ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS               |
| COMMON_EVENT_FOUNDATION_READY                                | usual.event.data.FOUNDATION_READY                           | ohos.permission.RECEIVER_STARTUP_COMPLETED                   |
E
ester.zhou 已提交
159
| COMMON_EVENT_AIRPLANE_MODE_CHANGED                           | usual.event.AIRPLANE_MODE                                   | -                                                          |
E
esterzhou 已提交
160
| COMMON_EVENT_SPLIT_SCREEN                                    | usual.event.SPLIT_SCREEN                                    | ohos.permission.RECEIVER_SPLIT_SCREEN                        |
W
wusongqing 已提交
161 162 163 164

## Modules to Import

```js
E
ester.zhou 已提交
165
import CommonEvent from '@ohos.commonEvent';
W
wusongqing 已提交
166 167
```

W
wusongqing 已提交
168
## CommonEvent.publish
W
wusongqing 已提交
169

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

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

E
esterzhou 已提交
174
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
175

W
wusongqing 已提交
176
**Parameters**
W
wusongqing 已提交
177

E
ester.zhou 已提交
178
| Name    | Readable/Writable| Type                | Mandatory| Description                  |
W
wusongqing 已提交
179
| -------- | -------- | -------------------- | ---- | ---------------------- |
E
ester.zhou 已提交
180 181
| event    | Read only    | string               | Yes  | Name of the common event to publish.|
| callback | Read only    | AsyncCallback\<void> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
182

W
wusongqing 已提交
183
**Example**
W
wusongqing 已提交
184 185

```js
E
ester.zhou 已提交
186
// Callback for common event publication.
W
wusongqing 已提交
187
function PublishCallBack(err) {
E
ester.zhou 已提交
188 189 190 191 192
	if (err.code) {
        console.error("publish failed " + JSON.stringify(err));
    } else {
        console.info("publish");
    }
W
wusongqing 已提交
193
}
E
ester.zhou 已提交
194

W
wusongqing 已提交
195
// Publish a common event.
E
ester.zhou 已提交
196
CommonEvent.publish("event", PublishCallBack);
W
wusongqing 已提交
197 198 199 200
```



W
wusongqing 已提交
201
## CommonEvent.publish
W
wusongqing 已提交
202

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

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

E
esterzhou 已提交
207
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
208

W
wusongqing 已提交
209
**Parameters**
W
wusongqing 已提交
210

E
ester.zhou 已提交
211
| Name    | Readable/Writable| Type                  | Mandatory| Description                  |
W
wusongqing 已提交
212
| -------- | -------- | ---------------------- | ---- | ---------------------- |
E
ester.zhou 已提交
213 214 215
| event    | Read only    | string                 | Yes  | Name of the common event to publish. |
| options  | Read only    | [CommonEventPublishData](#commoneventpublishdata) | Yes  | Attributes of the common event to publish.|
| callback | Read only    | AsyncCallback\<void>   | Yes  | Callback used to return the result. |
W
wusongqing 已提交
216

W
wusongqing 已提交
217
**Example**
W
wusongqing 已提交
218 219 220 221 222


```js
// Attributes of a common event.
var options = {
E
ester.zhou 已提交
223
	code: 0,			 // Result code of the common event
E
ester.zhou 已提交
224
	data: "initial data",// Result data of the common event
E
ester.zhou 已提交
225
	isOrdered: true	 // The common event is an ordered one.
W
wusongqing 已提交
226
}
E
ester.zhou 已提交
227

W
wusongqing 已提交
228 229
// Callback for common event publication
function PublishCallBack(err) {
E
ester.zhou 已提交
230 231 232 233 234
	if (err.code) {
        console.error("publish failed " + JSON.stringify(err));
    } else {
        console.info("publish");
    }
W
wusongqing 已提交
235
}
E
ester.zhou 已提交
236

W
wusongqing 已提交
237
// Publish a common event.
E
ester.zhou 已提交
238
CommonEvent.publish("event", options, PublishCallBack);
W
wusongqing 已提交
239 240 241 242
```



E
esterzhou 已提交
243
## CommonEvent.publishAsUser<sup>8+</sup>
E
ester.zhou 已提交
244 245 246

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

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

E
esterzhou 已提交
249
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
250

E
ester.zhou 已提交
251 252
**Parameters**

E
ester.zhou 已提交
253
| Name    | Readable/Writable| Type                | Mandatory| Description                              |
E
ester.zhou 已提交
254
| -------- | -------- | -------------------- | ---- | ---------------------------------- |
E
ester.zhou 已提交
255 256 257
| event    | Read only    | string               | Yes  | Name of the common event to publish.            |
| userId   | Read only    | number               | Yes  | User ID.|
| callback | Read only    | AsyncCallback\<void> | Yes  | Callback used to return the result.            |
E
ester.zhou 已提交
258 259 260 261

**Example**

```js
E
ester.zhou 已提交
262
// Callback for common event publication.
E
ester.zhou 已提交
263 264
function PublishAsUserCallBack(err) {
	if (err.code) {
E
ester.zhou 已提交
265
        console.error("publishAsUser failed " + JSON.stringify(err));
E
ester.zhou 已提交
266 267 268 269
    } else {
        console.info("publishAsUser");
    }
}
E
ester.zhou 已提交
270

E
ester.zhou 已提交
271 272
// Specify the user to whom the common event will be published.
var userId = 100;
E
ester.zhou 已提交
273

E
ester.zhou 已提交
274
// Publish a common event.
E
ester.zhou 已提交
275
CommonEvent.publishAsUser("event", userId, PublishAsUserCallBack);
E
ester.zhou 已提交
276 277 278 279
```



E
esterzhou 已提交
280
## CommonEvent.publishAsUser<sup>8+</sup>
E
ester.zhou 已提交
281 282 283

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

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

E
esterzhou 已提交
286
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
287

E
ester.zhou 已提交
288 289
**Parameters**

E
ester.zhou 已提交
290
| Name    | Readable/Writable| Type                  | Mandatory| Description                  |
E
ester.zhou 已提交
291
| -------- | -------- | ---------------------- | ---- | ---------------------- |
E
ester.zhou 已提交
292 293 294 295
| event    | Read only    | string                 | Yes  | Name of the common event to publish. |
| userId | Read only| number | Yes| User ID.|
| options  | Read only    | [CommonEventPublishData](#commoneventpublishdata) | Yes  | Attributes of the common event to publish.|
| callback | Read only    | AsyncCallback\<void>   | Yes  | Callback used to return the result. |
E
ester.zhou 已提交
296 297 298 299 300 301 302

**Example**


```js
// Attributes of a common event.
var options = {
E
esterzhou 已提交
303
	code: 0,			 // Result code of the common event
E
ester.zhou 已提交
304
	data: "initial data",// Result data of the common event
E
ester.zhou 已提交
305
}
E
ester.zhou 已提交
306

E
ester.zhou 已提交
307 308 309
// Callback for common event publication
function PublishAsUserCallBack(err) {
	if (err.code) {
E
ester.zhou 已提交
310
        console.error("publishAsUser failed " + JSON.stringify(err));
E
ester.zhou 已提交
311 312 313 314
    } else {
        console.info("publishAsUser");
    }
}
E
ester.zhou 已提交
315

E
ester.zhou 已提交
316 317
// Specify the user to whom the common event will be published.
var userId = 100;
E
ester.zhou 已提交
318

E
ester.zhou 已提交
319
// Publish a common event.
E
ester.zhou 已提交
320
CommonEvent.publishAsUser("event", userId, options, PublishAsUserCallBack);
E
ester.zhou 已提交
321 322 323 324
```



W
wusongqing 已提交
325
## CommonEvent.createSubscriber
W
wusongqing 已提交
326

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

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

E
esterzhou 已提交
331
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
332

W
wusongqing 已提交
333
**Parameters**
W
wusongqing 已提交
334

E
ester.zhou 已提交
335
| Name         | Readable/Writable| Type                                                        | Mandatory| Description                      |
W
wusongqing 已提交
336
| ------------- | -------- | ------------------------------------------------------------ | ---- | -------------------------- |
E
ester.zhou 已提交
337 338
| subscribeInfo | Read only    | [CommonEventSubscribeInfo](#commoneventsubscribeinfo)        | Yes  | Subscriber information.            |
| callback      | Read only    | AsyncCallback\<[CommonEventSubscriber](#commoneventsubscriber)> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
339

W
wusongqing 已提交
340
**Example**
W
wusongqing 已提交
341 342 343 344


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

E
ester.zhou 已提交
346
// Subscriber information.
W
wusongqing 已提交
347 348 349
var subscribeInfo = {
	events: ["event"]
};
E
ester.zhou 已提交
350

E
ester.zhou 已提交
351
// Callback for subscriber creation.
E
ester.zhou 已提交
352 353 354 355 356 357 358
function CreateSubscriberCallBack(err, commonEventSubscriber) {
    if (err.code) {
        console.error("createSubscriber failed " + JSON.stringify(err));
    } else {
        console.info("createSubscriber");
        subscriber = commonEventSubscriber;
    }
W
wusongqing 已提交
359
}
E
ester.zhou 已提交
360

W
wusongqing 已提交
361 362 363 364 365 366
// Create a subscriber.
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack);
```



W
wusongqing 已提交
367
## CommonEvent.createSubscriber
W
wusongqing 已提交
368

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

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

E
esterzhou 已提交
373
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
374

W
wusongqing 已提交
375
**Parameters**
W
wusongqing 已提交
376

E
ester.zhou 已提交
377
| Name         | Readable/Writable| Type                                                 | Mandatory| Description          |
W
wusongqing 已提交
378
| ------------- | -------- | ----------------------------------------------------- | ---- | -------------- |
E
ester.zhou 已提交
379
| subscribeInfo | Read only    | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | Yes  | Subscriber information.|
W
wusongqing 已提交
380

W
wusongqing 已提交
381
**Return value**
E
ester.zhou 已提交
382
| Type                                                     | Description            |
W
wusongqing 已提交
383
| --------------------------------------------------------- | ---------------- |
W
wusongqing 已提交
384
| Promise\<[CommonEventSubscriber](#commoneventsubscriber)> | Promise used to return the subscriber object.|
W
wusongqing 已提交
385

W
wusongqing 已提交
386
**Example**
W
wusongqing 已提交
387 388 389

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

E
ester.zhou 已提交
391
// Subscriber information.
W
wusongqing 已提交
392 393 394
var subscribeInfo = {
	events: ["event"]
};
E
ester.zhou 已提交
395

W
wusongqing 已提交
396
// Create a subscriber.
E
ester.zhou 已提交
397 398 399 400 401
CommonEvent.createSubscriber(subscribeInfo).then((commonEventSubscriber) => {
    console.info("createSubscriber");
    subscriber = commonEventSubscriber;
}).catch((err) => {
    console.error("createSubscriber failed " + JSON.stringify(err));
W
wusongqing 已提交
402 403 404 405 406
});
```



W
wusongqing 已提交
407
## CommonEvent.subscribe
W
wusongqing 已提交
408

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

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

E
esterzhou 已提交
413
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
414

W
wusongqing 已提交
415
**Parameters**
W
wusongqing 已提交
416

E
ester.zhou 已提交
417
| Name      | Readable/Writable| Type                                               | Mandatory| Description                            |
W
wusongqing 已提交
418
| ---------- | -------- | --------------------------------------------------- | ---- | -------------------------------- |
E
ester.zhou 已提交
419 420
| subscriber | Read only    | [CommonEventSubscriber](#commoneventsubscriber)     | Yes  | Subscriber object.                |
| callback   | Read only    | AsyncCallback\<[CommonEventData](#commoneventdata)> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
421

W
wusongqing 已提交
422
**Example**
W
wusongqing 已提交
423 424 425

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

E
ester.zhou 已提交
427
// Subscriber information.
W
wusongqing 已提交
428 429 430 431
var subscribeInfo = {
    events: ["event"]
};

E
ester.zhou 已提交
432
// Callback for common event subscription.
W
wusongqing 已提交
433
function SubscribeCallBack(err, data) {
E
ester.zhou 已提交
434 435 436 437 438
    if (err.code) {
        console.error("subscribe failed " + JSON.stringify(err));
    } else {
        console.info("subscribe " + JSON.stringify(data));
    }
W
wusongqing 已提交
439 440
}

E
ester.zhou 已提交
441
// Callback for subscriber creation.
E
ester.zhou 已提交
442 443 444 445 446 447 448 449 450
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 已提交
451 452 453 454 455 456
}

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

E
ester.zhou 已提交
457

W
wusongqing 已提交
458

W
wusongqing 已提交
459
## CommonEvent.unsubscribe
W
wusongqing 已提交
460

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

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

E
esterzhou 已提交
465
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
466

W
wusongqing 已提交
467
**Parameters**
W
wusongqing 已提交
468

E
ester.zhou 已提交
469 470 471 472
| Name      | Readable/Writable| Type                                            | Mandatory| Description                    |
| ---------- | -------- | ----------------------------------------------- | ---- | ------------------------ |
| subscriber | Read only    | [CommonEventSubscriber](#commoneventsubscriber) | Yes  | Subscriber object.        |
| callback   | Read only    | AsyncCallback\<void>                            | No  | Callback used to return the result.|
W
wusongqing 已提交
473

W
wusongqing 已提交
474
**Example**
W
wusongqing 已提交
475 476 477

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

E
ester.zhou 已提交
479
// Subscriber information.
W
wusongqing 已提交
480 481 482
var subscribeInfo = {
	events: ["event"]
};
E
ester.zhou 已提交
483

E
ester.zhou 已提交
484
// Callback for common event subscription.
W
wusongqing 已提交
485
function SubscribeCallBack(err, data) {
E
ester.zhou 已提交
486 487 488 489 490
    if (err.code) {
        console.info("subscribe failed " + JSON.stringify(err));
    } else {
        console.info("subscribe " + JSON.stringify(data));
    }
W
wusongqing 已提交
491
}
E
ester.zhou 已提交
492

E
ester.zhou 已提交
493
// Callback for subscriber creation.
E
ester.zhou 已提交
494 495 496 497 498 499 500 501 502
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 已提交
503
}
E
ester.zhou 已提交
504

E
ester.zhou 已提交
505
// Callback for common event unsubscription.
W
wusongqing 已提交
506
function UnsubscribeCallBack(err) {
E
ester.zhou 已提交
507 508 509 510 511
	if (err.code) {
        console.info("unsubscribe failed " + JSON.stringify(err));
    } else {
        console.info("unsubscribe");
    }
W
wusongqing 已提交
512
}
E
ester.zhou 已提交
513

W
wusongqing 已提交
514 515
// Create a subscriber.
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack);
E
ester.zhou 已提交
516

W
wusongqing 已提交
517 518 519 520
// Unsubscribe from the common event.
CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack);
```

W
wusongqing 已提交
521
## CommonEventSubscriber
W
wusongqing 已提交
522

W
wusongqing 已提交
523
### getCode
W
wusongqing 已提交
524

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

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

E
esterzhou 已提交
529
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
530

W
wusongqing 已提交
531
**Parameters**
W
wusongqing 已提交
532

E
ester.zhou 已提交
533
| Name  | Type                  | Mandatory| Description              |
W
wusongqing 已提交
534
| -------- | ---------------------- | ---- | ------------------ |
E
ester.zhou 已提交
535
| callback | AsyncCallback\<number> | Yes  | Callback used to return the result code.|
W
wusongqing 已提交
536

W
wusongqing 已提交
537
**Example**
W
wusongqing 已提交
538

W
wusongqing 已提交
539
```js
E
esterzhou 已提交
540
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
541

E
ester.zhou 已提交
542
// Callback for result code obtaining of an ordered common event.
E
ester.zhou 已提交
543 544 545 546 547 548
function getCodeCallback(err, Code) {
    if (err.code) {
        console.error("getCode failed " + JSON.stringify(err));
    } else {
        console.info("getCode " + JSON.stringify(Code));
    }
W
wusongqing 已提交
549 550 551
}
subscriber.getCode(getCodeCallback);
```
W
wusongqing 已提交
552

W
wusongqing 已提交
553
### getCode
W
wusongqing 已提交
554

W
wusongqing 已提交
555
getCode(): Promise\<number>
W
wusongqing 已提交
556

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

E
esterzhou 已提交
559
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
560

W
wusongqing 已提交
561
**Return value**
W
wusongqing 已提交
562

E
ester.zhou 已提交
563
| Type            | Description                |
W
wusongqing 已提交
564
| ---------------- | -------------------- |
W
wusongqing 已提交
565
| Promise\<number> | Promise used to return the result code.|
W
wusongqing 已提交
566

W
wusongqing 已提交
567
**Example**
W
wusongqing 已提交
568

W
wusongqing 已提交
569
```js
E
esterzhou 已提交
570
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
571 572 573 574 575

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

W
wusongqing 已提交
579
### setCode
W
wusongqing 已提交
580

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

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

E
esterzhou 已提交
585
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
586

W
wusongqing 已提交
587
**Parameters**
W
wusongqing 已提交
588

E
ester.zhou 已提交
589
| Name  | Type                | Mandatory| Description                  |
W
wusongqing 已提交
590
| -------- | -------------------- | ---- | ---------------------- |
E
ester.zhou 已提交
591 592
| code     | number               | Yes  | Result code of the common event.  |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
593

W
wusongqing 已提交
594
**Example**
W
wusongqing 已提交
595

W
wusongqing 已提交
596
```js
E
esterzhou 已提交
597
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
598

E
ester.zhou 已提交
599
// Callback for result code setting of an ordered common event.
W
wusongqing 已提交
600
function setCodeCallback(err) {
E
ester.zhou 已提交
601 602 603 604 605
    if (err.code) {
        console.error("setCode failed " + JSON.stringify(err));
    } else {
        console.info("setCode");
    }
W
wusongqing 已提交
606 607 608
}
subscriber.setCode(1, setCodeCallback);
```
W
wusongqing 已提交
609

W
wusongqing 已提交
610
### setCode
W
wusongqing 已提交
611

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

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

E
esterzhou 已提交
616
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
617

W
wusongqing 已提交
618
**Parameters**
W
wusongqing 已提交
619

E
ester.zhou 已提交
620
| Name| Type  | Mandatory| Description              |
W
wusongqing 已提交
621
| ------ | ------ | ---- | ------------------ |
E
ester.zhou 已提交
622 623 624 625 626 627 628
| code   | number | Yes  | Result code of the common event.|

**Return value**

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

W
wusongqing 已提交
630
**Example**
W
wusongqing 已提交
631

W
wusongqing 已提交
632
```js
E
esterzhou 已提交
633
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
634

W
wusongqing 已提交
635
subscriber.setCode(1).then(() => {
E
ester.zhou 已提交
636 637 638
    console.info("setCode");
}).catch((err) => {
    console.error("setCode failed " + JSON.stringify(err));
W
wusongqing 已提交
639 640
});
```
W
wusongqing 已提交
641

W
wusongqing 已提交
642
### getData
W
wusongqing 已提交
643

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

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

E
esterzhou 已提交
648
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
649

W
wusongqing 已提交
650
**Parameters**
W
wusongqing 已提交
651

E
ester.zhou 已提交
652
| Name  | Type                  | Mandatory| Description                |
W
wusongqing 已提交
653
| -------- | ---------------------- | ---- | -------------------- |
E
ester.zhou 已提交
654
| callback | AsyncCallback\<string> | Yes  | Result data of the common event.|
W
wusongqing 已提交
655

W
wusongqing 已提交
656
**Example**
W
wusongqing 已提交
657

W
wusongqing 已提交
658
```js
E
esterzhou 已提交
659
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
660

E
ester.zhou 已提交
661
// Callback for result data obtaining of an ordered common event.
E
ester.zhou 已提交
662 663 664 665 666 667
function getDataCallback(err, Data) {
    if (err.code) {
        console.error("getData failed " + JSON.stringify(err));
    } else {
        console.info("getData " + JSON.stringify(Data));
    }
W
wusongqing 已提交
668 669 670
}
subscriber.getData(getDataCallback);
```
W
wusongqing 已提交
671

W
wusongqing 已提交
672
### getData
W
wusongqing 已提交
673

W
wusongqing 已提交
674
getData(): Promise\<string>
W
wusongqing 已提交
675

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

E
esterzhou 已提交
678
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
679

W
wusongqing 已提交
680
**Return value**
W
wusongqing 已提交
681

E
ester.zhou 已提交
682
| Type            | Description              |
W
wusongqing 已提交
683
| ---------------- | ------------------ |
E
ester.zhou 已提交
684
| Promise\<string> | Result data of the common event.|
W
wusongqing 已提交
685

W
wusongqing 已提交
686
**Example**
W
wusongqing 已提交
687

W
wusongqing 已提交
688
```js
E
esterzhou 已提交
689
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
690 691 692 693 694

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

W
wusongqing 已提交
698
### setData
W
wusongqing 已提交
699

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

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

E
esterzhou 已提交
704
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
705

W
wusongqing 已提交
706
**Parameters**
W
wusongqing 已提交
707

E
ester.zhou 已提交
708
| Name  | Type                | Mandatory| Description                |
W
wusongqing 已提交
709
| -------- | -------------------- | ---- | -------------------- |
E
ester.zhou 已提交
710 711
| data     | string               | Yes  | Result data of the common event.  |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
712

W
wusongqing 已提交
713
**Example**
W
wusongqing 已提交
714

W
wusongqing 已提交
715
```js
E
esterzhou 已提交
716
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
717

W
wusongqing 已提交
718 719
// Callback for result data setting of an ordered common event
function setDataCallback(err) {
E
ester.zhou 已提交
720 721 722 723 724
    if (err.code) {
        console.error("setData failed " + JSON.stringify(err));
    } else {
        console.info("setData");
    }
W
wusongqing 已提交
725 726 727
}
subscriber.setData("publish_data_changed", setDataCallback);
```
W
wusongqing 已提交
728

W
wusongqing 已提交
729
### setData
W
wusongqing 已提交
730

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

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

E
esterzhou 已提交
735
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
736

W
wusongqing 已提交
737
**Parameters**
W
wusongqing 已提交
738

E
ester.zhou 已提交
739
| Name| Type  | Mandatory| Description                |
W
wusongqing 已提交
740
| ------ | ------ | ---- | -------------------- |
E
ester.zhou 已提交
741 742 743 744 745 746
| data   | string | Yes  | Result data of the common event.|

**Return value**

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

W
wusongqing 已提交
749
**Example**
W
wusongqing 已提交
750

W
wusongqing 已提交
751
```js
E
esterzhou 已提交
752
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
753

W
wusongqing 已提交
754
subscriber.setData("publish_data_changed").then(() => {
E
ester.zhou 已提交
755 756 757
    console.info("setData");
}).catch((err) => {
    console.error("setData failed " + JSON.stringify(err));
W
wusongqing 已提交
758 759
});
```
W
wusongqing 已提交
760

W
wusongqing 已提交
761
### setCodeAndData
W
wusongqing 已提交
762

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

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

E
esterzhou 已提交
767
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
768

W
wusongqing 已提交
769
**Parameters**
W
wusongqing 已提交
770

E
ester.zhou 已提交
771
| Name  | Type                | Mandatory| Description                  |
W
wusongqing 已提交
772
| -------- | -------------------- | ---- | ---------------------- |
E
ester.zhou 已提交
773 774 775
| 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 已提交
776

W
wusongqing 已提交
777
**Example**
W
wusongqing 已提交
778

W
wusongqing 已提交
779
```js
E
esterzhou 已提交
780
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
781

E
ester.zhou 已提交
782
// Callback for result code and result data setting of an ordered common event.
W
wusongqing 已提交
783
function setCodeDataCallback(err) {
E
ester.zhou 已提交
784 785 786 787 788
    if (err.code) {
        console.error("setCodeAndData failed " + JSON.stringify(err));
    } else {
        console.info("setCodeDataCallback");
    }
W
wusongqing 已提交
789 790 791
}
subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCallback);
```
W
wusongqing 已提交
792

W
wusongqing 已提交
793
### setCodeAndData
W
wusongqing 已提交
794

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

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

E
esterzhou 已提交
799
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
800

W
wusongqing 已提交
801
**Parameters**
W
wusongqing 已提交
802

E
ester.zhou 已提交
803
| Name| Type  | Mandatory| Description                |
W
wusongqing 已提交
804
| ------ | ------ | ---- | -------------------- |
E
ester.zhou 已提交
805
| code   | number | Yes  | Result code of the common event.|
E
ester.zhou 已提交
806 807 808 809 810 811 812
| data   | string | Yes  | Result data of the common event.|

**Return value**

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

W
wusongqing 已提交
814
**Example**
W
wusongqing 已提交
815

W
wusongqing 已提交
816
```js
E
esterzhou 已提交
817
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
818

W
wusongqing 已提交
819
subscriber.setCodeAndData(1, "publish_data_changed").then(() => {
E
ester.zhou 已提交
820 821 822
    console.info("setCodeAndData");
}).catch((err) => {
    console.info("setCodeAndData failed " + JSON.stringify(err));
W
wusongqing 已提交
823 824
});
```
W
wusongqing 已提交
825

W
wusongqing 已提交
826
### isOrderedCommonEvent
W
wusongqing 已提交
827

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

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

E
esterzhou 已提交
832
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
833

W
wusongqing 已提交
834
**Parameters**
W
wusongqing 已提交
835

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

W
wusongqing 已提交
840
**Example**
W
wusongqing 已提交
841

W
wusongqing 已提交
842
```js
E
esterzhou 已提交
843
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
844

E
ester.zhou 已提交
845
// Callback for checking whether the current common event is an ordered one.
E
ester.zhou 已提交
846 847 848 849 850 851
function isOrderedCallback(err, isOrdered) {
    if (err.code) {
        console.error("isOrderedCommonEvent failed " + JSON.stringify(err));
    } else {
        console.info("isOrdered " + JSON.stringify(isOrdered));
    }
W
wusongqing 已提交
852 853 854
}
subscriber.isOrderedCommonEvent(isOrderedCallback);
```
W
wusongqing 已提交
855

W
wusongqing 已提交
856
### isOrderedCommonEvent
W
wusongqing 已提交
857

W
wusongqing 已提交
858
isOrderedCommonEvent(): Promise\<boolean>
W
wusongqing 已提交
859

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

E
esterzhou 已提交
862
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
863

W
wusongqing 已提交
864
**Return value**
W
wusongqing 已提交
865

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

W
wusongqing 已提交
870
**Example**
W
wusongqing 已提交
871

W
wusongqing 已提交
872
```js
E
esterzhou 已提交
873
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
874 875 876 877 878

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

E
ester.zhou 已提交
882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900
### 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 已提交
901
// Callback for checking whether the current common event is a sticky one.
E
ester.zhou 已提交
902 903 904 905 906 907 908 909 910 911 912 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
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 已提交
938
### abortCommonEvent
W
wusongqing 已提交
939

W
wusongqing 已提交
940
abortCommonEvent(callback: AsyncCallback\<void>): void
W
wusongqing 已提交
941

E
esterzhou 已提交
942
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 已提交
943

E
esterzhou 已提交
944
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
945

W
wusongqing 已提交
946
**Parameters**
W
wusongqing 已提交
947

E
ester.zhou 已提交
948
| Name  | Type                | Mandatory| Description                |
W
wusongqing 已提交
949
| -------- | -------------------- | ---- | -------------------- |
E
ester.zhou 已提交
950
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
951

W
wusongqing 已提交
952
**Example**
W
wusongqing 已提交
953

W
wusongqing 已提交
954
```js
E
esterzhou 已提交
955
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
956

E
ester.zhou 已提交
957
// Callback for common event aborting.
W
wusongqing 已提交
958
function abortCallback(err) {
E
ester.zhou 已提交
959 960 961 962 963
    if (err.code) {
        console.error("abortCommonEvent failed " + JSON.stringify(err));
    } else {
        console.info("abortCommonEvent");
    }
W
wusongqing 已提交
964 965 966
}
subscriber.abortCommonEvent(abortCallback);
```
W
wusongqing 已提交
967

W
wusongqing 已提交
968
### abortCommonEvent
W
wusongqing 已提交
969

W
wusongqing 已提交
970
abortCommonEvent(): Promise\<void>
W
wusongqing 已提交
971

E
esterzhou 已提交
972
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 已提交
973

E
esterzhou 已提交
974
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
975

E
ester.zhou 已提交
976 977 978 979 980 981
**Return value**

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

W
wusongqing 已提交
982
**Example**
W
wusongqing 已提交
983

W
wusongqing 已提交
984
```js
E
esterzhou 已提交
985
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
986

W
wusongqing 已提交
987
subscriber.abortCommonEvent().then(() => {
E
ester.zhou 已提交
988 989 990
    console.info("abortCommonEvent");
}).catch((err) => {
    console.error("abortCommonEvent failed " + JSON.stringify(err));
W
wusongqing 已提交
991 992
});
```
W
wusongqing 已提交
993

W
wusongqing 已提交
994
### clearAbortCommonEvent
W
wusongqing 已提交
995

W
wusongqing 已提交
996
clearAbortCommonEvent(callback: AsyncCallback\<void>): void
W
wusongqing 已提交
997

E
esterzhou 已提交
998
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 已提交
999

E
esterzhou 已提交
1000
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
1001

W
wusongqing 已提交
1002
**Parameters**
W
wusongqing 已提交
1003

E
ester.zhou 已提交
1004
| Name  | Type                | Mandatory| Description                |
W
wusongqing 已提交
1005
| -------- | -------------------- | ---- | -------------------- |
E
ester.zhou 已提交
1006
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
W
wusongqing 已提交
1007

W
wusongqing 已提交
1008
**Example**
W
wusongqing 已提交
1009

W
wusongqing 已提交
1010
```js
E
esterzhou 已提交
1011
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
1012

E
ester.zhou 已提交
1013
// Callback for clearing the aborted state of the current common event.
W
wusongqing 已提交
1014
function clearAbortCallback(err) {
E
ester.zhou 已提交
1015 1016 1017 1018 1019
    if (err.code) {
        console.error("clearAbortCommonEvent failed " + JSON.stringify(err));
    } else {
        console.info("clearAbortCommonEvent");
    }
W
wusongqing 已提交
1020 1021 1022
}
subscriber.clearAbortCommonEvent(clearAbortCallback);
```
W
wusongqing 已提交
1023

W
wusongqing 已提交
1024
### clearAbortCommonEvent
W
wusongqing 已提交
1025

W
wusongqing 已提交
1026
clearAbortCommonEvent(): Promise\<void>
W
wusongqing 已提交
1027

E
esterzhou 已提交
1028
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 已提交
1029

E
esterzhou 已提交
1030
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
1031

E
ester.zhou 已提交
1032 1033 1034 1035 1036 1037
**Return value**

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

W
wusongqing 已提交
1038
**Example**
W
wusongqing 已提交
1039

W
wusongqing 已提交
1040
```js
E
esterzhou 已提交
1041
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
1042

W
wusongqing 已提交
1043
subscriber.clearAbortCommonEvent().then(() => {
E
ester.zhou 已提交
1044 1045 1046
    console.info("clearAbortCommonEvent");
}).catch((err) => {
    console.error("clearAbortCommonEvent failed " + JSON.stringify(err));
W
wusongqing 已提交
1047 1048
});
```
W
wusongqing 已提交
1049

W
wusongqing 已提交
1050
### getAbortCommonEvent
W
wusongqing 已提交
1051

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

E
esterzhou 已提交
1054
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 已提交
1055

E
esterzhou 已提交
1056
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
1057

W
wusongqing 已提交
1058
**Parameters**
W
wusongqing 已提交
1059

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

W
wusongqing 已提交
1064
**Example**
W
wusongqing 已提交
1065

W
wusongqing 已提交
1066
```js
E
esterzhou 已提交
1067
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
1068

E
ester.zhou 已提交
1069
// Callback for checking whether the current common event is in the aborted state.
E
ester.zhou 已提交
1070 1071 1072 1073 1074 1075
function getAbortCallback(err, AbortCommonEvent) {
    if (err.code) {
        console.error("getAbortCommonEvent failed " + JSON.stringify(err));
    } else {
        console.info("AbortCommonEvent " + AbortCommonEvent)
    }
W
wusongqing 已提交
1076 1077 1078
}
subscriber.getAbortCommonEvent(getAbortCallback);
```
W
wusongqing 已提交
1079

W
wusongqing 已提交
1080
### getAbortCommonEvent
W
wusongqing 已提交
1081

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

E
esterzhou 已提交
1084
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 已提交
1085

E
esterzhou 已提交
1086
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
1087

W
wusongqing 已提交
1088
**Return value**
W
wusongqing 已提交
1089

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

W
wusongqing 已提交
1094
**Example**
W
wusongqing 已提交
1095

W
wusongqing 已提交
1096
```js
E
esterzhou 已提交
1097
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
1098 1099 1100 1101 1102

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

W
wusongqing 已提交
1106
### getSubscribeInfo
W
wusongqing 已提交
1107

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

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

E
esterzhou 已提交
1112
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
1113

W
wusongqing 已提交
1114
**Parameters**
W
wusongqing 已提交
1115

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

W
wusongqing 已提交
1120
**Example**
W
wusongqing 已提交
1121

W
wusongqing 已提交
1122
```js
E
esterzhou 已提交
1123
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
1124

E
ester.zhou 已提交
1125
// Callback for subscriber information obtaining.
E
ester.zhou 已提交
1126 1127 1128 1129 1130 1131
function getSubscribeInfoCallback(err, SubscribeInfo) {
    if (err.code) {
        console.error("getSubscribeInfo failed " + JSON.stringify(err));
    } else {
        console.info("SubscribeInfo " + JSON.stringify(SubscribeInfo));
    }
W
wusongqing 已提交
1132 1133 1134
}
subscriber.getSubscribeInfo(getSubscribeInfoCallback);
```
W
wusongqing 已提交
1135

W
wusongqing 已提交
1136
### getSubscribeInfo
W
wusongqing 已提交
1137

W
wusongqing 已提交
1138
getSubscribeInfo(): Promise\<CommonEventSubscribeInfo>
W
wusongqing 已提交
1139

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

E
esterzhou 已提交
1142
**System capability**: SystemCapability.Notification.CommonEvent
E
ester.zhou 已提交
1143

W
wusongqing 已提交
1144
**Return value**
W
wusongqing 已提交
1145

E
ester.zhou 已提交
1146
| Type                                                        | Description                  |
W
wusongqing 已提交
1147
| ------------------------------------------------------------ | ---------------------- |
W
wusongqing 已提交
1148
| Promise\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Promise used to return the subscriber information.|
W
wusongqing 已提交
1149

W
wusongqing 已提交
1150
**Example**
W
wusongqing 已提交
1151

W
wusongqing 已提交
1152
```js
E
esterzhou 已提交
1153
var subscriber;	// Subscriber object successfully created.
E
ester.zhou 已提交
1154 1155 1156 1157 1158

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

E
ester.zhou 已提交
1162
### finishCommonEvent<sup>9+</sup>
E
ester.zhou 已提交
1163 1164 1165

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

E
ester.zhou 已提交
1166
Finishes this ordered common event. This API uses a callback to return the result.
E
ester.zhou 已提交
1167 1168 1169 1170 1171 1172 1173

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

**Parameters**

| Name  | Type                 | Mandatory| Description                             |
| -------- | -------------------- | ---- | -------------------------------- |
E
ester.zhou 已提交
1174
| callback | AsyncCallback\<void> | Yes  | Callback returned after the ordered common event is finished.|
E
ester.zhou 已提交
1175 1176 1177 1178 1179 1180

**Example**

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

E
ester.zhou 已提交
1181
// Callback for ordered common event finishing.
E
ester.zhou 已提交
1182
function finishCommonEventCallback(err) {
E
ester.zhou 已提交
1183
  if (err.code) {
E
ester.zhou 已提交
1184 1185 1186 1187
    console.error("finishCommonEvent failed " + JSON.stringify(err));
} else {
    console.info("FinishCommonEvent");
}
E
ester.zhou 已提交
1188 1189 1190 1191
}
subscriber.finishCommonEvent(finishCommonEventCallback);
```

E
ester.zhou 已提交
1192
### finishCommonEvent<sup>9+</sup>
E
ester.zhou 已提交
1193 1194 1195

finishCommonEvent(): Promise\<void\>

E
ester.zhou 已提交
1196
Finishes this ordered common event. This API uses a promise to return the result.
E
ester.zhou 已提交
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210

**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 已提交
1211 1212 1213 1214 1215
subscriber.finishCommonEvent().then(() => {
    console.info("FinishCommonEvent");
}).catch((err) => {
    console.error("finishCommonEvent failed " + JSON.stringify(err));
});
E
ester.zhou 已提交
1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
```

## CommonEventData

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

| Name      | Readable/Writable| Type                | Mandatory| Description                                                   |
| ---------- | -------- | -------------------- | ---- | ------------------------------------------------------- |
| event      | Read only    | string               | Yes  | Name of the common event that is being received.                             |
| bundleName | Read only    | string               | No  | Bundle name.                                             |
| code       | Read only    | number               | No  | Result code of the common event, which is used to transfer data of the int type.          |
| data       | Read only    | string               | No  | Custom result data of the common event, which is used to transfer data of the string type.|
| parameters | Read only    | {[key: string]: any} | No  | Additional information about the common event.                                 |


## CommonEventPublishData

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

| Name                 | Readable/Writable| Type                | Mandatory| Description                        |
| --------------------- | -------- | -------------------- | ---- | ---------------------------- |
| bundleName            | Read only    | string               | No  | Bundle name.                  |
| code                  | Read only    | number               | No  | Result code of the common event.      |
| data                  | Read only    | string               | No  | Custom result data of the common event.|
| subscriberPermissions | Read only    | Array\<string>       | No  | Permissions required for subscribers to receive the common event.            |
| isOrdered             | Read only    | boolean              | No  | Whether the common event is an ordered one.          |
| isSticky              | Read only    | boolean              | No  | Whether the common event is a sticky one.          |
| parameters            | Read only    | {[key: string]: any} | No  | Additional information about the common event.      |

## CommonEventSubscribeInfo

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

| Name               | Readable/Writable| Type          | Mandatory| Description                                                        |
| ------------------- | -------- | -------------- | ---- | ------------------------------------------------------------ |
| events              | Read only    | Array\<string> | Yes  | Name of the common event to publish.                                        |
| publisherPermission | Read only    | string         | No  | Permissions required for publishers to publish the common event.                                            |
| publisherDeviceId   | Read only    | string         | No  | Device ID. The value must be the ID of an existing device on the same network.            |
| userId              | Read only    | number         | No  | User ID. The default value is the ID of the current user. If this parameter is specified, the value must be an existing user ID in the system.|
| priority            | Read only    | number         | No  | Subscriber priority. The value ranges from -100 to 1000.                    |