js-apis-commonEvent.md 39.2 KB
Newer Older
X
xuchenghua09 已提交
1 2
# 公共事件模块

Z
zengyawen 已提交
3 4
> **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
X
xuchenghua09 已提交
5

X
xuzhihao 已提交
6 7 8
## Support

权限列表。
X
xuchenghua09 已提交
9

Z
zengyawen 已提交
10 11
| 系统公共事件宏      | 系统公共事件名称          | 订阅者所需权限     |
| ------------ | ------------------ | ---------------------- |
X
xuchenghua09 已提交
12
| COMMON_EVENT_BOOT_COMPLETED                                  | usual.event.BOOT_COMPLETED                                  | ohos.permission.RECEIVER_STARTUP_COMPLETED                   |
13
| COMMON_EVENT_LOCKED_BOOT_COMPLETED                           | usual.event.LOCKED_BOOT_COMPLETED                           | ohos.permission.RECEIVER_STARTUP_COMPLETED                   |
X
xuchenghua09 已提交
14 15 16 17 18 19 20 21
| 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                                       | 无                                                           |
22
| COMMON_EVENT_THERMAL_LEVEL_CHANGED                           | usual.event.THERMAL_LEVEL_CHANGED                           | 无                                                           |
X
xuchenghua09 已提交
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 55 56
| 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_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                                 | 无                                                           |
| COMMON_EVENT_USER_SWITCHED                                   | usual.event.USER_SWITCHED                                   | ohos.permission.MANAGE_USERS                                 |
57
| COMMON_EVENT_USER_STARTING                                   | usual.event.USER_STARTING                                   | ohos.permission.INTERACT_ACROSS_USERS                        |
X
xuchenghua09 已提交
58
| COMMON_EVENT_USER_UNLOCKED                                   | usual.event.USER_UNLOCKED                                   | 无                                                           |
59
| COMMON_EVENT_USER_STOPPING                                   | usual.event.USER_STOPPING                                   | ohos.permission.INTERACT_ACROSS_USERS                        |
X
xuchenghua09 已提交
60 61 62 63 64 65 66 67 68 69 70 71
| 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                                | 无                                                           |
| 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                                |
| COMMON_EVENT_WIFI_CONN_STATE                                 | usual.event.wifi.CONN_STATE                                 | 无                                                           |
| COMMON_EVENT_WIFI_HOTSPOT_STATE                              | usual.event.wifi.HOTSPOT_STATE                              | 无                                                           |
| 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                                |
72
| COMMON_EVENT_WIFI_MPLINK_STATE_CHANGE                        | usual.event.wifi.mplink.STATE_CHANGE                        | ohos.permission.MPLINK_CHANGE_STATE                          |
X
xuchenghua09 已提交
73 74 75 76 77 78
| 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                                |
79 80 81 82 83 84
| 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                                |
X
xuchenghua09 已提交
85
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsource.AVRCP_CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH                                |
86 87 88 89 90 91 92 93
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_UPDATE         | usual.event.bluetooth.a2dpsource.CODEC_VALUE_UPDATE         | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_DISCOVERED               | usual.event.bluetooth.remotedevice.DISCOVERED               | ohos.permission.LOCATION                                     |
| 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                                |
X
xuchenghua09 已提交
94
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_SDP_RESULT               | usual.event.bluetooth.remotedevice.SDP_RESULT               | 无                                                           |
95 96
| 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                           |
X
xuchenghua09 已提交
97 98 99 100 101 102 103 104
| 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    | 无                                                           |
105
| COMMON_EVENT_BLUETOOTH_HOST_STATE_UPDATE                     | usual.event.bluetooth.host.STATE_UPDATE                     | ohos.permission.USE_BLUETOOTH                                |
X
xuchenghua09 已提交
106
| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISCOVERABLE                 | usual.event.bluetooth.host.REQ_DISCOVERABLE                 | 无                                                           |
107 108 109 110 111 112 113 114 115
| 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                                |
X
xuchenghua09 已提交
116
| COMMON_EVENT_NFC_ACTION_ADAPTER_STATE_CHANGED                | usual.event.nfc.action.ADAPTER_STATE_CHANGED                | 无                                                           |
117 118
| 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                       |
X
xuchenghua09 已提交
119 120 121 122 123 124
| 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                         | 无                                                           |
| COMMON_EVENT_USER_ADDED                                      | usual.event.USER_ADDED                                      | ohos.permission.MANAGE_USERS                                 |
| COMMON_EVENT_USER_REMOVED                                    | usual.event.USER_REMOVED                                    | ohos.permission.MANAGE_USERS                                 |
125 126 127
| 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                         |
X
xuchenghua09 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| 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                                     | 无                                                           |
| 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      | 无                                                           |
Z
zengyawen 已提交
144 145 146 147
| COMMON_EVENT_DISK_REMOVED                                    | usual.event.data.DISK_REMOVED                               | ohos.permission.WRITE_USER_STORAGE 或 ohos.permission.READ_USER_STORAGE |
| COMMON_EVENT_DISK_UNMOUNTED                                  | usual.event.data.DISK_UNMOUNTED                             | ohos.permission.WRITE_USER_STORAGE 或 ohos.permission.READ_USER_STORAGE |
| COMMON_EVENT_DISK_MOUNTED                                    | usual.event.data.DISK_MOUNTED                               | ohos.permission.WRITE_USER_STORAGE 或 ohos.permission.READ_USER_STORAGE |
| COMMON_EVENT_DISK_BAD_REMOVAL                                | usual.event.data.DISK_BAD_REMOVAL                           | ohos.permission.WRITE_USER_STORAGE 或 ohos.permission.READ_USER_STORAGE |
148
| COMMON_EVENT_DISK_UNMOUNTABLE                                | usual.event.data.DISK_UNMOUNTABLE                           | ohos.permission.WRITE_USER_STORAGE 或 ohos.permission.READ_USER_STORAGE |
Z
zengyawen 已提交
149
| COMMON_EVENT_DISK_EJECT                                      | usual.event.data.DISK_EJECT                                 | ohos.permission.WRITE_USER_STORAGE 或 ohos.permission.READ_USER_STORAGE |
150 151 152 153 154 155 156 157
| COMMON_EVENT_VOLUME_REMOVED                                  | usual.event.data.VOLUME_REMOVED                             | ohos.permission.WRITE_USER_STORAGE 或 ohos.permission.READ_USER_STORAGE |
| COMMON_EVENT_VOLUME_UNMOUNTED                                | usual.event.data.VOLUME_UNMOUNTED                           | ohos.permission.WRITE_USER_STORAGE 或 ohos.permission.READ_USER_STORAGE |
| COMMON_EVENT_VOLUME_MOUNTED                                  | usual.event.data.VOLUME_MOUNTED                             | ohos.permission.WRITE_USER_STORAGE 或 ohos.permission.READ_USER_STORAGE |
| COMMON_EVENT_VOLUME_BAD_REMOVAL                              | usual.event.data.VOLUME_BAD_REMOVAL                         | ohos.permission.WRITE_USER_STORAGE 或 ohos.permission.READ_USER_STORAGE |
| COMMON_EVENT_VOLUME_EJECT                                    | usual.event.data.VOLUME_EJECT                               | ohos.permission.WRITE_USER_STORAGE 或 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                   |
X
xuchenghua09 已提交
158
| COMMON_EVENT_AIRPLANE_MODE_CHANGED                           | usual.event.AIRPLANE_MODE                                   | 无                                                           |
159
| COMMON_EVENT_SPLIT_SCREEN                                    | usual.event.SPLIT_SCREEN                                    | ohos.permission.RECEIVER_SPLIT_SCREEN                        |
X
xuchenghua09 已提交
160 161 162 163

