js-apis-commonEvent.md 44.0 KB
Newer Older
W
wusongqing 已提交
1 2
# CommonEvent Module

W
wusongqing 已提交
3 4
> **Note:**
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
W
wusongqing 已提交
5 6 7 8

## Required Permissions

| Common Event Macro| Common Event Name| Subscriber Permissions|
W
wusongqing 已提交
9
| ------------ | ------------------ | ---------------------- |
W
wusongqing 已提交
10 11 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| COMMON_EVENT_BOOT_COMPLETED                                  | usual.event.BOOT_COMPLETED                                  | ohos.permission.RECEIVER_STARTUP_COMPLETED                   |
| COMMON_EVENT_SHUTDOWN                                        | usual.event.SHUTDOWN                                        | N/A|
| COMMON_EVENT_BATTERY_CHANGED                                 | usual.event.BATTERY_CHANGED                                 | N/A|
| COMMON_EVENT_BATTERY_LOW                                     | usual.event.BATTERY_LOW                                     | N/A|
| COMMON_EVENT_BATTERY_OKAY                                    | usual.event.BATTERY_OKAY                                    | N/A|
| COMMON_EVENT_POWER_CONNECTED                                 | usual.event.POWER_CONNECTED                                 | N/A|
| COMMON_EVENT_POWER_DISCONNECTED                              | usual.event.POWER_DISCONNECTED                              | N/A|
| COMMON_EVENT_SCREEN_OFF                                      | usual.event.SCREEN_OFF                                      | N/A|
| COMMON_EVENT_SCREEN_ON                                       | usual.event.SCREEN_ON                                       | N/A|
| COMMON_EVENT_USER_PRESENT                                    | usual.event.USER_PRESENT                                    | N/A|
| COMMON_EVENT_TIME_TICK                                       | usual.event.TIME_TICK                                       | N/A|
| COMMON_EVENT_TIME_CHANGED                                    | usual.event.TIME_CHANGED                                    | N/A|
| COMMON_EVENT_DATE_CHANGED                                    | usual.event.DATE_CHANGED                                    | N/A|
| COMMON_EVENT_TIMEZONE_CHANGED                                | usual.event.TIMEZONE_CHANGED                                | N/A|
| COMMON_EVENT_CLOSE_SYSTEM_DIALOGS                            | usual.event.CLOSE_SYSTEM_DIALOGS                            | N/A|
| COMMON_EVENT_PACKAGE_ADDED                                   | usual.event.PACKAGE_ADDED                                   | N/A|
| COMMON_EVENT_PACKAGE_REPLACED                                | usual.event.PACKAGE_REPLACED                                | N/A|
| COMMON_EVENT_MY_PACKAGE_REPLACED                             | usual.event.MY_PACKAGE_REPLACED                             | N/A|
| COMMON_EVENT_PACKAGE_REMOVED                                 | usual.event.PACKAGE_REMOVED                                 | N/A|
| COMMON_EVENT_PACKAGE_FULLY_REMOVED                           | usual.event.PACKAGE_FULLY_REMOVED                           | N/A|
| COMMON_EVENT_PACKAGE_CHANGED                                 | usual.event.PACKAGE_CHANGED                                 | N/A|
| COMMON_EVENT_PACKAGE_RESTARTED                               | usual.event.PACKAGE_RESTARTED                               | N/A|
| COMMON_EVENT_PACKAGE_DATA_CLEARED                            | usual.event.PACKAGE_DATA_CLEARED                            | N/A|
| COMMON_EVENT_PACKAGES_SUSPENDED                              | usual.event.PACKAGES_SUSPENDED                              | N/A|
| COMMON_EVENT_PACKAGES_UNSUSPENDED                            | usual.event.PACKAGES_UNSUSPENDED                            | N/A|
| COMMON_EVENT_MY_PACKAGE_SUSPENDED                            | usual.event.MY_PACKAGE_SUSPENDED                            | N/A|
| COMMON_EVENT_MY_PACKAGE_UNSUSPENDED                          | usual.event.MY_PACKAGE_UNSUSPENDED                          | N/A|
| COMMON_EVENT_UID_REMOVED                                     | usual.event.UID_REMOVED                                     | N/A|
| COMMON_EVENT_PACKAGE_FIRST_LAUNCH                            | usual.event.PACKAGE_FIRST_LAUNCH                            | N/A|
| COMMON_EVENT_PACKAGE_NEEDS_VERIFICATION                      | usual.event.PACKAGE_NEEDS_VERIFICATION                      | N/A|
| COMMON_EVENT_PACKAGE_VERIFIED                                | usual.event.PACKAGE_VERIFIED                                | N/A|
| COMMON_EVENT_EXTERNAL_APPLICATIONS_AVAILABLE                 | usual.event.EXTERNAL_APPLICATIONS_AVAILABLE                 | N/A|
| COMMON_EVENT_EXTERNAL_APPLICATIONS_UNAVAILABLE               | usual.event.EXTERNAL_APPLICATIONS_UNAVAILABLE               | N/A|
| COMMON_EVENT_CONFIGURATION_CHANGED                           | usual.event.CONFIGURATION_CHANGED                           | N/A|
| COMMON_EVENT_LOCALE_CHANGED                                  | usual.event.LOCALE_CHANGED                                  | N/A|
| COMMON_EVENT_MANAGE_PACKAGE_STORAGE                          | usual.event.MANAGE_PACKAGE_STORAGE                          | N/A|
| COMMON_EVENT_DRIVE_MODE                                      | common.event.DRIVE_MODE                                     | N/A|
| COMMON_EVENT_HOME_MODE                                       | common.event.HOME_MODE                                      | N/A|
| COMMON_EVENT_OFFICE_MODE                                     | common.event.OFFICE_MODE                                    | N/A|
| COMMON_EVENT_USER_STARTED                                    | usual.event.USER_STARTED                                    | N/A|
| COMMON_EVENT_USER_BACKGROUND                                 | usual.event.USER_BACKGROUND                                 | N/A|
| COMMON_EVENT_USER_FOREGROUND                                 | usual.event.USER_FOREGROUND                                 | N/A|
| COMMON_EVENT_USER_SWITCHED                                   | usual.event.USER_SWITCHED                                   | ohos.permission.MANAGE_USERS                                 |
| COMMON_EVENT_USER_UNLOCKED                                   | usual.event.USER_UNLOCKED                                   | N/A|
| COMMON_EVENT_USER_STOPPED                                    | usual.event.USER_STOPPED                                    | N/A|
| COMMON_EVENT_HWID_LOGIN                                      | common.event.HWID_LOGIN                                     | N/A|
| COMMON_EVENT_HWID_LOGOUT                                     | common.event.HWID_LOGOUT                                    | N/A|
| COMMON_EVENT_HWID_TOKEN_INVALID                              | common.event.HWID_TOKEN_INVALID                             | N/A|
| COMMON_EVENT_HWID_LOGOFF                                     | common.event.HWID_LOGOFF                                    | N/A|
| COMMON_EVENT_WIFI_POWER_STATE                                | usual.event.wifi.POWER_STATE                                | N/A|
| 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                                 | N/A|
| COMMON_EVENT_WIFI_HOTSPOT_STATE                              | usual.event.wifi.HOTSPOT_STATE                              | N/A|
| 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                                |
| 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                                |
| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsource.AVRCP_CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH                                |
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_SDP_RESULT               | usual.event.bluetooth.remotedevice.SDP_RESULT               | N/A|
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_CANCEL           | usual.event.bluetooth.remotedevice.PAIRING_CANCEL           | N/A|
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REQ              | usual.event.bluetooth.remotedevice.CONNECT_REQ              | N/A|
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REPLY            | usual.event.bluetooth.remotedevice.CONNECT_REPLY            | N/A|
| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_CANCEL           | usual.event.bluetooth.remotedevice.CONNECT_CANCEL           | N/A|
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_CONNECT_STATE_UPDATE    | usual.event.bluetooth.handsfreeunit.CONNECT_STATE_UPDATE    | N/A|
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AUDIO_STATE_UPDATE      | usual.event.bluetooth.handsfreeunit.AUDIO_STATE_UPDATE      | N/A|
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_COMMON_EVENT         | usual.event.bluetooth.handsfreeunit.AG_COMMON_EVENT         | N/A|
| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_CALL_STATE_UPDATE    | usual.event.bluetooth.handsfreeunit.AG_CALL_STATE_UPDATE    | N/A|
| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISCOVERABLE                 | usual.event.bluetooth.host.REQ_DISCOVERABLE                 | N/A|
| COMMON_EVENT_NFC_ACTION_ADAPTER_STATE_CHANGED                | usual.event.nfc.action.ADAPTER_STATE_CHANGED                | N/A|
| COMMON_EVENT_DISCHARGING                                     | usual.event.DISCHARGING                                     | N/A|
| COMMON_EVENT_CHARGING                                        | usual.event.CHARGING                                        | N/A|
| COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED                        | usual.event.DEVICE_IDLE_MODE_CHANGED                        | N/A|
| COMMON_EVENT_POWER_SAVE_MODE_CHANGED                         | usual.event.POWER_SAVE_MODE_CHANGED                         | N/A|
| COMMON_EVENT_USER_ADDED                                      | usual.event.USER_ADDED                                      | ohos.permission.MANAGE_USERS                                 |
| COMMON_EVENT_USER_REMOVED                                    | usual.event.USER_REMOVED                                    | ohos.permission.MANAGE_USERS                                 |
| COMMON_EVENT_LOCATION_MODE_STATE_CHANGED                     | usual.event.location.MODE_STATE_CHANGED                     | N/A|
| COMMON_EVENT_IVI_SLEEP                                       | common.event.IVI_SLEEP                                      | N/A|
| COMMON_EVENT_IVI_PAUSE                                       | common.event.IVI_PAUSE                                      | N/A|
| COMMON_EVENT_IVI_STANDBY                                     | common.event.IVI_STANDBY                                    | N/A|
| COMMON_EVENT_IVI_LASTMODE_SAVE                               | common.event.IVI_LASTMODE_SAVE                              | N/A|
| COMMON_EVENT_IVI_VOLTAGE_ABNORMAL                            | common.event.IVI_VOLTAGE_ABNORMAL                           | N/A|
| COMMON_EVENT_IVI_HIGH_TEMPERATURE                            | common.event.IVI_HIGH_TEMPERATURE                           | N/A|
| COMMON_EVENT_IVI_EXTREME_TEMPERATURE                         | common.event.IVI_EXTREME_TEMPERATURE                        | N/A|
| COMMON_EVENT_IVI_TEMPERATURE_ABNORMAL                        | common.event.IVI_TEMPERATURE_ABNORMAL                       | N/A|
| COMMON_EVENT_IVI_VOLTAGE_RECOVERY                            | common.event.IVI_VOLTAGE_RECOVERY                           | N/A|
| COMMON_EVENT_IVI_TEMPERATURE_RECOVERY                        | common.event.IVI_TEMPERATURE_RECOVERY                       | N/A|
| COMMON_EVENT_IVI_ACTIVE                                      | common.event.IVI_ACTIVE                                     | N/A|
| COMMON_EVENT_USB_DEVICE_ATTACHED                             | usual.event.hardware.usb.action.USB_DEVICE_ATTACHED         | N/A|
| COMMON_EVENT_USB_DEVICE_DETACHED                             | usual.event.hardware.usb.action.USB_DEVICE_DETACHED         | N/A|
| COMMON_EVENT_USB_ACCESSORY_ATTACHED                          | usual.event.hardware.usb.action.USB_ACCESSORY_ATTACHED      | N/A|
| COMMON_EVENT_USB_ACCESSORY_DETACHED                          | usual.event.hardware.usb.action.USB_ACCESSORY_DETACHED      | N/A|
W
wusongqing 已提交
106 107 108 109 110
| 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|
| COMMON_EVENT_DISK_EJECT                                      | usual.event.data.DISK_EJECT                                 | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE|
W
wusongqing 已提交
111 112 113 114 115
| COMMON_EVENT_AIRPLANE_MODE_CHANGED                           | usual.event.AIRPLANE_MODE                                   | N/A|

