提交 97805a86 编写于 作者: E ester.zhou

Update docs (15715)

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 790029ca
......@@ -59,7 +59,7 @@ Indicates that the device screen is on and the device is in interactive state.
- Required subscriber permissions: none
## COMMON_EVENT_THERMAL_LEVEL_CHANGED<sup>8+<sup>
## COMMON_EVENT_THERMAL_LEVEL_CHANGED<sup>8+</sup>
Indicates that the device's thermal level has changed.
- Value: **usual.event.THERMAL_LEVEL_CHANGED**
- Required subscriber permissions: none
......@@ -810,7 +810,7 @@ Indicates that a USB device has been detached from the device functioning as a U
## COMMON_EVENT_DISK_BAD_REMOVAL
(Reserved, not supported yet) Indicates that an external storage device was removed without being unmounted.
- Value: usual.event.data.DISK_BAD_REMOVAL
- Value: **usual.event.data.DISK_BAD_REMOVAL**
- Required subscriber permissions: ohos.permission.STORAGE_MANAGER
......@@ -826,33 +826,33 @@ Indicates that a USB device has been detached from the device functioning as a U
- Required subscriber permissions: ohos.permission.STORAGE_MANAGER
## COMMON_EVENT_VOLUME_REMOVED<sup>9+<sup>
## COMMON_EVENT_VOLUME_REMOVED<sup>9+</sup>
Indicates that an external storage device was removed.
- Value: **usual.event.data.VOLUME_REMOVED**
- Required subscriber permissions: ohos.permission.STORAGE_MANAGER
## COMMON_EVENT_VOLUME_UNMOUNTED<sup>9+<sup>
## COMMON_EVENT_VOLUME_UNMOUNTED<sup>9+</sup>
Indicates that an external storage device was unmounted.
- Value: **usual.event.data.VOLUME_UNMOUNTED**
- Required subscriber permissions: ohos.permission.STORAGE_MANAGER
## COMMON_EVENT_VOLUME_MOUNTED<sup>9+<sup>
## COMMON_EVENT_VOLUME_MOUNTED<sup>9+</sup>
Indicates that an external storage device was mounted.
- Value: **usual.event.data.VOLUME_MOUNTED**
- Required subscriber permissions: ohos.permission.STORAGE_MANAGER
## COMMON_EVENT_VOLUME_BAD_REMOVAL<sup>9+<sup>
## COMMON_EVENT_VOLUME_BAD_REMOVAL<sup>9+</sup>
Indicates that an external storage device was removed without being unmounted.
- Value: **usual.event.data.VOLUME_BAD_REMOVAL**
- Required subscriber permissions: ohos.permission.STORAGE_MANAGER
## COMMON_EVENT_VOLUME_EJECT<sup>9+<sup>
## COMMON_EVENT_VOLUME_EJECT<sup>9+</sup>
Indicates that an external storage device was ejected (at the software level).
- Value: usual.event.data.VOLUME_EJECT
- **Value: usual.event.data.VOLUME_EJECT**
- Required subscriber permissions: ohos.permission.STORAGE_MANAGER
......@@ -880,25 +880,30 @@ Indicates that the airplane mode of the device has changed.
- Required subscriber permissions: none
## COMMON_EVENT_SPLIT_SCREEN<sup>8+<sup>
## COMMON_EVENT_SPLIT_SCREEN<sup>8+</sup>
Indicates that the screen has been split.
- Value: **usual.event.SPLIT_SCREEN**
- Required subscriber permissions: none
## COMMON_EVENT_SLOT_CHANGE<sup>9+<sup>
## COMMON_EVENT_SLOT_CHANGE<sup>9+</sup>
Indicates that the notification slot has been updated.
- Value: **usual.event.SLOT_CHANGE**
- Required subscriber permissions: ohos.permission.NOTIFICATION_CONTROLLER
## COMMON_EVENT_SPN_INFO_CHANGED<sup>9+<sup>
## COMMON_EVENT_SPN_INFO_CHANGED<sup>9+</sup>
Indicates that the SPN displayed has been updated.
- Value: **usual.event.SPN_INFO_CHANGED**
- Required subscriber permissions: none
## COMMON_EVENT_QUICK_FIX_APPLY_RESULT<sup>9+<sup>
## COMMON_EVENT_QUICK_FIX_APPLY_RESULT<sup>9+</sup>
Indicates the result of applying a quick fix to the application.
- Value: **usual.event.QUICK_FIX_APPLY_RESULT**
- Required subscriber permissions: none
## COMMON_EVENT_USER_INFO_UPDATED<sup>9+</sup>
Indicates that the user information has been updated.
- Value: **usual.event.USER_INFO_UPDATED**
- Required subscriber permissions: none
......@@ -59,7 +59,7 @@ Indicates that the device screen is on and the device is in interactive state.
- Required subscriber permissions: none
## COMMON_EVENT_THERMAL_LEVEL_CHANGED<sup>8+<sup>
## COMMON_EVENT_THERMAL_LEVEL_CHANGED<sup>8+</sup>
Indicates that the device's thermal level has changed.
- Value: **usual.event.THERMAL_LEVEL_CHANGED**
- Required subscriber permissions: none
......@@ -658,6 +658,10 @@ Indicates that the system starts charging the battery.
- Value: **usual.event.CHARGING**
- Required subscriber permissions: none
## COMMON_EVENT_CHARGE_TYPE_CHANGED
Indicates that the system charging type has changed. This event is available only for system applications.
- Value: **usual.event.CHARGE_TYPE_CHANGED**
- Required subscriber permissions: none
## COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED
(Reserved, not supported yet) Indicates that the system idle mode has changed.
......@@ -845,31 +849,31 @@ Indicates that a USB device has been detached from the device functioning as a U
- Required subscriber permissions: ohos.permission.STORAGE_MANAGER
## COMMON_EVENT_VOLUME_REMOVED<sup>9+<sup>
## COMMON_EVENT_VOLUME_REMOVED<sup>9+</sup>
Indicates that an external storage device was removed.
- Value: **usual.event.data.VOLUME_REMOVED**
- Required subscriber permissions: ohos.permission.STORAGE_MANAGER
## COMMON_EVENT_VOLUME_UNMOUNTED<sup>9+<sup>
## COMMON_EVENT_VOLUME_UNMOUNTED<sup>9+</sup>
Indicates that an external storage device was unmounted.
- Value: **usual.event.data.VOLUME_UNMOUNTED**
- Required subscriber permissions: ohos.permission.STORAGE_MANAGER
## COMMON_EVENT_VOLUME_MOUNTED<sup>9+<sup>
## COMMON_EVENT_VOLUME_MOUNTED<sup>9+</sup>
Indicates that an external storage device was mounted.
- Value: **usual.event.data.VOLUME_MOUNTED**
- Required subscriber permissions: ohos.permission.STORAGE_MANAGER
## COMMON_EVENT_VOLUME_BAD_REMOVAL<sup>9+<sup>
## COMMON_EVENT_VOLUME_BAD_REMOVAL<sup>9+</sup>
Indicates that an external storage device was removed without being unmounted.
- Value: **usual.event.data.VOLUME_BAD_REMOVAL**
- Required subscriber permissions: ohos.permission.STORAGE_MANAGER
## COMMON_EVENT_VOLUME_EJECT<sup>9+<sup>
## COMMON_EVENT_VOLUME_EJECT<sup>9+</sup>
Indicates that an external storage device was ejected (at the software level).
- Value: usual.event.data.VOLUME_EJECT
- Required subscriber permissions: ohos.permission.STORAGE_MANAGER
......@@ -905,23 +909,23 @@ Indicates that the screen has been split.
- Required subscriber permissions: ohos.permission.RECEIVER_SPLIT_SCREEN
## COMMON_EVENT_SLOT_CHANGE<sup>9+<sup>
## COMMON_EVENT_SLOT_CHANGE<sup>9+</sup>
Indicates that the notification slot has been updated.
- Value: **usual.event.SLOT_CHANGE**
- Required subscriber permissions: ohos.permission.NOTIFICATION_CONTROLLER
## COMMON_EVENT_SPN_INFO_CHANGED<sup>9+<sup>
## COMMON_EVENT_SPN_INFO_CHANGED<sup>9+</sup>
Indicates that the SPN displayed has been updated.
- Value: **usual.event.SPN_INFO_CHANGED**
- Required subscriber permissions: none
## COMMON_EVENT_QUICK_FIX_APPLY_RESULT<sup>9+<sup>
## COMMON_EVENT_QUICK_FIX_APPLY_RESULT<sup>9+</sup>
Indicates the result of applying a quick fix to the application.
- Value: **usual.event.QUICK_FIX_APPLY_RESULT**
- Required subscriber permissions: none
## COMMON_EVENT_HTTP_PROXY_CHANGE<sup>10+<sup>
## COMMON_EVENT_HTTP_PROXY_CHANGE<sup>10+</sup>
Indicates that the HTTP proxy configuration has changed.
- Value: **usual.event.HTTP_PROXY_CHANGE**
- Required subscriber permissions: none
......@@ -67,7 +67,7 @@ Publishes a common event with given attributes. This API uses an asynchronous ca
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ---------------------- |
| event | string | Yes | Name of the common event to publish. |
| options | [CommonEventPublishData](#commoneventpublishdata) | Yes | Attributes of the common event to publish.|
| options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | Yes | Attributes of the common event to publish.|
| callback | syncCallback\<void> | Yes | Callback used to return the result. |
**Example**
......@@ -76,8 +76,8 @@ Publishes a common event with given attributes. This API uses an asynchronous ca
```ts
// Attributes of a common event.
let options = {
code: 0, // Initial code of the common event.
data: "initial data";// Initial data of the common event.
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.
}
......@@ -151,7 +151,7 @@ Publishes a common event with given attributes to a specific user. This API uses
| -------- | ---------------------- | ---- | ---------------------- |
| event | string | Yes | Name of the common event to publish. |
| userId | number | Yes| User ID.|
| options | [CommonEventPublishData](#commoneventpublishdata) | Yes | Attributes of the common event to publish.|
| options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | Yes | Attributes of the common event to publish.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example**
......@@ -194,8 +194,8 @@ Creates a subscriber. This API uses an asynchronous callback to return the resul
| Name | Type | Mandatory| Description |
| ------------- | ------------------------------------------------------------ | ---- | -------------------------- |
| subscribeInfo | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | Yes | Subscriber information. |
| callback | AsyncCallback\<[CommonEventSubscriber](#commoneventsubscriber)> | Yes | Callback used to return the result.|
| subscribeInfo | [CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md) | Yes | Subscriber information. |
| callback | AsyncCallback\<[CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md)> | Yes | Callback used to return the result.|
**Example**
......@@ -236,12 +236,12 @@ Creates a subscriber. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| ------------- | ----------------------------------------------------- | ---- | -------------- |
| subscribeInfo | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | Yes | Subscriber information.|
| subscribeInfo | [CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md) | Yes | Subscriber information.|
**Return value**
| Type | Description |
| --------------------------------------------------------- | ---------------- |
| Promise\<[CommonEventSubscriber](#commoneventsubscriber)> | Promise used to return the subscriber object.|
| Promise\<[CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md)> | Promise used to return the subscriber object.|
**Example**
......@@ -276,8 +276,8 @@ Subscribes to common events. This API uses an asynchronous callback to return th
| Name | Type | Mandatory| Description |
| ---------- | ---------------------------------------------------- | ---- | -------------------------------- |
| subscriber | [CommonEventSubscriber](#commoneventsubscriber) | Yes | Subscriber object. |
| callback | AsyncCallback\<[CommonEventData](#commoneventdata)> | Yes | Callback used to return the result.|
| subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md) | Yes | Subscriber object. |
| callback | AsyncCallback\<[CommonEventData](./js-apis-inner-commonEvent-commonEventData.md)> | Yes | Callback used to return the result.|
**Example**
......@@ -299,11 +299,12 @@ function subscribeCB(err, data) {
}
// Callback for subscriber creation.
function createCB(err, subscriber) {
function createCB(err, commonEventSubscriber) {
if (err.code) {
console.error(`createSubscriber failed, code is ${err.code}`);
} else {
console.info("createSubscriber");
subscriber = commonEventSubscriber;
// Subscribe to a common event.
CommonEvent.subscribe(subscriber, subscribeCB);
}
......@@ -327,7 +328,7 @@ Unsubscribes from common events. This API uses an asynchronous callback to retur
| Name | Type | Mandatory| Description |
| ---------- | ----------------------------------------------- | ---- | ------------------------ |
| subscriber | [CommonEventSubscriber](#commoneventsubscriber) | Yes | Subscriber object. |
| subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md) | Yes | Subscriber object. |
| callback | AsyncCallback\<void> | No | Callback used to return the result.|
**Example**
......@@ -376,800 +377,3 @@ CommonEvent.createSubscriber(subscribeInfo, createCB);
// Unsubscribe from the common event.
CommonEvent.unsubscribe(subscriber, unsubscribeCB);
```
## CommonEventSubscriber
### getCode
```ts
getCode(callback: AsyncCallback<number>): void
```
Obtains the code of this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------ |
| callback | AsyncCallback\<number> | Yes | Common event code.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for result code obtaining of an ordered common event.
function getCodeCB(err, Code) {
if (err.code) {
console.error(`getCode failed, code is ${err.code}`);
} else {
console.info("getCode " + JSON.stringify(Code));
}
}
subscriber.getCode(getCodeCB);
```
### getCode
```ts
getCode(): Promise<number>
```
Obtains the code of this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<number> | Common event code.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.getCode().then((code) => {
console.info("getCode " + JSON.stringify(code));
}).catch((err) => {
console.error(`getCode failed, code is ${err.code}`);
});
```
### setCode
```ts
setCode(code: number, callback: AsyncCallback<void>): void
```
Sets the code for this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------- |
| code | number | Yes | Common event code. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for result code setting of an ordered common event.
function setCodeCB(err) {
if (err.code) {
console.error(`setCode failed, code is ${err.code}`);
} else {
console.info("setCode");
}
}
subscriber.setCode(1, setCodeCB);
```
### setCode
```ts
setCode(code: number): Promise<void>
```
Sets the code for this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| code | number | Yes | Common event code.|
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.setCode(1).then(() => {
console.info("setCode");
}).catch((err) => {
console.error(`setCode failed, code is ${err.code}`);
});
```
### getData
```ts
getData(callback: AsyncCallback<string>): void
```
Obtains the data of this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<string> | Yes | Common event data.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for result data obtaining of an ordered common event.
function getDataCB(err, data) {
if (err.code) {
console.error(`getData failed, code is ${err.code}`);
} else {
console.info("getData " + JSON.stringify(data));
}
}
subscriber.getData(getDataCB);
```
### getData
```ts
getData(): Promise<string>
```
Obtains the data of this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | ------------------ |
| Promise\<string> | Common event data.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.getData().then((data) => {
console.info("getData " + JSON.stringify(data));
}).catch((err) => {
console.error(`getData failed, code is ${err.code}`);
});
```
### setData
```ts
setData(data: string, callback: AsyncCallback<void>): void
```
Sets the data for this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| data | string | Yes | Common event data. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for result data setting of an ordered common event
function setDataCB(err) {
if (err.code) {
console.error(`sendData failed, code is ${err.code}`);
} else {
console.info("setData");
}
}
subscriber.setData("publish_data_changed", setDataCB);
```
### setData
```ts
setData(data: string): Promise<void>
```
Sets the data for this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------- |
| data | string | Yes | Common event data.|
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.setData("publish_data_changed").then(() => {
console.info("setData");
}).catch((err) => {
console.error(`setData failed, code is ${err.code}`);
});
```
### setCodeAndData
```ts
setCodeAndData(code: number, data: string, callback:AsyncCallback<void>): void
```
Sets the code and data for this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------- |
| code | number | Yes | Common event code. |
| data | string | Yes | Common event data. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for result code and result data setting of an ordered common event.
function setCodeDataCB(err) {
if (err.code) {
console.error(`setCodeAndData failed, code is ${err.code}`);
} else {
console.info("setCodeDataCallback");
}
}
subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCB);
```
### setCodeAndData
```ts
setCodeAndData(code: number, data: string): Promise<void>
```
Sets the code and data for this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------- |
| code | number | Yes | Common event code.|
| data | string | Yes | Common event data.|
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.setCodeAndData(1, "publish_data_changed").then(() => {
console.info("setCodeAndData");
}).catch((err) => {
console.error(`setCodeAndData failed, code is ${err.code}`);
});
```
### isOrderedCommonEvent
```ts
isOrderedCommonEvent(callback: AsyncCallback<boolean>): void
```
Checks whether this common event is an ordered one. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | Yes | Returns **true** if the common event is an ordered one; returns **false** otherwise.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for checking whether the current common event is an ordered one.
function isOrderedCB(err, isOrdered) {
if (err.code) {
console.error(`isOrderedCommonEvent failed, code is ${err.code}`);
} else {
console.info("isOrdered " + JSON.stringify(isOrdered));
}
}
subscriber.isOrderedCommonEvent(isOrderedCB);
```
### isOrderedCommonEvent
```ts
isOrderedCommonEvent(): Promise<boolean>
```
Checks whether this common event is an ordered one. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ----------------- | -------------------------------- |
| Promise\<boolean> | Returns **true** if the common event is an ordered one; returns **false** otherwise.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.isOrderedCommonEvent().then((isOrdered) => {
console.info("isOrdered " + JSON.stringify(isOrdered));
}).catch((err) => {
console.error(`isOrderedCommonEvent failed, code is ${err.code}`);
});
```
### isStickyCommonEvent
```ts
isStickyCommonEvent(callback: AsyncCallback<boolean>): void
```
Checks whether this common event is a sticky one. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | Yes | Returns **true** if the common event is a sticky one; returns **false** otherwise.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for checking whether the current common event is a sticky one.
function isStickyCB(err, isSticky) {
if (err.code) {
console.error(`isStickyCommonEvent failed, code is ${err.code}`);
} else {
console.info("isSticky " + JSON.stringify(isSticky));
}
}
subscriber.isStickyCommonEvent(isStickyCB);
```
### isStickyCommonEvent
```ts
isStickyCommonEvent(): Promise<boolean>
```
Checks whether this common event is a sticky one. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ----------------- | -------------------------------- |
| Promise\<boolean> | Returns **true** if the common event is a sticky one; returns **false** otherwise.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.isStickyCommonEvent().then((isSticky) => {
console.info("isSticky " + JSON.stringify(isSticky));
}).catch((err) => {
console.error(`isSticky failed, code is ${err.code}`);
});
```
### abortCommonEvent
```ts
abortCommonEvent(callback: AsyncCallback<void>): void
```
Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for common event aborting.
function abortCB(err) {
if (err.code) {
console.error(`abortCommonEvent failed, code is ${err.code}`);
} else {
console.info("abortCommonEvent");
}
}
subscriber.abortCommonEvent(abortCB);
```
### abortCommonEvent
```ts
abortCommonEvent(): Promise<void>
```
Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API takes effect only for ordered common events. It uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.abortCommonEvent().then(() => {
console.info("abortCommonEvent");
}).catch((err) => {
console.error(`abortCommonEvent failed, code is ${err.code}`);
});
```
### clearAbortCommonEvent
```ts
clearAbortCommonEvent(callback: AsyncCallback<void>): void
```
Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for clearing the aborted state of the current common event.
function clearAbortCB(err) {
if (err.code) {
console.error(`clearAbortCommonEvent failed, code is ${err.code}`);
} else {
console.info("clearAbortCommonEvent");
}
}
subscriber.clearAbortCommonEvent(clearAbortCB);
```
### clearAbortCommonEvent
```ts
clearAbortCommonEvent(): Promise<void>
```
Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.clearAbortCommonEvent().then(() => {
console.info("clearAbortCommonEvent");
}).catch((err) => {
console.error(`clearAbortCommonEvent failed, code is ${err.code}`);
});
```
### getAbortCommonEvent
```ts
getAbortCommonEvent(callback: AsyncCallback<boolean>): void
```
Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | Yes | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for checking whether the current common event is in the aborted state.
function getAbortCB(err, abortEvent) {
if (err.code) {
console.error(`getAbortCommonEvent failed, code is ${err.code}`);
} else {
console.info("abortEvent " + abortEvent)
}
}
subscriber.getAbortCommonEvent(getAbortCB);
```
### getAbortCommonEvent
```ts
getAbortCommonEvent(): Promise<boolean>
```
Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ----------------- | ---------------------------------- |
| Promise\<boolean> | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.getAbortCommonEvent().then((abortCommonEvent) => {
console.info("abortCommonEvent " + JSON.stringify(abortCommonEvent));
}).catch((err) => {
console.error(`getAbortCommonEvent failed, code is ${err.code}`);
});
```
### getSubscribeInfo
```ts
getSubscribeInfo(callback: AsyncCallback<CommonEventSubscribeInfo>): void
```
Obtains the subscriber information. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ---------------------- |
| callback | AsyncCallback\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Yes | Promise used to return the subscriber information.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for subscriber information obtaining.
function getCB(err, subscribeInfo) {
if (err.code) {
console.error(`getSubscribeInfo failed, code is ${err.code}`);
} else {
console.info("SubscribeInfo " + JSON.stringify(subscribeInfo));
}
}
subscriber.getSubscribeInfo(getCB);
```
### getSubscribeInfo
```ts
getSubscribeInfo(): Promise<CommonEventSubscribeInfo>
```
Obtains the subscriber information. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ---------------------- |
| Promise\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Promise used to return the subscriber information.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.getSubscribeInfo().then((subscribeInfo) => {
console.info("subscribeInfo " + JSON.stringify(subscribeInfo));
}).catch((err) => {
console.error(`getSubscribeInfo failed, code is ${err.code}`);
});
```
### finishCommonEvent<sup>9+</sup>
```ts
finishCommonEvent(callback: AsyncCallback<void>): void
```
Finishes this common event. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback returned after the ordered common event is finished.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for ordered common event finishing.
function finishCB(err) {
if (err.code) {
console.error(`finishCommonEvent failed, code is ${err.code}`);
} else {
console.info("FinishCommonEvent");
}
}
subscriber.finishCommonEvent(finishCB);
```
### finishCommonEvent<sup>9+</sup>
```ts
finishCommonEvent(): Promise<void>
```
Finishes this common event. This API takes effect only for ordered common events. It uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.finishCommonEvent().then(() => {
console.info("FinishCommonEvent");
}).catch((err) => {
console.error(`finishCommonEvent failed, code is ${err.code}`);
});
```
## CommonEventData
Describes the common event data body.
**System capability**: SystemCapability.Notification.CommonEvent
| Name | Type | Readable| Writable| Description |
| ---------- |-------------------- | ---- | ---- | ------------------------------------------------------- |
| event | string | Yes | No | Name of the common event that is being received. |
| bundleName | string | Yes | No | Bundle name. |
| code | number | Yes | No | Result code of the common event, which is used to transfer data of the int type. |
| data | string | Yes | No | Custom result data of the common event, which is used to transfer data of the string type.|
| parameters | {[key: string]: any} | Yes | No | Additional information about the common event. |
## CommonEventPublishData
Describes the data body published by a common event, including the common event content and attributes.
**System capability**: SystemCapability.Notification.CommonEvent
| Name | Type | Readable| Writable| Description |
| --------------------- | -------------------- | ---- | ---- | ---------------------------- |
| bundleName | string | Yes | No | Bundle name. |
| code | number | Yes | No | Result code of the common event. |
| data | string | Yes | No | Custom result data of the common event.|
| subscriberPermissions | Array\<string\> | Yes | No | Permissions required for subscribers to receive the common event. |
| isOrdered | boolean | Yes | No | Whether the common event is an ordered one. |
| isSticky | boolean | Yes | No | Whether the common event is a sticky one. Only system applications and system services are allowed to send sticky events.|
| parameters | {[key: string]: any} | Yes | No | Additional information about the common event. |
## CommonEventSubscribeInfo
Provides the subscriber information.
**System capability**: SystemCapability.Notification.CommonEvent
| Name | Type | Readable| Writable| Description |
| ------------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| events | Array\<string\> | Yes | No | Name of the common event to publish. |
| publisherPermission | string | Yes | No | Permissions required for publishers to publish the common event. |
| publisherDeviceId | string | Yes | No | Device ID. The value must be the ID of an existing device on the same network. |
| userId | number | Yes | 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 | number | Yes | No | Subscriber priority. The value ranges from -100 to +1000. |
......@@ -74,7 +74,7 @@ Publishes a common event with given attributes. This API uses an asynchronous ca
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ---------------------- |
| event | string | Yes | Name of the common event to publish. |
| options | [CommonEventPublishData](#commoneventpublishdata) | Yes | Attributes of the common event to publish.|
| options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | Yes | Attributes of the common event to publish.|
| callback | syncCallback\<void> | Yes | Callback used to return the result. |
**Error codes**
......@@ -87,7 +87,7 @@ For details about the error codes, see [Event Error Codes](../errorcodes/errorco
// Attributes of a common event.
let options = {
code: 0, // Initial code of the common event.
data: "initial data";// Initial data of the common event.
data: "initial data",// Initial data of the common event.
isOrdered: true // The common event is an ordered one.
}
......@@ -173,7 +173,7 @@ Publishes a common event with given attributes to a specific user. This API uses
| -------- | ---------------------- | ---- | ---------------------- |
| event | string | Yes | Name of the common event to publish. |
| userId | number | Yes| User ID.|
| options | [CommonEventPublishData](#commoneventpublishdata) | Yes | Attributes of the common event to publish.|
| options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | Yes | Attributes of the common event to publish.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Error codes**
......@@ -187,7 +187,7 @@ For details about the error codes, see [Event Error Codes](../errorcodes/errorco
// Attributes of a common event.
let options = {
code: 0, // Initial code of the common event.
data: "initial data";// Initial data of the common event.
data: "initial data",// Initial data of the common event.
}
// Callback for common event publication.
......@@ -224,8 +224,8 @@ Creates a subscriber. This API uses an asynchronous callback to return the resul
| Name | Type | Mandatory| Description |
| ------------- | ------------------------------------------------------------ | ---- | -------------------------- |
| subscribeInfo | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | Yes | Subscriber information. |
| callback | AsyncCallback\<[CommonEventSubscriber](#commoneventsubscriber)> | Yes | Callback used to return the result.|
| subscribeInfo | [CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md) | Yes | Subscriber information. |
| callback | AsyncCallback\<[CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md)> | Yes | Callback used to return the result.|
**Example**
......@@ -270,12 +270,12 @@ Creates a subscriber. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| ------------- | ----------------------------------------------------- | ---- | -------------- |
| subscribeInfo | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | Yes | Subscriber information.|
| subscribeInfo | [CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md) | Yes | Subscriber information.|
**Return value**
| Type | Description |
| --------------------------------------------------------- | ---------------- |
| Promise\<[CommonEventSubscriber](#commoneventsubscriber)> | Promise used to return the subscriber object.|
| Promise\<[CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md)> | Promise used to return the subscriber object.|
**Example**
......@@ -311,8 +311,8 @@ Subscribes to common events. This API uses an asynchronous callback to return th
| Name | Type | Mandatory| Description |
| ---------- | ---------------------------------------------------- | ---- | -------------------------------- |
| subscriber | [CommonEventSubscriber](#commoneventsubscriber) | Yes | Subscriber object. |
| callback | AsyncCallback\<[CommonEventData](#commoneventdata)> | Yes | Callback used to return the result.|
| subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md) | Yes | Subscriber object. |
| callback | AsyncCallback\<[CommonEventData](./js-apis-inner-commonEvent-commonEventData.md)> | Yes | Callback used to return the result.|
**Example**
......@@ -335,9 +335,10 @@ function SubscribeCB(err, data) {
}
// Callback for subscriber creation.
function createCB(err, subscriber) {
function createCB(err, commonEventSubscriber) {
if(!err) {
console.info("createSubscriber");
subscriber = commonEventSubscriber;
// Subscribe to a common event.
try {
CommonEventManager.subscribe(subscriber, SubscribeCB);
......@@ -371,7 +372,7 @@ Unsubscribes from common events. This API uses an asynchronous callback to retur
| Name | Type | Mandatory| Description |
| ---------- | ----------------------------------------------- | ---- | ------------------------ |
| subscriber | [CommonEventSubscriber](#commoneventsubscriber) | Yes | Subscriber object. |
| subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md) | Yes | Subscriber object. |
| callback | AsyncCallback\<void> | No | Callback used to return the result.|
**Example**
......@@ -391,11 +392,12 @@ function subscribeCB(err, data) {
}
}
// Callback for subscriber creation.
function createCB(err, subscriber) {
function createCB(err, commonEventSubscriber) {
if (err) {
console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("createSubscriber");
subscriber = commonEventSubscriber;
// Subscribe to a common event.
try {
CommonEventManager.subscribe(subscriber, subscribeCB);
......@@ -426,785 +428,3 @@ try {
console.error(`unsubscribe failed, code is ${err.code}, message is ${err.message}`);
}
```
## CommonEventSubscriber
### getCode
```ts
getCode(callback: AsyncCallback<number>): void
```
Obtains the code of this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------ |
| callback | AsyncCallback\<number\> | Yes | Common event code.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for code obtaining of an ordered common event.
function getCodeCB(err, code) {
if (err.code) {
console.error(`getCode failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("getCode " + JSON.stringify(code));
}
}
subscriber.getCode(getCodeCB);
```
### getCode
```ts
getCode(): Promise<number>
```
Obtains the code of this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<number> | Common event code.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.getCode().then((code) => {
console.info("getCode " + JSON.stringify(code));
}).catch((err) => {
console.error(`getCode failed, code is ${err.code}, message is ${err.message}`);
});
```
### setCode
```ts
setCode(code: number, callback: AsyncCallback<void>): void
```
Sets the code for this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------- |
| code | number | Yes | Common event code. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for code setting of an ordered common event.
function setCodeCB(err) {
if (err.code) {
console.error(`setCode failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("setCode");
}
}
subscriber.setCode(1, setCodeCB);
```
### setCode
```ts
setCode(code: number): Promise<void>
```
Sets the code for this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| code | number | Yes | Common event code.|
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.setCode(1).then(() => {
console.info("setCode");
}).catch((err) => {
console.error(`setCode failed, code is ${err.code}, message is ${err.message}`);
});
```
### getData
```ts
getData(callback: AsyncCallback<string>): void
```
Obtains the data of this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<string> | Yes | Common event data.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for data obtaining of an ordered common event.
function getDataCB(err, data) {
if (err.code) {
console.error(`getData failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("getData " + JSON.stringify(data));
}
}
subscriber.getData(getDataCB);
```
### getData
```ts
getData(): Promise<string>
```
Obtains the data of this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | ------------------ |
| Promise\<string> | Common event data.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.getData().then((data) => {
console.info("getData " + JSON.stringify(data));
}).catch((err) => {
console.error(`getData failed, code is ${err.code}, message is ${err.message}`);
});
```
### setData
setData(data: string, callback: AsyncCallback\<void>): void
Sets the data for this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| data | string | Yes | Common event data. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for result data setting of an ordered common event
function setDataCB(err) {
if (err.code) {
console.error(`setCode failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("setData");
}
}
subscriber.setData("publish_data_changed", setDataCB);
```
### setData
```ts
setData(data: string): Promise<void>
```
Sets the data for this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------- |
| data | string | Yes | Common event data.|
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.setData("publish_data_changed").then(() => {
console.info("setData");
}).catch((err) => {
console.error(`setCode failed, code is ${err.code}, message is ${err.message}`);
});
```
### setCodeAndData
```ts
setCodeAndData(code: number, data: string, callback:AsyncCallback<void>): void
```
Sets the code and data for this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------- |
| code | number | Yes | Common event code. |
| data | string | Yes | Common event data. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for code and data setting of an ordered common event.
function setCodeDataCB(err) {
if (err.code) {
console.error(`setCodeAndData failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("setCodeDataCallback");
}
}
subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCB);
```
### setCodeAndData
```ts
setCodeAndData(code: number, data: string): Promise<void>
```
Sets the code and data for this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------- |
| code | number | Yes | Common event code.|
| data | string | Yes | Common event data.|
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.setCodeAndData(1, "publish_data_changed").then(() => {
console.info("setCodeAndData");
}).catch((err) => {
console.error(`setCodeAndData failed, code is ${err.code}, message is ${err.message}`);
});
```
### isOrderedCommonEvent
```ts
isOrderedCommonEvent(callback: AsyncCallback<boolean>): void
```
Checks whether this common event is an ordered one. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. The value **true** means that the common event is an ordered one; and **false** means the opposite.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for checking whether the current common event is an ordered one.
function isOrderedCB(err, isOrdered) {
if (err.code) {
console.error(`isOrderedCommonEvent failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("isOrdered " + JSON.stringify(isOrdered));
}
}
subscriber.isOrderedCommonEvent(isOrderedCB);
```
### isOrderedCommonEvent
```ts
isOrderedCommonEvent(): Promise<boolean>
```
Checks whether this common event is an ordered one. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ----------------- | -------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the common event is an ordered one; and **false** means the opposite.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.isOrderedCommonEvent().then((isOrdered) => {
console.info("isOrdered " + JSON.stringify(isOrdered));
}).catch((err) => {
console.error(`isOrdered failed, code is ${err.code}, message is ${err.message}`);
});
```
### isStickyCommonEvent
```ts
isStickyCommonEvent(callback: AsyncCallback<boolean>): void
```
Checks whether this common event is a sticky one. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. The value **true** means that the common event is a sticky one; and **false** means the opposite.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for checking whether the current common event is a sticky one.
function isStickyCB(err, isSticky) {
if (err.code) {
console.error(`isStickyCommonEvent failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("isSticky " + JSON.stringify(isSticky));
}
}
subscriber.isStickyCommonEvent(isStickyCB);
```
### isStickyCommonEvent
```ts
isStickyCommonEvent(): Promise<boolean>
```
Checks whether this common event is a sticky one. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ----------------- | -------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the common event is a sticky one; and **false** means the opposite.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.isStickyCommonEvent().then((isSticky) => {
console.info("isSticky " + JSON.stringify(isSticky));
}).catch((err) => {
console.error(`isSticky failed, code is ${err.code}, message is ${err.message}`);
});
```
### abortCommonEvent
```ts
abortCommonEvent(callback: AsyncCallback<void>): void
```
Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for common event aborting.
function abortCB(err) {
if (err.code) {
console.error(`abortCommonEvent failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("abortCommonEvent");
}
}
subscriber.abortCommonEvent(abortCB);
```
### abortCommonEvent
```ts
abortCommonEvent(): Promise<void>
```
Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API takes effect only for ordered common events. It uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.abortCommonEvent().then(() => {
console.info("abortCommonEvent");
}).catch((err) => {
console.error(`abortCommonEvent failed, code is ${err.code}, message is ${err.message}`);
});
```
### clearAbortCommonEvent
```ts
clearAbortCommonEvent(callback: AsyncCallback<void>): void
```
Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for clearing the aborted state of the current common event.
function clearAbortCB(err) {
if (err.code) {
console.error(`clearAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("clearAbortCommonEvent");
}
}
subscriber.clearAbortCommonEvent(clearAbortCB);
```
### clearAbortCommonEvent
```ts
clearAbortCommonEvent(): Promise<void>
```
Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.clearAbortCommonEvent().then(() => {
console.info("clearAbortCommonEvent");
}).catch((err) => {
console.error(`clearAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`);
});
```
### getAbortCommonEvent
```ts
getAbortCommonEvent(callback: AsyncCallback<boolean>): void
```
Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. The value **true** means that the ordered common event is in the aborted state; and **false** means the opposite.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for checking whether the current common event is in the aborted state.
function getAbortCB(err, abortEvent) {
if (err.code) {
console.error(`getAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("abortCommonEvent " + abortEvent)
}
}
subscriber.getAbortCommonEvent(getAbortCB);
```
### getAbortCommonEvent
```ts
getAbortCommonEvent(): Promise<boolean>
```
Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ----------------- | ---------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the ordered common event is in the aborted state; and **false** means the opposite.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.getAbortCommonEvent().then((abortEvent) => {
console.info("abortCommonEvent " + JSON.stringify(abortEvent));
}).catch((err) => {
console.error(`getAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`);
});
```
### getSubscribeInfo
```ts
getSubscribeInfo(callback: AsyncCallback<CommonEventSubscribeInfo>): void
```
Obtains the subscriber information. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ---------------------- |
| callback | AsyncCallback\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Yes | Callback used to return the subscriber information.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for subscriber information obtaining.
function getCB(err, subscribeInfo) {
if (err.code) {
console.error(`getSubscribeInfo failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("subscribeInfo " + JSON.stringify(subscribeInfo));
}
}
subscriber.getSubscribeInfo(getCB);
```
### getSubscribeInfo
```ts
getSubscribeInfo(): Promise<CommonEventSubscribeInfo>
```
Obtains the subscriber information. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ---------------------- |
| Promise\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | Promise used to return the subscriber information.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.getSubscribeInfo().then((subscribeInfo) => {
console.info("subscribeInfo " + JSON.stringify(subscribeInfo));
}).catch((err) => {
console.error(`getSubscribeInfo failed, code is ${err.code}, message is ${err.message}`);
});
```
### finishCommonEvent<sup>9+</sup>
```ts
finishCommonEvent(callback: AsyncCallback<void>): void
```
Finishes this common event. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback returned after the ordered common event is finished.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for ordered common event finishing.
function finishCB(err) {
if (err.code) {
console.error(`finishCommonEvent failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("FinishCommonEvent");
}
subscriber.finishCommonEvent(finishCB);
```
### finishCommonEvent<sup>9+</sup>
```ts
finishCommonEvent(): Promise<void\>
```
Finishes this common event. This API takes effect only for ordered common events. It uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.finishCommonEvent().then(() => {
console.info("FinishCommonEvent");
}).catch((err) => {
console.error(`finishCommonEvent failed, code is ${err.code}, message is ${err.message}`);
});
```
## CommonEventData
**System capability**: SystemCapability.Notification.CommonEvent
| Name | Type | Readable| Writable| Description |
| ---------- |-------------------- | ---- | ---- | ------------------------------------------------------- |
| event | string | Yes | No | Name of the common event that is being received. |
| bundleName | string | Yes | No | Bundle name. |
| code | number | Yes | No | Code of the common event, which is used to transfer data of the int type. |
| data | string | Yes | No | Custom data of the common event, which is used to transfer data of the string type.|
| parameters | {[key: string]: any} | Yes | No | Additional information about the common event. |
## CommonEventPublishData
**System capability**: SystemCapability.Notification.CommonEvent
| Name | Type | Readable| Writable| Description |
| --------------------- | -------------------- | ---- | ---- | ---------------------------- |
| bundleName | string | Yes | No | Bundle name. |
| code | number | Yes | No | Code of the common event. |
| data | string | Yes | No | Custom data of the common event.|
| subscriberPermissions | Array\<string> | Yes | No | Permissions required for subscribers to receive the common event. |
| isOrdered | boolean | Yes | No | Whether the common event is an ordered one. |
| isSticky | boolean | Yes | No | Whether the common event is a sticky one. Only system applications and system services are allowed to send sticky events.|
| parameters | {[key: string]: any} | Yes | No | Additional information about the common event. |
## CommonEventSubscribeInfo
**System capability**: SystemCapability.Notification.CommonEvent
| Name | Type | Readable| Writable| Description |
| ------------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| events | Array\<string> | Yes | No | Name of the common event to publish. |
| publisherPermission | string | Yes | No | Permissions required for publishers to publish the common event. |
| publisherDeviceId | string | Yes | No | Device ID. The value must be the ID of an existing device on the same network. |
| userId | number | Yes | 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 | number | Yes | No | Subscriber priority. The value ranges from -100 to +1000. |
# CommonEventData
**System capability**: SystemCapability.Notification.CommonEvent
| Name | Type | Readable| Writable| Description |
| ---------- |-------------------- | ---- | ---- | ------------------------------------------------------- |
| event | string | Yes | No | Name of the common event that is being received. |
| bundleName | string | Yes | No | Bundle name. |
| code | number | Yes | No | Result code of the common event, which is used to transfer data of the int type. |
| data | string | Yes | No | Custom result data of the common event, which is used to transfer data of the string type.|
| parameters | {[key: string]: any} | Yes | No | Additional information about the common event. |
# CommonEventPublishData
**System capability**: SystemCapability.Notification.CommonEvent
| Name | Type | Readable| Writable| Description |
| --------------------- | -------------------- | ---- | ---- | ---------------------------- |
| bundleName | string | Yes | No | Bundle name. |
| code | number | Yes | No | Result code of the common event. |
| data | string | Yes | No | Custom result data of the common event.|
| subscriberPermissions | Array\<string> | Yes | No | Permissions required for subscribers to receive the common event. |
| isOrdered | boolean | Yes | No | Whether the common event is an ordered one. |
| isSticky | boolean | Yes | No | Whether the common event is a sticky one. Only system applications and system services are allowed to send sticky events.|
| parameters | {[key: string]: any} | Yes | No | Additional information about the common event. |
# CommonEventSubscribeInfo
**System capability**: SystemCapability.Notification.CommonEvent
| Name | Type | Readable| Writable| Description |
| ------------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| events | Array\<string> | Yes | No | Name of the common event to publish. |
| publisherPermission | string | Yes | No | Permissions required for publishers to publish the common event. |
| publisherDeviceId | string | Yes | No | Device ID. The value must be the ID of a device on the same network. |
| userId | number | Yes | No | User ID. The value must be an existing user ID in the system. If this parameter is not specified, the default value, which is the ID of the current user, will be used. |
| priority | number | Yes | No | Subscriber priority. The value ranges from –100 to +1000. |
# CommonEventSubscriber
## getCode
```ts
getCode(callback: AsyncCallback<number>): void
```
Obtains the code of this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------ |
| callback | AsyncCallback\<number\> | Yes | Common event code.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for result code obtaining of an ordered common event.
function getCodeCB(err, code) {
if (err.code) {
console.error(`getCode failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("getCode " + JSON.stringify(code));
}
}
subscriber.getCode(getCodeCB);
```
## getCode
```ts
getCode(): Promise<number>
```
Obtains the code of this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<number> | Common event code.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.getCode().then((code) => {
console.info("getCode " + JSON.stringify(code));
}).catch((err) => {
console.error(`getCode failed, code is ${err.code}, message is ${err.message}`);
});
```
## setCode
```ts
setCode(code: number, callback: AsyncCallback<void>): void
```
Sets the code for this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------- |
| code | number | Yes | Common event code. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for result code setting of an ordered common event.
function setCodeCB(err) {
if (err.code) {
console.error(`setCode failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("setCode");
}
}
subscriber.setCode(1, setCodeCB);
```
## setCode
```ts
setCode(code: number): Promise<void>
```
Sets the code for this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| code | number | Yes | Common event code.|
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.setCode(1).then(() => {
console.info("setCode");
}).catch((err) => {
console.error(`setCode failed, code is ${err.code}, message is ${err.message}`);
});
```
## getData
```ts
getData(callback: AsyncCallback<string>): void
```
Obtains the data of this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<string> | Yes | Common event data.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for result data obtaining of an ordered common event.
function getDataCB(err, data) {
if (err.code) {
console.error(`getData failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("getData " + JSON.stringify(data));
}
}
subscriber.getData(getDataCB);
```
## getData
```ts
getData(): Promise<string>
```
Obtains the data of this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | ------------------ |
| Promise\<string> | Common event data.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.getData().then((data) => {
console.info("getData " + JSON.stringify(data));
}).catch((err) => {
console.error(`getData failed, code is ${err.code}, message is ${err.message}`);
});
```
## setData
setData(data: string, callback: AsyncCallback\<void>): void
Sets the data for this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| data | string | Yes | Common event data. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for result data setting of an ordered common event
function setDataCB(err) {
if (err.code) {
console.error(`setCode failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("setData");
}
}
subscriber.setData("publish_data_changed", setDataCB);
```
## setData
```ts
setData(data: string): Promise<void>
```
Sets the data for this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------- |
| data | string | Yes | Common event data.|
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.setData("publish_data_changed").then(() => {
console.info("setData");
}).catch((err) => {
console.error(`setCode failed, code is ${err.code}, message is ${err.message}`);
});
```
## setCodeAndData
```ts
setCodeAndData(code: number, data: string, callback:AsyncCallback<void>): void
```
Sets the code and data for this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------- |
| code | number | Yes | Common event code. |
| data | string | Yes | Common event data. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for code and data setting of an ordered common event.
function setCodeDataCB(err) {
if (err.code) {
console.error(`setCodeAndData failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("setCodeDataCallback");
}
}
subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCB);
```
## setCodeAndData
```ts
setCodeAndData(code: number, data: string): Promise<void>
```
Sets the code and data for this common event. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------- |
| code | number | Yes | Common event code.|
| data | string | Yes | Common event data.|
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.setCodeAndData(1, "publish_data_changed").then(() => {
console.info("setCodeAndData");
}).catch((err) => {
console.error(`setCodeAndData failed, code is ${err.code}, message is ${err.message}`);
});
```
## isOrderedCommonEvent
```ts
isOrderedCommonEvent(callback: AsyncCallback<boolean>): void
```
Checks whether this common event is an ordered one. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | Yes | Returns **true** if the common event is an ordered one; returns **false** otherwise.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for checking whether the current common event is an ordered one.
function isOrderedCB(err, isOrdered) {
if (err.code) {
console.error(`isOrderedCommonEvent failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("isOrdered " + JSON.stringify(isOrdered));
}
}
subscriber.isOrderedCommonEvent(isOrderedCB);
```
## isOrderedCommonEvent
```ts
isOrderedCommonEvent(): Promise<boolean>
```
Checks whether this common event is an ordered one. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ----------------- | -------------------------------- |
| Promise\<boolean> | Returns **true** if the common event is an ordered one; returns **false** otherwise.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.isOrderedCommonEvent().then((isOrdered) => {
console.info("isOrdered " + JSON.stringify(isOrdered));
}).catch((err) => {
console.error(`isOrdered failed, code is ${err.code}, message is ${err.message}`);
});
```
## isStickyCommonEvent
```ts
isStickyCommonEvent(callback: AsyncCallback<boolean>): void
```
Checks whether this common event is a sticky one. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | Yes | Returns **true** if the common event is a sticky one; returns **false** otherwise.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for checking whether the current common event is a sticky one.
function isStickyCB(err, isSticky) {
if (err.code) {
console.error(`isStickyCommonEvent failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("isSticky " + JSON.stringify(isSticky));
}
}
subscriber.isStickyCommonEvent(isStickyCB);
```
## isStickyCommonEvent
```ts
isStickyCommonEvent(): Promise<boolean>
```
Checks whether this common event is a sticky one. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ----------------- | -------------------------------- |
| Promise\<boolean> | Returns **true** if the common event is a sticky one; returns **false** otherwise.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.isStickyCommonEvent().then((isSticky) => {
console.info("isSticky " + JSON.stringify(isSticky));
}).catch((err) => {
console.error(`isSticky failed, code is ${err.code}, message is ${err.message}`);
});
```
## abortCommonEvent
```ts
abortCommonEvent(callback: AsyncCallback<void>): void
```
Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for common event aborting.
function abortCB(err) {
if (err.code) {
console.error(`abortCommonEvent failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("abortCommonEvent");
}
}
subscriber.abortCommonEvent(abortCB);
```
## abortCommonEvent
```ts
abortCommonEvent(): Promise<void>
```
Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API takes effect only for ordered common events. It uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.abortCommonEvent().then(() => {
console.info("abortCommonEvent");
}).catch((err) => {
console.error(`abortCommonEvent failed, code is ${err.code}, message is ${err.message}`);
});
```
## clearAbortCommonEvent
```ts
clearAbortCommonEvent(callback: AsyncCallback<void>): void
```
Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for clearing the aborted state of the current common event.
function clearAbortCB(err) {
if (err.code) {
console.error(`clearAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("clearAbortCommonEvent");
}
}
subscriber.clearAbortCommonEvent(clearAbortCB);
```
## clearAbortCommonEvent
```ts
clearAbortCommonEvent(): Promise<void>
```
Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.clearAbortCommonEvent().then(() => {
console.info("clearAbortCommonEvent");
}).catch((err) => {
console.error(`clearAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`);
});
```
## getAbortCommonEvent
```ts
getAbortCommonEvent(callback: AsyncCallback<boolean>): void
```
Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | Yes | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for checking whether the current common event is in the aborted state.
function getAbortCB(err, abortEvent) {
if (err.code) {
console.error(`getAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("abortCommonEvent " + abortEvent)
}
}
subscriber.getAbortCommonEvent(getAbortCB);
```
## getAbortCommonEvent
```ts
getAbortCommonEvent(): Promise<boolean>
```
Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ----------------- | ---------------------------------- |
| Promise\<boolean> | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.getAbortCommonEvent().then((abortEvent) => {
console.info("abortCommonEvent " + JSON.stringify(abortEvent));
}).catch((err) => {
console.error(`getAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`);
});
```
## getSubscribeInfo
```ts
getSubscribeInfo(callback: AsyncCallback<CommonEventSubscribeInfo>): void
```
Obtains the subscriber information. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ---------------------- |
| callback | AsyncCallback\<[CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md)> | Yes | Callback used to return the subscriber information.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for subscriber information obtaining.
function getCB(err, subscribeInfo) {
if (err.code) {
console.error(`getSubscribeInfo failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("subscribeInfo " + JSON.stringify(subscribeInfo));
}
}
subscriber.getSubscribeInfo(getCB);
```
## getSubscribeInfo
```ts
getSubscribeInfo(): Promise<CommonEventSubscribeInfo>
```
Obtains the subscriber information. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ---------------------- |
| Promise\<[CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md)> | Promise used to return the subscriber information.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.getSubscribeInfo().then((subscribeInfo) => {
console.info("subscribeInfo " + JSON.stringify(subscribeInfo));
}).catch((err) => {
console.error(`getSubscribeInfo failed, code is ${err.code}, message is ${err.message}`);
});
```
## finishCommonEvent<sup>9+</sup>
```ts
finishCommonEvent(callback: AsyncCallback<void>): void
```
Finishes this common event. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback returned after the ordered common event is finished.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
// Callback for ordered common event finishing.
function finishCB(err) {
if (err.code) {
console.error(`finishCommonEvent failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("FinishCommonEvent");
}
subscriber.finishCommonEvent(finishCB);
```
## finishCommonEvent<sup>9+</sup>
```ts
finishCommonEvent(): Promise<void\>
```
Finishes this common event. This API takes effect only for ordered common events. It uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```ts
let subscriber; // Subscriber object successfully created.
subscriber.finishCommonEvent().then(() => {
console.info("FinishCommonEvent");
}).catch((err) => {
console.error(`finishCommonEvent failed, code is ${err.code}, message is ${err.message}`);
});
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册