## 导入模块

```js
Z
zengsiyu 已提交
164
import CommonEvent from '@ohos.commonEvent';
X
xuchenghua09 已提交
165 166
```

Z
zengyawen 已提交
167
## CommonEvent.publish
X
xuchenghua09 已提交
168

Z
zengyawen 已提交
169
publish(event: string, callback: AsyncCallback\<void>): void
X
xuchenghua09 已提交
170

Z
zengyawen 已提交
171
发布公共事件(callback形式)。
X
xuchenghua09 已提交
172

Z
zengsiyu 已提交
173
**系统能力:** SystemCapability.Notification.CommonEvent
Z
zengsiyu 已提交
174

Z
zengyawen 已提交
175
**参数:**
X
xuchenghua09 已提交
176

Z
zengyawen 已提交
177 178 179 180
| 名称     | 读写属性 | 类型                 | 必填 | 描述                   |
| -------- | -------- | -------------------- | ---- | ---------------------- |
| event    | 只读     | string               | 是   | 表示要发送的公共事件。 |
| callback | 只读     | AsyncCallback\<void> | 是   | 表示被指定的回调方法。 |
X
xuchenghua09 已提交
181

Z
zengyawen 已提交
182
**示例:**
X
xuchenghua09 已提交
183 184 185 186