## Modules to Import

```js
E
ester.zhou 已提交
116
import CommonEvent from '@ohos.commonEvent';
W
wusongqing 已提交
117 118
```

W
wusongqing 已提交
119
## System Capabilities
W
wusongqing 已提交
120

W
wusongqing 已提交
121 122 123
```js
SystemCapability.Notification.CommonEvent
```
W
wusongqing 已提交
124

W
wusongqing 已提交
125
## CommonEvent.publish
W
wusongqing 已提交
126

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

W
wusongqing 已提交
129
Publishes a common event. This method uses a callback to return the result.
W
wusongqing 已提交
130

W
wusongqing 已提交
131
**Parameters**
W
wusongqing 已提交
132

W
wusongqing 已提交
133 134 135 136
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | -------------------- | ---- | ---------------------- |
| 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 已提交
137

W
wusongqing 已提交
138
**Example**
W
wusongqing 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151

```js
// Callback for common event publication
function PublishCallBack(err) {
	console.info("==========================>PublishCallBack=======================>");
    console.info("==========================>err:=======================>", err.code);
}
// Publish a common event.
CommonEvent.publish("publish_event", PublishCallBack);
```



W
wusongqing 已提交
152
## CommonEvent.publish
W
wusongqing 已提交
153

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

W
wusongqing 已提交
156
Publishes a common event with given attributes. This method uses a callback to return the result.
W
wusongqing 已提交
157

W
wusongqing 已提交
158
**Parameters**
W
wusongqing 已提交
159

W
wusongqing 已提交
160 161 162 163 164
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | ---------------------- | ---- | ---------------------- |
| 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 已提交
165

W
wusongqing 已提交
166
**Example**
W
wusongqing 已提交
167 168 169 170 171


```js
// Attributes of a common event.
var options = {
E
ester.zhou 已提交
172 173 174
	code: 0,			 // Result code of the common event
	data: "initial data",// Result data of the common event
	isOrdered: true 	 // The common event is an ordered one.
W
wusongqing 已提交
175 176 177 178 179 180 181 182 183 184 185
}
// Callback for common event publication
function PublishCallBack(err) {
	console.info("==========================>PublishCallBack=======================>");
}
// Publish a common event.
CommonEvent.publish("publish_event", options, PublishCallBack);
```



E
ester.zhou 已提交
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
## CommonEvent.publishAsUser

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

Publishes a common event to a specific user. This method uses a callback to return the result.

**Parameters**

| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | -------------------- | ---- | ---------------------------------- |
| 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.|

**Example**

```js
// Callback for common event publication
function PublishAsUserCallBack(err) {
	if (err.code) {
        console.info("publishAsUser failed " + JSON.stringify(err));
    } else {
        console.info("publishAsUser");
    }
}
// Specify the user to whom the common event will be published.
var userId = 100;
// Publish a common event.
CommonEvent.publish("publish_event", userId, PublishAsUserCallBack);
```



## CommonEvent.publishAsUser

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

Publishes a common event with given attributes to a specific user. This method uses a callback to return the result.

**Parameters**

| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | ---------------------- | ---- | ---------------------- |
| 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.|

**Example**


```js
// Attributes of a common event.
var options = {
	code: 0;			 // Result code of the common event
	data: "initial data";// Result data of the common event
}
// Callback for common event publication
function PublishAsUserCallBack(err) {
	if (err.code) {
        console.info("publishAsUser failed " + JSON.stringify(err));
    } else {
        console.info("publishAsUser");
    }
}
// Specify the user to whom the common event will be published.
var userId = 100;
// Publish a common event.
CommonEvent.publish("publish_event", userId, options, PublishAsUserCallBack);
```