```js
//发布公共事件回调
function PublishCallBack(err) {
Z
zengsiyu 已提交
187 188 189 190 191
	if (err.code) {
        console.error("publish failed " + JSON.stringify(err));
    } else {
        console.info("publish");
    }
X
xuchenghua09 已提交
192
}
Z
zengsiyu 已提交
193

X
xuchenghua09 已提交
194
//发布公共事件
Z
zengsiyu 已提交
195
CommonEvent.publish("event", PublishCallBack);
X
xuchenghua09 已提交
196 197 198 199
```



Z
zengyawen 已提交
200
## CommonEvent.publish
X
xuchenghua09 已提交
201

Z
zengyawen 已提交
202
publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\<void>): void
X
xuchenghua09 已提交
203

Z
zengyawen 已提交
204
发布公共事件指定发布信息(callback形式)。
X
xuchenghua09 已提交
205

Z
zengsiyu 已提交
206
**系统能力:** SystemCapability.Notification.CommonEvent
Z
zengsiyu 已提交
207

Z
zengyawen 已提交
208
**参数:**
X
xuchenghua09 已提交
209

Z
zengyawen 已提交
210 211 212 213 214
| 名称     | 读写属性 | 类型                   | 必填 | 描述                   |
| -------- | -------- | ---------------------- | ---- | ---------------------- |
| event    | 只读     | string                 | 是   | 表示要发布的公共事件。  |
| options  | 只读     | [CommonEventPublishData](#commoneventpublishdata) | 是   | 表示发布公共事件的属性。 |
| callback | 只读     | AsyncCallback\<void>   | 是   | 表示被指定的回调方法。  |
X
xuchenghua09 已提交
215

Z
zengyawen 已提交
216
**示例:**
X
xuchenghua09 已提交
217 218 219 220 221


```js
//公共事件相关信息
var options = {
222 223 224
	code: 0,			 //公共事件的初始代码
	data: "initial data",//公共事件的初始数据
	isOrdered: true	 //有序公共事件
X
xuchenghua09 已提交
225
}
Z
zengsiyu 已提交
226

X
xuchenghua09 已提交
227 228
//发布公共事件回调
function PublishCallBack(err) {
Z
zengsiyu 已提交
229 230 231 232 233
	if (err.code) {
        console.error("publish failed " + JSON.stringify(err));
    } else {
        console.info("publish");
    }
X
xuchenghua09 已提交
234
}
Z
zengsiyu 已提交
235

X
xuchenghua09 已提交
236
//发布公共事件
Z
zengsiyu 已提交
237
CommonEvent.publish("event", options, PublishCallBack);
X
xuchenghua09 已提交
238 239 240 241
```



242
## CommonEvent.publishAsUser<sup>8+</sup>
Z
zengsiyu 已提交
243 244 245 246 247

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

向指定用户发布公共事件(callback形式)。

Z
zengsiyu 已提交
248
**系统能力:** SystemCapability.Notification.CommonEvent
Z
zengsiyu 已提交
249

Z
zengsiyu 已提交
250 251 252 253 254 255 256 257 258 259 260 261 262 263
**参数:**

| 名称     | 读写属性 | 类型                 | 必填 | 描述                               |
| -------- | -------- | -------------------- | ---- | ---------------------------------- |
| event    | 只读     | string               | 是   | 表示要发送的公共事件。             |
| userId   | 只读     | number               | 是   | 表示指定向该用户ID发送此公共事件。 |
| callback | 只读     | AsyncCallback\<void> | 是   | 表示被指定的回调方法。             |

**示例:**

```js
//发布公共事件回调
function PublishAsUserCallBack(err) {
	if (err.code) {
Z
zengsiyu 已提交
264
        console.error("publishAsUser failed " + JSON.stringify(err));
Z
zengsiyu 已提交
265 266 267 268
    } else {
        console.info("publishAsUser");
    }
}
Z
zengsiyu 已提交
269

Z
zengsiyu 已提交
270 271
//指定发送的用户
var userId = 100;
Z
zengsiyu 已提交
272

Z
zengsiyu 已提交
273
//发布公共事件
Z
zengsiyu 已提交
274
CommonEvent.publishAsUser("event", userId, PublishAsUserCallBack);
Z
zengsiyu 已提交
275 276 277 278
```



279
## CommonEvent.publishAsUser<sup>8+</sup>
Z
zengsiyu 已提交
280 281 282 283 284

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

向指定用户发布公共事件并指定发布信息(callback形式)。

Z
zengsiyu 已提交
285
**系统能力:** SystemCapability.Notification.CommonEvent
Z
zengsiyu 已提交
286

Z
zengsiyu 已提交
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
**参数:**

| 名称     | 读写属性 | 类型                   | 必填 | 描述                   |
| -------- | -------- | ---------------------- | ---- | ---------------------- |
| event    | 只读     | string                 | 是   | 表示要发布的公共事件。  |
| userId | 只读 | number | 是 | 表示指定向该用户ID发送此公共事件。 |
| options  | 只读     | [CommonEventPublishData](#commoneventpublishdata) | 是   | 表示发布公共事件的属性。 |
| callback | 只读     | AsyncCallback\<void>   | 是   | 表示被指定的回调方法。  |

**示例:**


```js
//公共事件相关信息
var options = {
X
xuezhongzhu 已提交
302 303
	code: 0,			 //公共事件的初始代码
	data: "initial data",//公共事件的初始数据
Z
zengsiyu 已提交
304
}
Z
zengsiyu 已提交
305

Z
zengsiyu 已提交
306 307 308
//发布公共事件回调
function PublishAsUserCallBack(err) {
	if (err.code) {
Z
zengsiyu 已提交
309
        console.error("publishAsUser failed " + JSON.stringify(err));
Z
zengsiyu 已提交
310 311 312 313
    } else {
        console.info("publishAsUser");
    }
}
Z
zengsiyu 已提交
314

Z
zengsiyu 已提交
315 316
//指定发送的用户
var userId = 100;
Z
zengsiyu 已提交
317

Z
zengsiyu 已提交
318
//发布公共事件
Z
zengsiyu 已提交
319
CommonEvent.publishAsUser("event", userId, options, PublishAsUserCallBack);
Z
zengsiyu 已提交
320 321 322 323
```



Z
zengyawen 已提交
324
## CommonEvent.createSubscriber
X
xuchenghua09 已提交
325

Z
zengyawen 已提交
326
createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback\<CommonEventSubscriber>): void
X
xuchenghua09 已提交
327

Z
zengyawen 已提交
328
创建订阅者(callback形式)。
X
xuchenghua09 已提交
329

Z
zengsiyu 已提交
330
**系统能力:** SystemCapability.Notification.CommonEvent
Z
zengsiyu 已提交
331

Z
zengyawen 已提交
332
**参数:**
X
xuchenghua09 已提交
333

Z
zengyawen 已提交
334 335 336 337
| 名称          | 读写属性 | 类型                                                         | 必填 | 描述                       |
| ------------- | -------- | ------------------------------------------------------------ | ---- | -------------------------- |
| subscribeInfo | 只读     | [CommonEventSubscribeInfo](#commoneventsubscribeinfo)        | 是   | 表示订阅信息。             |
| callback      | 只读     | AsyncCallback\<[CommonEventSubscriber](#commoneventsubscriber)> | 是   | 表示创建订阅者的回调方法。 |
X
xuchenghua09 已提交
338

Z
zengyawen 已提交
339
**示例:**
X
xuchenghua09 已提交
340 341 342 343


```js
var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
Z
zengsiyu 已提交
344

X
xuchenghua09 已提交
345 346 347 348
//订阅者信息
var subscribeInfo = {
	events: ["event"]
};
Z
zengsiyu 已提交
349

X
xuchenghua09 已提交
350
//创建订阅者回调
Z
zengsiyu 已提交
351 352 353 354 355 356 357
function CreateSubscriberCallBack(err, commonEventSubscriber) {
    if (err.code) {
        console.error("createSubscriber failed " + JSON.stringify(err));
    } else {
        console.info("createSubscriber");
        subscriber = commonEventSubscriber;
    }
X
xuchenghua09 已提交
358
}
Z
zengsiyu 已提交
359

X
xuchenghua09 已提交
360 361 362 363 364 365
//创建订阅者
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack);
```



Z
zengyawen 已提交
366
## CommonEvent.createSubscriber
X
xuchenghua09 已提交
367

Z
zengyawen 已提交
368
createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\<CommonEventSubscriber>
X
xuchenghua09 已提交
369

Z
zengyawen 已提交
370
创建订阅者(Promise形式)。
X
xuchenghua09 已提交
371

Z
zengsiyu 已提交
372
**系统能力:** SystemCapability.Notification.CommonEvent
Z
zengsiyu 已提交
373

Z
zengyawen 已提交
374
**参数:**
X
xuchenghua09 已提交
375

Z
zengyawen 已提交
376 377 378
| 名称          | 读写属性 | 类型                                                  | 必填 | 描述           |
| ------------- | -------- | ----------------------------------------------------- | ---- | -------------- |
| subscribeInfo | 只读     | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | 是   | 表示订阅信息。 |
X
xuchenghua09 已提交
379

Z
zengyawen 已提交
380 381 382 383
**返回值:**
| 类型                                                      | 说明             |
| --------------------------------------------------------- | ---------------- |
| Promise\<[CommonEventSubscriber](#commoneventsubscriber)> | 返回订阅者对象。 |
X
xuchenghua09 已提交
384

Z
zengyawen 已提交
385
**示例:**
X
xuchenghua09 已提交
386 387 388

```js
var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
Z
zengsiyu 已提交
389

X
xuchenghua09 已提交
390 391 392 393
//订阅者信息
var subscribeInfo = {
	events: ["event"]
};
Z
zengsiyu 已提交
394

X
xuchenghua09 已提交
395
//创建订阅者
Z
zengsiyu 已提交
396 397 398 399 400
CommonEvent.createSubscriber(subscribeInfo).then((commonEventSubscriber) => {
    console.info("createSubscriber");
    subscriber = commonEventSubscriber;
}).catch((err) => {
    console.error("createSubscriber failed " + JSON.stringify(err));
X
xuchenghua09 已提交
401 402 403 404 405
});
```



Z
zengyawen 已提交
406
## CommonEvent.subscribe
X
xuchenghua09 已提交
407

Z
zengyawen 已提交
408
subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEventData>): void
X
xuchenghua09 已提交
409

Z
zengyawen 已提交
410
订阅公共事件(callback形式)。
X
xuchenghua09 已提交
411

Z
zengsiyu 已提交
412
**系统能力:** SystemCapability.Notification.CommonEvent
Z
zengsiyu 已提交
413

Z
zengyawen 已提交
414
**参数:**
X
xuchenghua09 已提交
415

Z
zengyawen 已提交
416 417 418 419
| 名称       | 读写属性 | 类型                                                | 必填 | 描述                             |
| ---------- | -------- | --------------------------------------------------- | ---- | -------------------------------- |
| subscriber | 只读     | [CommonEventSubscriber](#commoneventsubscriber)     | 是   | 表示订阅者对象。                 |
| callback   | 只读     | AsyncCallback\<[CommonEventData](#commoneventdata)> | 是   | 表示接收公共事件数据的回调函数。 |
X
xuchenghua09 已提交
420

Z
zengyawen 已提交
421
**示例:**
X
xuchenghua09 已提交
422 423 424

```js
var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
Z
zengsiyu 已提交
425

X
xuchenghua09 已提交
426 427 428 429 430 431 432
//订阅者信息
var subscribeInfo = {
    events: ["event"]
};

//订阅公共事件回调
function SubscribeCallBack(err, data) {
Z
zengsiyu 已提交
433 434 435 436 437
    if (err.code) {
        console.error("subscribe failed " + JSON.stringify(err));
    } else {
        console.info("subscribe " + JSON.stringify(data));
    }
X
xuchenghua09 已提交
438 439 440
}

//创建订阅者回调
Z
zengsiyu 已提交
441 442 443 444 445 446 447 448 449
function CreateSubscriberCallBack(err, commonEventSubscriber) {
    if (err.code) {
        console.error("createSubscriber failed " + JSON.stringify(err));
    } else {
        console.info("createSubscriber");
        subscriber = commonEventSubscriber;
        //订阅公共事件
        CommonEvent.subscribe(subscriber, SubscribeCallBack);
    }
X
xuchenghua09 已提交
450 451 452 453 454 455
}

//创建订阅者
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack);
```

Z
zengsiyu 已提交
456
 
X
xuchenghua09 已提交
457

Z
zengyawen 已提交
458
## CommonEvent.unsubscribe
X
xuchenghua09 已提交
459

Z
zengyawen 已提交
460
unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>): void
X
xuchenghua09 已提交
461

Z
zengyawen 已提交
462
取消订阅公共事件(callback形式)。
X
xuchenghua09 已提交
463

Z
zengsiyu 已提交
464
**系统能力:** SystemCapability.Notification.CommonEvent
Z
zengsiyu 已提交
465

Z
zengyawen 已提交
466
**参数:**
X
xuchenghua09 已提交
467

Z
zengyawen 已提交
468 469 470
| 名称       | 读写属性 | 类型                  | 必填 | 描述                     |
| ---------- | -------- | --------------------- | ---- | ------------------------ |
| subscriber | 只读     | CommonEventSubscriber | 是   | 表示订阅者对象。         |
471
| callback   | 只读     | AsyncCallback\<void>  | 否   | 表示取消订阅的回调方法。 |
X
xuchenghua09 已提交
472

Z
zengyawen 已提交
473
**示例:**
X
xuchenghua09 已提交
474 475 476

```js
var subscriber;	//用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
Z
zengsiyu 已提交
477

X
xuchenghua09 已提交
478 479 480 481
//订阅者信息
var subscribeInfo = {
	events: ["event"]
};
Z
zengsiyu 已提交
482

X
xuchenghua09 已提交
483 484
//订阅公共事件回调
function SubscribeCallBack(err, data) {
Z
zengsiyu 已提交
485 486 487 488 489
    if (err.code) {
        console.info("subscribe failed " + JSON.stringify(err));
    } else {
        console.info("subscribe " + JSON.stringify(data));
    }
X
xuchenghua09 已提交
490
}
Z
zengsiyu 已提交
491

X
xuchenghua09 已提交
492
//创建订阅者回调
Z
zengsiyu 已提交
493 494 495 496 497 498 499 500 501
function CreateSubscriberCallBack(err, commonEventSubscriber) {
    if (err.code) {
        console.info("createSubscriber failed " + JSON.stringify(err));
    } else {
        console.info("createSubscriber");
        subscriber = commonEventSubscriber;
        //订阅公共事件
        CommonEvent.subscribe(subscriber, SubscribeCallBack);
    }
X
xuchenghua09 已提交
502
}
Z
zengsiyu 已提交
503

X
xuchenghua09 已提交
504 505
//取消订阅公共事件回调
function UnsubscribeCallBack(err) {
Z
zengsiyu 已提交
506 507 508 509 510
	if (err.code) {
        console.info("unsubscribe failed " + JSON.stringify(err));
    } else {
        console.info("unsubscribe");
    }
X
xuchenghua09 已提交
511
}
Z
zengsiyu 已提交
512

X
xuchenghua09 已提交
513 514
//创建订阅者
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack);
Z
zengsiyu 已提交
515

X
xuchenghua09 已提交
516 517 518
//取消订阅公共事件
CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack);
```