W
wusongqing 已提交
259
## CommonEvent.createSubscriber
W
wusongqing 已提交
260

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

W
wusongqing 已提交
263
Creates a subscriber. This method uses a callback to return the result.
W
wusongqing 已提交
264

W
wusongqing 已提交
265
**Parameters**
W
wusongqing 已提交
266

W
wusongqing 已提交
267 268 269 270
| Name| Readable/Writable| Type| Mandatory| Description|
| ------------- | -------- | ------------------------------------------------------------ | ---- | -------------------------- |
| subscribeInfo | Read-only| [CommonEventSubscribeInfo](#commoneventsubscribeinfo)        | Yes| Subscriber information.|
| callback      | Read-only| AsyncCallback\<[CommonEventSubscriber](#commoneventsubscriber)> | Yes| Callback used to return the result.|
W
wusongqing 已提交
271

W
wusongqing 已提交
272
**Example**
W
wusongqing 已提交
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291


```js
var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
// Subscriber information
var subscribeInfo = {
	events: ["event"]
};
// Callback for subscriber creation
function CreateSubscriberCallBack(err, data) {
    console.info("==========================>CreateSubscriberCallBack=======================>");
    subscriber = data;
}
// Create a subscriber.
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack);
```



W
wusongqing 已提交
292
## CommonEvent.createSubscriber
W
wusongqing 已提交
293

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

W
wusongqing 已提交
296
Creates a subscriber. This method uses a promise to return the result.
W
wusongqing 已提交
297

W
wusongqing 已提交
298
**Parameters**
W
wusongqing 已提交
299

W
wusongqing 已提交
300 301 302
| Name| Readable/Writable| Type| Mandatory| Description|
| ------------- | -------- | ----------------------------------------------------- | ---- | -------------- |
| subscribeInfo | Read-only| [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | Yes| Subscriber information.|
W
wusongqing 已提交
303

W
wusongqing 已提交
304 305 306
**Return value**
| Type| Description|
| --------------------------------------------------------- | ---------------- |
W
wusongqing 已提交
307
| Promise\<[CommonEventSubscriber](#commoneventsubscriber)> | Promise used to return the subscriber object.|
W
wusongqing 已提交
308

W
wusongqing 已提交
309
**Example**
W
wusongqing 已提交
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325

```js
var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
// Subscriber information
var subscribeInfo = {
	events: ["event"]
};
// Create a subscriber.
CommonEvent.createSubscriber(subscribeInfo).then((data) => {
	console.info("==========================>createSubscriberPromise=======================>");
    subscriber = data;
});
```



W
wusongqing 已提交
326
## CommonEvent.subscribe
W
wusongqing 已提交
327

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

W
wusongqing 已提交
330
Subscribes to common events. This method uses a callback to return the result.
W
wusongqing 已提交
331

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

W
wusongqing 已提交
334 335 336 337
| Name| Readable/Writable| Type| Mandatory| Description|
| ---------- | -------- | --------------------------------------------------- | ---- | -------------------------------- |
| subscriber | Read-only| [CommonEventSubscriber](#commoneventsubscriber)     | Yes| Subscriber object.|
| callback   | Read-only| AsyncCallback\<[CommonEventData](#commoneventdata)> | Yes| Callback used to return the result.|
W
wusongqing 已提交
338

W
wusongqing 已提交
339
**Example**
W
wusongqing 已提交
340

W
wusongqing 已提交
341
Unordered common event:
W
wusongqing 已提交
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363

```js
var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
// Subscriber information
var subscribeInfo = {
    events: ["event"]
};
// Callback for common event subscription
function SubscribeCallBack(err, data) {
    console.info("==========================>SubscribeCallBack=======================>");
}
// Callback for subscriber creation
function CreateSubscriberCallBack(err, data) {
    console.info("==========================>CreateSubscriberCallBack=======================>");
    subscriber = data;
    // Subscribe to a common event.
    CommonEvent.subscribe(subscriber, SubscribeCallBack);
}
// Create a subscriber.
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack);
```

W
wusongqing 已提交
364
 Ordered common event:
W
wusongqing 已提交
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407

```js
var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
// Subscriber information
var subscribeInfo = {
    events: ["event"]
};

// Callback for result code setting of an ordered common event
function SetCodeCallBack(err) {
    console.info("==========================>SetCodeCallBack=======================>");
}
// Callback for result data setting of an ordered common event
function SetDataCallBack(err) {
    console.info("==========================>SetDataCallBack=======================>");
}
// Callback for ordered common event processing
function FinishCommonEventCallBack(err) {
    console.info("==========================>FinishCommonEventCallBack=======================>");
}
// Callback for common event subscription
function SubscribeCallBack(err, data) {
    console.info("==========================>SubscribeCallBack=======================>");
    // Set the result code for the ordered common event.
    subscriber.setCode(0, SetCodeCallBack);
    // Set the result data for the ordered common event.
    subscriber.setData("publish_data_changed", SetDataCallBack);
    // Complete the processing of the ordered common event.
    subscriber.finishCommonEvent(FinishCommonEventCallBack)
}

// Callback for subscriber creation
function CreateSubscriberCallBack(err, data) {
    console.info("==========================>CreateSubscriberCallBack=======================>");
    subscriber = data;
    // Subscribe to a common event.
    CommonEvent.subscribe(subscriber, SubscribeCallBack);
}

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

W
wusongqing 已提交
408
 
W
wusongqing 已提交
409

W
wusongqing 已提交
410
## CommonEvent.unsubscribe
W
wusongqing 已提交
411

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

W
wusongqing 已提交
414
Unsubscribes from common events. This method uses a callback to return the result.
W
wusongqing 已提交
415

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

W
wusongqing 已提交
418 419 420 421
| Name| Readable/Writable| Type| Mandatory| Description|
| ---------- | -------- | --------------------- | ---- | ------------------------ |
| subscriber | Read-only| CommonEventSubscriber | Yes| Subscriber object.|
| callback   | Read-only| AsyncCallback\<void>  | Yes| Callback used to return the result.|
W
wusongqing 已提交
422

W
wusongqing 已提交
423
**Example**
W
wusongqing 已提交
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451

```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
// Subscriber information
var subscribeInfo = {
	events: ["event"]
};
// Callback for common event subscription
function SubscribeCallBack(err, data) {
	console.info("==========================>SubscribeCallBack=======================>");
}
// Callback for subscriber creation
function CreateSubscriberCallBack(err, data) {
	console.info("==========================>CreateSubscriberCallBack=======================>");
	subscriber = data;
	// Subscribe to a common event.
	CommonEvent.subscribe(subscriber, SubscribeCallBack);
}
// Callback for common event unsubscription
function UnsubscribeCallBack(err) {
	console.info("==========================>UnsubscribeCallBack=======================>");
}
// Create a subscriber.
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack);
// Unsubscribe from the common event.
CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack);
```

W
wusongqing 已提交
452
## CommonEventPublishData
W
wusongqing 已提交
453 454 455 456 457 458 459 460 461 462

| 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.|
| parameters            | Read-only| {[key: string]: any} | No| Additional information about the common event.|

W
wusongqing 已提交
463
## CommonEventSubscribeInfo
W
wusongqing 已提交
464 465 466 467 468 469 470 471 472

| Name| Readable/Writable| Type| Mandatory| Description|
| ------------------- | -------- | -------------- | ---- | ------------------------------------------------------------ |
| events              | Read-only| Array\<string> | Yes| Common events to subscribe to.|
| publisherPermission | Read-only| string         | No| Permission required for the publisher.|
| 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.|

W
wusongqing 已提交
473
## CommonEventData
W
wusongqing 已提交
474 475 476 477 478 479 480 481 482

| Name| Readable/Writable| Type| Mandatory| Description|
| ---------- | -------- | -------------------- | ---- | ------------------------------------------------------ |
| event      | Read-only| string               | Yes| Name of the common event to subscribe to.|
| 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.|

W
wusongqing 已提交
483
## CommonEventSubscriber
W
wusongqing 已提交
484

W
wusongqing 已提交
485
### getCode
W
wusongqing 已提交
486

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

W
wusongqing 已提交
489
Obtains the result code of this common event. This method uses a callback to return the result.
W
wusongqing 已提交
490

W
wusongqing 已提交
491
**Parameters**
W
wusongqing 已提交
492

W
wusongqing 已提交
493 494 495
| Name| Type| Mandatory| Description|
| -------- | ---------------------- | ---- | ------------------ |
| callback | AsyncCallback\<number> | Yes| Callback used to return the result code.|
W
wusongqing 已提交
496

W
wusongqing 已提交
497
**Example**
W
wusongqing 已提交
498

W
wusongqing 已提交
499 500 501 502 503 504 505 506 507 508
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
// Callback for result data setting of an ordered common event
function getCodeCallback(err, data) {
    console.info("==========================>getCodeCallback=======================>");
    console.info("==========================>err:=======================>", err.code);
    console.info("==========================>code:=======================>", data);
}
subscriber.getCode(getCodeCallback);
```
W
wusongqing 已提交
509

W
wusongqing 已提交
510
### getCode
W
wusongqing 已提交
511

W
wusongqing 已提交
512
getCode(): Promise\<number>
W
wusongqing 已提交
513

W
wusongqing 已提交
514
Obtains the result code of this common event. This method uses a promise to return the result.
W
wusongqing 已提交
515

W
wusongqing 已提交
516
**Return value**
W
wusongqing 已提交
517

W
wusongqing 已提交
518 519
| Type| Description|
| ---------------- | -------------------- |
W
wusongqing 已提交
520
| Promise\<number> | Promise used to return the result code.|
W
wusongqing 已提交
521

W
wusongqing 已提交
522
**Example**
W
wusongqing 已提交
523

W
wusongqing 已提交
524 525 526 527 528 529 530
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
subscriber.getCode().then((data) => {
	console.info("==========================>getCodePromise=======================>");
    console.info("==========================>code:=======================>", data);
});
```
W
wusongqing 已提交
531

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

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

W
wusongqing 已提交
536
Sets the result code for this common event. This method uses a callback to return the result.
W
wusongqing 已提交
537

W
wusongqing 已提交
538
**Parameters**
W
wusongqing 已提交
539

W
wusongqing 已提交
540 541 542 543
| Name| Type| Mandatory| Description|
| -------- | -------------------- | ---- | ---------------------- |
| code     | number               | Yes| Result code of the common event.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
544

W
wusongqing 已提交
545
**Example**
W
wusongqing 已提交
546

W
wusongqing 已提交
547 548 549 550 551 552 553 554 555
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
// Callback for result data setting of an ordered common event
function setCodeCallback(err) {
    console.info("==========================>setCodeCallback=======================>");
    console.info("==========================>err:=======================>", err.code);
}
subscriber.setCode(1, setCodeCallback);
```
W
wusongqing 已提交
556

W
wusongqing 已提交
557
### setCode
W
wusongqing 已提交
558

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

W
wusongqing 已提交
561
Sets the result code for this common event. This method uses a promise to return the result.
W
wusongqing 已提交
562

W
wusongqing 已提交
563
**Parameters**
W
wusongqing 已提交
564

W
wusongqing 已提交
565 566
| Name| Type| Mandatory| Description|
| ------ | ------ | ---- | ------------------ |
E
ester.zhou 已提交
567
| code   | number | Yes| Callback used to return the result code.|
W
wusongqing 已提交
568

W
wusongqing 已提交
569
**Example**
W
wusongqing 已提交
570

W
wusongqing 已提交
571 572 573 574 575 576
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
subscriber.setCode(1).then(() => {
	console.info("==========================>setCodePromise=======================>");
});
```
W
wusongqing 已提交
577

W
wusongqing 已提交
578
### getData
W
wusongqing 已提交
579

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

W
wusongqing 已提交
582
Obtains the result data of this common event. This method uses a callback to return the result.
W
wusongqing 已提交
583

W
wusongqing 已提交
584
**Parameters**
W
wusongqing 已提交
585

W
wusongqing 已提交
586 587 588
| Name| Type| Mandatory| Description|
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<string> | Yes| Callback used to return the result data.|
W
wusongqing 已提交
589

W
wusongqing 已提交
590
**Example**
W
wusongqing 已提交
591

W
wusongqing 已提交
592 593 594 595 596 597 598 599 600 601
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
// Callback for result data setting of an ordered common event
function getDataCallback(err, data) {
    console.info("==========================>getDataCallback=======================>");
    console.info("==========================>err:=======================>", err.code);
    console.info("==========================>data:=======================>", data);
}
subscriber.getData(getDataCallback);
```
W
wusongqing 已提交
602

W
wusongqing 已提交
603
### getData
W
wusongqing 已提交
604

W
wusongqing 已提交
605
getData(): Promise\<string>
W
wusongqing 已提交
606

W
wusongqing 已提交
607
Obtains the result data of this common event. This method uses a promise to return the result.
W
wusongqing 已提交
608

W
wusongqing 已提交
609
**Return value**
W
wusongqing 已提交
610

W
wusongqing 已提交
611 612
| Type| Description|
| ---------------- | ------------------ |
W
wusongqing 已提交
613
| Promise\<string> | Promise used to return the result data.|
W
wusongqing 已提交
614

W
wusongqing 已提交
615
**Example**
W
wusongqing 已提交
616

W
wusongqing 已提交
617 618 619 620 621 622 623
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
subscriber.getData().then((data) => {
	console.info("==========================>getDataPromise=======================>");
    console.info("==========================>data:=======================>", data);
});
```
W
wusongqing 已提交
624

W
wusongqing 已提交
625
### setData
W
wusongqing 已提交
626

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

W
wusongqing 已提交
629
Sets the result data for this common event. This method uses a callback to return the result.
W
wusongqing 已提交
630

W
wusongqing 已提交
631
**Parameters**
W
wusongqing 已提交
632

W
wusongqing 已提交
633 634 635 636
| Name| Type| Mandatory| Description|
| -------- | -------------------- | ---- | -------------------- |
| data     | string               | Yes| Result data of the common event.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
637

W
wusongqing 已提交
638
**Example**
W
wusongqing 已提交
639

W
wusongqing 已提交
640 641 642 643 644 645 646 647 648
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
// Callback for result data setting of an ordered common event
function setDataCallback(err) {
    console.info("==========================>setDataCallback=======================>");
    console.info("==========================>err:=======================>", err.code);
}
subscriber.setData("publish_data_changed", setDataCallback);
```
W
wusongqing 已提交
649

W
wusongqing 已提交
650
### setData
W
wusongqing 已提交
651

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

W
wusongqing 已提交
654
Sets the result data for this common event. This method uses a promise to return the result.
W
wusongqing 已提交
655

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

W
wusongqing 已提交
658 659
| Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------- |
E
ester.zhou 已提交
660
| data   | string | Yes| Callback used to return the result data.|
W
wusongqing 已提交
661

W
wusongqing 已提交
662
**Example**
W
wusongqing 已提交
663

W
wusongqing 已提交
664 665 666 667 668 669
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
subscriber.setData("publish_data_changed").then(() => {
	console.info("==========================>setDataPromise=======================>");
});
```
W
wusongqing 已提交
670

W
wusongqing 已提交
671
### setCodeAndData
W
wusongqing 已提交
672

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

W
wusongqing 已提交
675
Sets the result code and result data for this common event. This method uses a callback to return the result.
W
wusongqing 已提交
676

W
wusongqing 已提交
677
**Parameters**
W
wusongqing 已提交
678

W
wusongqing 已提交
679 680 681 682 683
| Name| Type| Mandatory| Description|
| -------- | -------------------- | ---- | ---------------------- |
| 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 已提交
684

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

W
wusongqing 已提交
687 688 689 690 691 692 693 694 695
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
// Callback for result data setting of an ordered common event
function setCodeDataCallback(err) {
    console.info("==========================>setCodeDataCallback=======================>");
    console.info("==========================>err:=======================>", err.code);
}
subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCallback);
```
W
wusongqing 已提交
696

W
wusongqing 已提交
697
### setCodeAndData
W
wusongqing 已提交
698

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

W
wusongqing 已提交
701
Sets the result code and result data for this common event. This method uses a promise to return the result.
W
wusongqing 已提交
702

W
wusongqing 已提交
703
**Parameters**
W
wusongqing 已提交
704

W
wusongqing 已提交
705 706 707
| Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------- |
| code   | number | Yes| Result code of the common event.|
E
ester.zhou 已提交
708
| data   | string | Yes| Callback used to return the result data.|
W
wusongqing 已提交
709

W
wusongqing 已提交
710
**Example**
W
wusongqing 已提交
711

W
wusongqing 已提交
712 713 714 715 716 717
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
subscriber.setCodeAndData(1, "publish_data_changed").then(() => {
	console.info("==========================>setCodeAndData=======================>");
});
```
W
wusongqing 已提交
718

W
wusongqing 已提交
719
### isOrderedCommonEvent
W
wusongqing 已提交
720

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

W
wusongqing 已提交
723
Checks whether this common event is an ordered one. This method uses a callback to return the result.
W
wusongqing 已提交
724

W
wusongqing 已提交
725
**Parameters**
W
wusongqing 已提交
726

W
wusongqing 已提交
727 728 729
| Name| Type| Mandatory| Description|
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | Yes| Returns **true** if the common event is an ordered one; returns **false** otherwise.|
W
wusongqing 已提交
730

W
wusongqing 已提交
731
**Example**
W
wusongqing 已提交
732

W
wusongqing 已提交
733 734 735 736 737 738 739 740 741 742
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
// Callback for result data setting of an ordered common event
function isOrderedCallback(err, data) {
    console.info("==========================>isOrderedCallback=======================>");
    console.info("==========================>err:=======================>", err.code);
    console.info("==========================>isOrdered:=======================>", data);
}
subscriber.isOrderedCommonEvent(isOrderedCallback);
```
W
wusongqing 已提交
743

W
wusongqing 已提交
744
### isOrderedCommonEvent
W
wusongqing 已提交
745

W
wusongqing 已提交
746
isOrderedCommonEvent(): Promise\<boolean>
W
wusongqing 已提交
747

W
wusongqing 已提交
748
Checks whether this common event is an ordered one. This method uses a promise to return the result.
W
wusongqing 已提交
749

W
wusongqing 已提交
750
**Return value**
W
wusongqing 已提交
751

W
wusongqing 已提交
752 753 754
| Type| Description|
| ----------------- | -------------------------------- |
| Promise\<boolean> | Returns **true** if the common event is an ordered one; returns **false** otherwise.|
W
wusongqing 已提交
755

W
wusongqing 已提交
756
**Example**
W
wusongqing 已提交
757

W
wusongqing 已提交
758 759 760 761 762 763
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
subscriber.isOrderedCommonEvent().then((data) => {
	console.info("==========================>isOrdered:=======================>", data);
});
```
W
wusongqing 已提交
764

W
wusongqing 已提交
765
### abortCommonEvent
W
wusongqing 已提交
766

W
wusongqing 已提交
767
abortCommonEvent(callback: AsyncCallback\<void>): void
W
wusongqing 已提交
768

W
wusongqing 已提交
769
Aborts this common event. After the abort, the common event is not sent to the next subscriber. This method takes effect only for ordered common events. It uses a callback to return the result.
W
wusongqing 已提交
770

W
wusongqing 已提交
771
**Parameters**
W
wusongqing 已提交
772

W
wusongqing 已提交
773 774 775
| Name| Type| Mandatory| Description|
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
776

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

W
wusongqing 已提交
779 780 781 782 783 784 785 786 787
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
// Callback for result data setting of an ordered common event
function abortCallback(err) {
    console.info("==========================>abortCallback=======================>");
 	console.info("==========================>err:=======================>", err.code);
}
subscriber.abortCommonEvent(abortCallback);
```
W
wusongqing 已提交
788

W
wusongqing 已提交
789
### abortCommonEvent
W
wusongqing 已提交
790

W
wusongqing 已提交
791
abortCommonEvent(): Promise\<void>
W
wusongqing 已提交
792

W
wusongqing 已提交
793
Aborts this common event. After the abort, the common event is not sent to the next subscriber. This method takes effect only for ordered common events. It uses a promise to return the result.
W
wusongqing 已提交
794

W
wusongqing 已提交
795
**Example**
W
wusongqing 已提交
796

W
wusongqing 已提交
797 798 799 800 801 802
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
subscriber.abortCommonEvent().then(() => {
	console.info("==========================>abortCommonEvent:=======================>");
});
```
W
wusongqing 已提交
803

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

W
wusongqing 已提交
806
clearAbortCommonEvent(callback: AsyncCallback\<void>): void
W
wusongqing 已提交
807

W
wusongqing 已提交
808
Clears the aborted state of this common event. This method takes effect only for ordered common events. It uses a callback to return the result.
W
wusongqing 已提交
809

W
wusongqing 已提交
810
**Parameters**
W
wusongqing 已提交
811

W
wusongqing 已提交
812 813 814
| Name| Type| Mandatory| Description|
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
815

W
wusongqing 已提交
816
**Example**
W
wusongqing 已提交
817

W
wusongqing 已提交
818 819 820 821 822 823 824 825 826
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
// Callback for result data setting of an ordered common event
function clearAbortCallback(err) {
    console.info("==========================>clearAbortCallback=======================>");
 	console.info("==========================>err:=======================>", err.code);
}
subscriber.clearAbortCommonEvent(clearAbortCallback);
```
W
wusongqing 已提交
827

W
wusongqing 已提交
828
### clearAbortCommonEvent
W
wusongqing 已提交
829

W
wusongqing 已提交
830
clearAbortCommonEvent(): Promise\<void>
W
wusongqing 已提交
831

W
wusongqing 已提交
832
Clears the aborted state of this common event. This method takes effect only for ordered common events. It uses a promise to return the result.
W
wusongqing 已提交
833

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

W
wusongqing 已提交
836 837 838 839 840 841
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
subscriber.clearAbortCommonEvent().then(() => {
	console.info("==========================>clearAbortCommonEvent:=======================>");
});
```
W
wusongqing 已提交
842

W
wusongqing 已提交
843
### getAbortCommonEvent
W
wusongqing 已提交
844

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

W
wusongqing 已提交
847
Checks whether this common event is in the aborted state. This method takes effect only for ordered common events. It uses a callback to return the result.
W
wusongqing 已提交
848

W
wusongqing 已提交
849
**Parameters**
W
wusongqing 已提交
850

W
wusongqing 已提交
851 852 853
| Name| Type| Mandatory| Description|
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | Yes| Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.|
W
wusongqing 已提交
854

W
wusongqing 已提交
855
**Example**
W
wusongqing 已提交
856

W
wusongqing 已提交
857 858 859 860 861 862 863 864 865 866
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
// Callback for result data setting of an ordered common event
function getAbortCallback(err, data) {
    console.info("==========================>getAbortCallback=======================>");
 	console.info("==========================>err:=======================>", err.code);
    console.info("==========================>abort:=======================>", data);
}
subscriber.getAbortCommonEvent(getAbortCallback);
```
W
wusongqing 已提交
867

W
wusongqing 已提交
868
### getAbortCommonEvent
W
wusongqing 已提交
869

W
wusongqing 已提交
870
getAbortCommonEvent(): Promise\<void>
W
wusongqing 已提交
871

W
wusongqing 已提交
872
Checks whether this common event is in the aborted state. This method takes effect only for ordered common events. It uses a promise to return the result.
W
wusongqing 已提交
873

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

W
wusongqing 已提交
876 877 878
| Type| Description|
| ----------------- | ---------------------------------- |
| Promise\<boolean> | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.|
W
wusongqing 已提交
879

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

W
wusongqing 已提交
882 883 884 885 886 887 888
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
subscriber.getAbortCommonEvent().then((data) => {
	console.info("==========================>getAbortCommonEvent:=======================>");
    console.info("==========================>abort:=======================>", data);
});
```
W
wusongqing 已提交
889

W
wusongqing 已提交
890
### getSubscribeInfo
W
wusongqing 已提交
891

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

W
wusongqing 已提交
894
Obtains the subscriber information. This method uses a callback to return the result.
W
wusongqing 已提交
895

W
wusongqing 已提交
896
**Parameters**
W
wusongqing 已提交
897

W
wusongqing 已提交
898 899 900
| Name| Type| Mandatory| Description|
| -------- | ------------------------------------------------------------ | ---- | ---------------------- |
| callback | AsyncCallback\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Yes| Callback used to return the subscriber information.|
W
wusongqing 已提交
901

W
wusongqing 已提交
902
**Example**
W
wusongqing 已提交
903

W
wusongqing 已提交
904 905 906 907 908 909 910 911 912 913
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
// Callback for result data setting of an ordered common event
function getSubscribeInfoCallback(err, data) {
    console.info("==========================>getSubscribeInfoCallback=======================>");
 	console.info("==========================>err:=======================>", err.code);
    console.info("==========================>priority:=======================>", data.priority);
}
subscriber.getSubscribeInfo(getSubscribeInfoCallback);
```
W
wusongqing 已提交
914

W
wusongqing 已提交
915
### getSubscribeInfo
W
wusongqing 已提交
916

W
wusongqing 已提交
917
getSubscribeInfo(): Promise\<CommonEventSubscribeInfo>
W
wusongqing 已提交
918

W
wusongqing 已提交
919
Obtains the subscriber information. This method uses a promise to return the result.
W
wusongqing 已提交
920

W
wusongqing 已提交
921
**Return value**
W
wusongqing 已提交
922

W
wusongqing 已提交
923 924
| Type| Description|
| ------------------------------------------------------------ | ---------------------- |
W
wusongqing 已提交
925
| Promise\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Promise used to return the subscriber information.|
W
wusongqing 已提交
926

W
wusongqing 已提交
927
**Example**
W
wusongqing 已提交
928

W
wusongqing 已提交
929 930 931 932 933 934 935
```js
var subscriber;	// Used to save the created subscriber object for subsequent subscription and unsubscription.
subscriber.getSubscribeInfo().then((data) => {
	console.info("==========================>getSubscribeInfo:=======================>");
    console.info("==========================>priority:=======================>", data.priority);
});
```