提交 56c5ca95 编写于 作者: E esterzhou

update docs (9357)

Signed-off-by: Nesterzhou <ester.zhou@huawei.com>
上级 370c8642
...@@ -32,7 +32,8 @@ import commonEvent from '@ohos.commonEvent'; ...@@ -32,7 +32,8 @@ import commonEvent from '@ohos.commonEvent';
2. Create a **subscribeInfo** object. For details about the data types and parameters of the object, see [CommonEventSubscribeInfo](../reference/apis/js-apis-commonEvent.md#commoneventsubscribeinfo). 2. Create a **subscribeInfo** object. For details about the data types and parameters of the object, see [CommonEventSubscribeInfo](../reference/apis/js-apis-commonEvent.md#commoneventsubscribeinfo).
```js ```js
private subscriber = null // Used to save the created subscriber object for subsequent subscription and unsubscription. // Used to save the created subscriber object for subsequent subscription and unsubscription.
private subscriber = null
// Subscriber information // Subscriber information
var subscribeInfo = { var subscribeInfo = {
......
# Common Event and Notification Overview # Common Event and Notification Overview
The common event and notification module enables applications to publish messages to other applications, and receive messages from the system or other applications. These messages can be news push messages, advertisement notifications, or warning information. The common event and notification module enables applications to publish messages to other applications, and receive messages from the system or other applications. These messages can be news push messages, advertisement notifications, warning information, and more.
Common Event Service (CES) enables applications to publish, subscribe to, and unsubscribe from common events. Based on the sender type, common events are classified into system common events and custom common events. Common Event Service (CES) enables applications to publish, subscribe to, and unsubscribe from common events. Based on the sender type, common events are classified into system common events and custom common events.
......
...@@ -18,7 +18,7 @@ Provides the event types supported by the **CommonEvent** module. The name and v ...@@ -18,7 +18,7 @@ Provides the event types supported by the **CommonEvent** module. The name and v
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
| Name | Value | Subscriber Permission | Description | | Name | Value | Subscriber Permission | Description |
| ------------ | ------------------ | ---------------------- | -------------------- | | ------------ | ------------------ | ---------------------- | -------------------- |
| COMMON_EVENT_BOOT_COMPLETED | usual.event.BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the user has finished booting and the system has been loaded. | | COMMON_EVENT_BOOT_COMPLETED | usual.event.BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the user has finished booting and the system has been loaded. |
| COMMON_EVENT_LOCKED_BOOT_COMPLETED | usual.event.LOCKED_BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the user has finished booting and the system has been loaded but the screen is still locked. | | COMMON_EVENT_LOCKED_BOOT_COMPLETED | usual.event.LOCKED_BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the user has finished booting and the system has been loaded but the screen is still locked. |
...@@ -152,17 +152,17 @@ Provides the event types supported by the **CommonEvent** module. The name and v ...@@ -152,17 +152,17 @@ Provides the event types supported by the **CommonEvent** module. The name and v
| COMMON_EVENT_USB_DEVICE_DETACHED | usual.event.hardware.usb.action.USB_DEVICE_DETACHED | - | Indicates the common event that a USB device has been detached when the user device functions as a USB host. | | COMMON_EVENT_USB_DEVICE_DETACHED | usual.event.hardware.usb.action.USB_DEVICE_DETACHED | - | Indicates the common event that a USB device has been detached when the user device functions as a USB host. |
| COMMON_EVENT_USB_ACCESSORY_ATTACHED | usual.event.hardware.usb.action.USB_ACCESSORY_ATTACHED | - | Indicates the common event that a USB accessory was attached. | | COMMON_EVENT_USB_ACCESSORY_ATTACHED | usual.event.hardware.usb.action.USB_ACCESSORY_ATTACHED | - | Indicates the common event that a USB accessory was attached. |
| COMMON_EVENT_USB_ACCESSORY_DETACHED | usual.event.hardware.usb.action.USB_ACCESSORY_DETACHED | - | Indicates the common event that a USB accessory was detached. | | COMMON_EVENT_USB_ACCESSORY_DETACHED | usual.event.hardware.usb.action.USB_ACCESSORY_DETACHED | - | Indicates the common event that a USB accessory was detached. |
| COMMON_EVENT_DISK_REMOVED | usual.event.data.DISK_REMOVED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was removed. | | COMMON_EVENT_DISK_REMOVED | usual.event.data.DISK_REMOVED | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was removed. |
| COMMON_EVENT_DISK_UNMOUNTED | usual.event.data.DISK_UNMOUNTED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was unmounted. | | COMMON_EVENT_DISK_UNMOUNTED | usual.event.data.DISK_UNMOUNTED | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was unmounted. |
| COMMON_EVENT_DISK_MOUNTED | usual.event.data.DISK_MOUNTED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was mounted. | | COMMON_EVENT_DISK_MOUNTED | usual.event.data.DISK_MOUNTED | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was mounted. |
| COMMON_EVENT_DISK_BAD_REMOVAL | usual.event.data.DISK_BAD_REMOVAL | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was removed without being unmounted. | | COMMON_EVENT_DISK_BAD_REMOVAL | usual.event.data.DISK_BAD_REMOVAL | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was removed without being unmounted. |
| COMMON_EVENT_DISK_UNMOUNTABLE | usual.event.data.DISK_UNMOUNTABLE | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device becomes unmountable. | | COMMON_EVENT_DISK_UNMOUNTABLE | usual.event.data.DISK_UNMOUNTABLE | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device becomes unmountable. |
| COMMON_EVENT_DISK_EJECT | usual.event.data.DISK_EJECT | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was ejected. | | COMMON_EVENT_DISK_EJECT | usual.event.data.DISK_EJECT | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was ejected. |
| COMMON_EVENT_VOLUME_REMOVED<sup>9+<sup> | usual.event.data.VOLUME_REMOVED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was removed. | | COMMON_EVENT_VOLUME_REMOVED<sup>9+<sup> | usual.event.data.VOLUME_REMOVED | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was removed. |
| COMMON_EVENT_VOLUME_UNMOUNTED<sup>9+<sup> | usual.event.data.VOLUME_UNMOUNTED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was unmounted. | | COMMON_EVENT_VOLUME_UNMOUNTED<sup>9+<sup> | usual.event.data.VOLUME_UNMOUNTED | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was unmounted. |
| COMMON_EVENT_VOLUME_MOUNTED<sup>9+<sup> | usual.event.data.VOLUME_MOUNTED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was mounted. | | COMMON_EVENT_VOLUME_MOUNTED<sup>9+<sup> | usual.event.data.VOLUME_MOUNTED | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was mounted. |
| COMMON_EVENT_VOLUME_BAD_REMOVAL<sup>9+<sup> | usual.event.data.VOLUME_BAD_REMOVAL | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was removed without being unmounted. | | COMMON_EVENT_VOLUME_BAD_REMOVAL<sup>9+<sup> | usual.event.data.VOLUME_BAD_REMOVAL | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was removed without being unmounted. |
| COMMON_EVENT_VOLUME_EJECT<sup>9+<sup> | usual.event.data.VOLUME_EJECT | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE| Indicates the common event that an external storage device was ejected. | | COMMON_EVENT_VOLUME_EJECT<sup>9+<sup> | usual.event.data.VOLUME_EJECT | ohos.permission.STORAGE_MANAGER | Indicates the common event that an external storage device was ejected. |
| COMMON_EVENT_VISIBLE_ACCOUNTS_UPDATED | usual.event.data.VISIBLE_ACCOUNTS_UPDATED | ohos.permission.GET_APP_ACCOUNTS | Indicates the common event that the account visibility changed. | | COMMON_EVENT_VISIBLE_ACCOUNTS_UPDATED | usual.event.data.VISIBLE_ACCOUNTS_UPDATED | ohos.permission.GET_APP_ACCOUNTS | Indicates the common event that the account visibility changed. |
| COMMON_EVENT_ACCOUNT_DELETED | usual.event.data.ACCOUNT_DELETED | ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS | Indicates the common event that the account was deleted. | | COMMON_EVENT_ACCOUNT_DELETED | usual.event.data.ACCOUNT_DELETED | ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS | Indicates the common event that the account was deleted. |
| COMMON_EVENT_FOUNDATION_READY | usual.event.data.FOUNDATION_READY | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the foundation is ready. | | COMMON_EVENT_FOUNDATION_READY | usual.event.data.FOUNDATION_READY | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the foundation is ready. |
...@@ -170,13 +170,14 @@ Provides the event types supported by the **CommonEvent** module. The name and v ...@@ -170,13 +170,14 @@ Provides the event types supported by the **CommonEvent** module. The name and v
| COMMON_EVENT_SPLIT_SCREEN<sup>8+<sup> | usual.event.SPLIT_SCREEN | ohos.permission.RECEIVER_SPLIT_SCREEN | Indicates the common event of screen splitting. | | COMMON_EVENT_SPLIT_SCREEN<sup>8+<sup> | usual.event.SPLIT_SCREEN | ohos.permission.RECEIVER_SPLIT_SCREEN | Indicates the common event of screen splitting. |
| COMMON_EVENT_SLOT_CHANGE<sup>9+<sup> | usual.event.SLOT_CHANGE | ohos.permission.NOTIFICATION_CONTROLLER | Indicates the common event that the notification slot has changed. | | COMMON_EVENT_SLOT_CHANGE<sup>9+<sup> | usual.event.SLOT_CHANGE | ohos.permission.NOTIFICATION_CONTROLLER | Indicates the common event that the notification slot has changed. |
| COMMON_EVENT_SPN_INFO_CHANGED <sup>9+<sup> | usual.event.SPN_INFO_CHANGED | - | Indicates the common event that the SPN displayed has been updated. | | COMMON_EVENT_SPN_INFO_CHANGED <sup>9+<sup> | usual.event.SPN_INFO_CHANGED | - | Indicates the common event that the SPN displayed has been updated. |
| COMMON_EVENT_QUICK_FIX_APPLY_RESULT <sup>9+<sup> | usual.event.QUICK_FIX_APPLY_RESULT | - | Indicates the common event that a quick fix is applied to the application. |
## CommonEvent.publish ## CommonEvent.publish
publish(event: string, callback: AsyncCallback\<void>): void publish(event: string, callback: AsyncCallback\<void>): void
Publishes a common event. This API uses a callback to return the result. Publishes a common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -209,7 +210,7 @@ CommonEvent.publish("event", PublishCallBack); ...@@ -209,7 +210,7 @@ CommonEvent.publish("event", PublishCallBack);
publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\<void>): void publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\<void>): void
Publishes a common event with given attributes. This API uses a callback to return the result. Publishes a common event with given attributes. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -226,7 +227,7 @@ Publishes a common event with given attributes. This API uses a callback to retu ...@@ -226,7 +227,7 @@ Publishes a common event with given attributes. This API uses a callback to retu
```js ```js
// Attributes of a common event. // Attributes of a common event.
var options = { let options = {
code: 0, // Result code of the common event. code: 0, // Result code of the common event.
data: "initial data";// Result data of the common event. data: "initial data";// Result data of the common event.
isOrdered: true // The common event is an ordered one. isOrdered: true // The common event is an ordered one.
...@@ -251,7 +252,7 @@ CommonEvent.publish("event", options, PublishCallBack); ...@@ -251,7 +252,7 @@ CommonEvent.publish("event", options, PublishCallBack);
publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): void publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): void
Publishes a common event to a specific user. This API uses a callback to return the result. Publishes a common event to a specific user. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -278,7 +279,7 @@ function PublishAsUserCallBack(err) { ...@@ -278,7 +279,7 @@ function PublishAsUserCallBack(err) {
} }
// Specify the user to whom the common event will be published. // Specify the user to whom the common event will be published.
var userId = 100; let userId = 100;
// Publish a common event. // Publish a common event.
CommonEvent.publishAsUser("event", userId, PublishAsUserCallBack); CommonEvent.publishAsUser("event", userId, PublishAsUserCallBack);
...@@ -290,7 +291,7 @@ CommonEvent.publishAsUser("event", userId, PublishAsUserCallBack); ...@@ -290,7 +291,7 @@ CommonEvent.publishAsUser("event", userId, PublishAsUserCallBack);
publishAsUser(event: string, userId: number, options: CommonEventPublishData, callback: AsyncCallback\<void>): void publishAsUser(event: string, userId: number, options: CommonEventPublishData, callback: AsyncCallback\<void>): void
Publishes a common event with given attributes to a specific user. This API uses a callback to return the result. Publishes a common event with given attributes to a specific user. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -310,9 +311,9 @@ Publishes a common event with given attributes to a specific user. This API uses ...@@ -310,9 +311,9 @@ Publishes a common event with given attributes to a specific user. This API uses
```js ```js
// Attributes of a common event. // Attributes of a common event.
var options = { let options = {
code: 0, // Result code of the common event. code: 0, // Result code of the common event.
data: "initial data";// Result data of the common event data: "initial data";// Result data of the common event.
} }
// Callback for common event publication // Callback for common event publication
...@@ -325,7 +326,7 @@ function PublishAsUserCallBack(err) { ...@@ -325,7 +326,7 @@ function PublishAsUserCallBack(err) {
} }
// Specify the user to whom the common event will be published. // Specify the user to whom the common event will be published.
var userId = 100; let userId = 100;
// Publish a common event. // Publish a common event.
CommonEvent.publishAsUser("event", userId, options, PublishAsUserCallBack); CommonEvent.publishAsUser("event", userId, options, PublishAsUserCallBack);
...@@ -337,7 +338,7 @@ CommonEvent.publishAsUser("event", userId, options, PublishAsUserCallBack); ...@@ -337,7 +338,7 @@ CommonEvent.publishAsUser("event", userId, options, PublishAsUserCallBack);
createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback\<CommonEventSubscriber>): void createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback\<CommonEventSubscriber>): void
Creates a subscriber. This API uses a callback to return the result. Creates a subscriber. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -352,10 +353,10 @@ Creates a subscriber. This API uses a callback to return the result. ...@@ -352,10 +353,10 @@ Creates a subscriber. This API uses a callback to return the result.
```js ```js
var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. let subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
// Subscriber information. // Subscriber information.
var subscribeInfo = { let subscribeInfo = {
events: ["event"] events: ["event"]
}; };
...@@ -397,10 +398,10 @@ Creates a subscriber. This API uses a promise to return the result. ...@@ -397,10 +398,10 @@ Creates a subscriber. This API uses a promise to return the result.
**Example** **Example**
```js ```js
var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. let subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
// Subscriber information. // Subscriber information.
var subscribeInfo = { let subscribeInfo = {
events: ["event"] events: ["event"]
}; };
...@@ -419,7 +420,7 @@ CommonEvent.createSubscriber(subscribeInfo).then((commonEventSubscriber) => { ...@@ -419,7 +420,7 @@ CommonEvent.createSubscriber(subscribeInfo).then((commonEventSubscriber) => {
subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEventData>): void subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEventData>): void
Subscribes to common events. This API uses a callback to return the result. Subscribes to common events. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -433,10 +434,10 @@ Subscribes to common events. This API uses a callback to return the result. ...@@ -433,10 +434,10 @@ Subscribes to common events. This API uses a callback to return the result.
**Example** **Example**
```js ```js
var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. let subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
// Subscriber information. // Subscriber information.
var subscribeInfo = { let subscribeInfo = {
events: ["event"] events: ["event"]
}; };
...@@ -471,7 +472,7 @@ CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); ...@@ -471,7 +472,7 @@ CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack);
unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>): void unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>): void
Unsubscribes from common events. This API uses a callback to return the result. Unsubscribes from common events. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -485,10 +486,10 @@ Unsubscribes from common events. This API uses a callback to return the result. ...@@ -485,10 +486,10 @@ Unsubscribes from common events. This API uses a callback to return the result.
**Example** **Example**
```js ```js
var subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. let subscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
// Subscriber information. // Subscriber information.
var subscribeInfo = { let subscribeInfo = {
events: ["event"] events: ["event"]
}; };
...@@ -535,7 +536,7 @@ CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack); ...@@ -535,7 +536,7 @@ CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack);
getCode(callback: AsyncCallback\<number>): void getCode(callback: AsyncCallback\<number>): void
Obtains the result code of this common event. This API uses a callback to return the result. Obtains the result code of this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -548,7 +549,7 @@ Obtains the result code of this common event. This API uses a callback to return ...@@ -548,7 +549,7 @@ Obtains the result code of this common event. This API uses a callback to return
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
// Callback for result code obtaining of an ordered common event. // Callback for result code obtaining of an ordered common event.
function getCodeCallback(err, Code) { function getCodeCallback(err, Code) {
...@@ -578,7 +579,7 @@ Obtains the result code of this common event. This API uses a promise to return ...@@ -578,7 +579,7 @@ Obtains the result code of this common event. This API uses a promise to return
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
subscriber.getCode().then((Code) => { subscriber.getCode().then((Code) => {
console.info("getCode " + JSON.stringify(Code)); console.info("getCode " + JSON.stringify(Code));
...@@ -591,7 +592,7 @@ subscriber.getCode().then((Code) => { ...@@ -591,7 +592,7 @@ subscriber.getCode().then((Code) => {
setCode(code: number, callback: AsyncCallback\<void>): void setCode(code: number, callback: AsyncCallback\<void>): void
Sets the result code for this common event. This API uses a callback to return the result. Sets the result code for this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -605,7 +606,7 @@ Sets the result code for this common event. This API uses a callback to return t ...@@ -605,7 +606,7 @@ Sets the result code for this common event. This API uses a callback to return t
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
// Callback for result code setting of an ordered common event. // Callback for result code setting of an ordered common event.
function setCodeCallback(err) { function setCodeCallback(err) {
...@@ -641,7 +642,7 @@ Sets the result code for this common event. This API uses a promise to return th ...@@ -641,7 +642,7 @@ Sets the result code for this common event. This API uses a promise to return th
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
subscriber.setCode(1).then(() => { subscriber.setCode(1).then(() => {
console.info("setCode"); console.info("setCode");
...@@ -654,7 +655,7 @@ subscriber.setCode(1).then(() => { ...@@ -654,7 +655,7 @@ subscriber.setCode(1).then(() => {
getData(callback: AsyncCallback\<string>): void getData(callback: AsyncCallback\<string>): void
Obtains the result data of this common event. This API uses a callback to return the result. Obtains the result data of this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -667,7 +668,7 @@ Obtains the result data of this common event. This API uses a callback to return ...@@ -667,7 +668,7 @@ Obtains the result data of this common event. This API uses a callback to return
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
// Callback for result data obtaining of an ordered common event. // Callback for result data obtaining of an ordered common event.
function getDataCallback(err, Data) { function getDataCallback(err, Data) {
...@@ -697,7 +698,7 @@ Obtains the result data of this common event. This API uses a promise to return ...@@ -697,7 +698,7 @@ Obtains the result data of this common event. This API uses a promise to return
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
subscriber.getData().then((Data) => { subscriber.getData().then((Data) => {
console.info("getData " + JSON.stringify(Data)); console.info("getData " + JSON.stringify(Data));
...@@ -710,7 +711,7 @@ subscriber.getData().then((Data) => { ...@@ -710,7 +711,7 @@ subscriber.getData().then((Data) => {
setData(data: string, callback: AsyncCallback\<void>): void setData(data: string, callback: AsyncCallback\<void>): void
Sets the result data for this common event. This API uses a callback to return the result. Sets the result data for this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -724,7 +725,7 @@ Sets the result data for this common event. This API uses a callback to return t ...@@ -724,7 +725,7 @@ Sets the result data for this common event. This API uses a callback to return t
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
// Callback for result data setting of an ordered common event // Callback for result data setting of an ordered common event
function setDataCallback(err) { function setDataCallback(err) {
...@@ -760,7 +761,7 @@ Sets the result data for this common event. This API uses a promise to return th ...@@ -760,7 +761,7 @@ Sets the result data for this common event. This API uses a promise to return th
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
subscriber.setData("publish_data_changed").then(() => { subscriber.setData("publish_data_changed").then(() => {
console.info("setData"); console.info("setData");
...@@ -773,7 +774,7 @@ subscriber.setData("publish_data_changed").then(() => { ...@@ -773,7 +774,7 @@ subscriber.setData("publish_data_changed").then(() => {
setCodeAndData(code: number, data: string, callback:AsyncCallback\<void>): void setCodeAndData(code: number, data: string, callback:AsyncCallback\<void>): void
Sets the result code and result data for this common event. This API uses a callback to return the result. Sets the result code and result data for this common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -788,7 +789,7 @@ Sets the result code and result data for this common event. This API uses a call ...@@ -788,7 +789,7 @@ Sets the result code and result data for this common event. This API uses a call
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
// Callback for result code and result data setting of an ordered common event. // Callback for result code and result data setting of an ordered common event.
function setCodeDataCallback(err) { function setCodeDataCallback(err) {
...@@ -825,7 +826,7 @@ Sets the result code and result data for this common event. This API uses a prom ...@@ -825,7 +826,7 @@ Sets the result code and result data for this common event. This API uses a prom
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
subscriber.setCodeAndData(1, "publish_data_changed").then(() => { subscriber.setCodeAndData(1, "publish_data_changed").then(() => {
console.info("setCodeAndData"); console.info("setCodeAndData");
...@@ -838,7 +839,8 @@ subscriber.setCodeAndData(1, "publish_data_changed").then(() => { ...@@ -838,7 +839,8 @@ subscriber.setCodeAndData(1, "publish_data_changed").then(() => {
isOrderedCommonEvent(callback: AsyncCallback\<boolean>): void isOrderedCommonEvent(callback: AsyncCallback\<boolean>): void
Checks whether this common event is an ordered one. This API uses a callback to return the result. Checks whether this common event is an ordered one. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -851,7 +853,7 @@ Checks whether this common event is an ordered one. This API uses a callback to ...@@ -851,7 +853,7 @@ Checks whether this common event is an ordered one. This API uses a callback to
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
// Callback for checking whether the current common event is an ordered one. // Callback for checking whether the current common event is an ordered one.
function isOrderedCallback(err, isOrdered) { function isOrderedCallback(err, isOrdered) {
...@@ -870,6 +872,7 @@ isOrderedCommonEvent(): Promise\<boolean> ...@@ -870,6 +872,7 @@ isOrderedCommonEvent(): Promise\<boolean>
Checks whether this common event is an ordered one. This API uses a promise to return the result. Checks whether this common event is an ordered one. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
**Return value** **Return value**
...@@ -881,7 +884,7 @@ Checks whether this common event is an ordered one. This API uses a promise to r ...@@ -881,7 +884,7 @@ Checks whether this common event is an ordered one. This API uses a promise to r
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
subscriber.isOrderedCommonEvent().then((isOrdered) => { subscriber.isOrderedCommonEvent().then((isOrdered) => {
console.info("isOrdered " + JSON.stringify(isOrdered)); console.info("isOrdered " + JSON.stringify(isOrdered));
...@@ -894,7 +897,8 @@ subscriber.isOrderedCommonEvent().then((isOrdered) => { ...@@ -894,7 +897,8 @@ subscriber.isOrderedCommonEvent().then((isOrdered) => {
isStickyCommonEvent(callback: AsyncCallback\<boolean>): void isStickyCommonEvent(callback: AsyncCallback\<boolean>): void
Checks whether this common event is a sticky one. This API uses a callback to return the result. Checks whether this common event is a sticky one. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -907,7 +911,7 @@ Checks whether this common event is a sticky one. This API uses a callback to re ...@@ -907,7 +911,7 @@ Checks whether this common event is a sticky one. This API uses a callback to re
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
// Callback for checking whether the current common event is a sticky one. // Callback for checking whether the current common event is a sticky one.
function isStickyCallback(err, isSticky) { function isStickyCallback(err, isSticky) {
...@@ -926,6 +930,7 @@ isStickyCommonEvent(): Promise\<boolean> ...@@ -926,6 +930,7 @@ isStickyCommonEvent(): Promise\<boolean>
Checks whether this common event is a sticky one. This API uses a promise to return the result. Checks whether this common event is a sticky one. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
**Return value** **Return value**
...@@ -937,7 +942,7 @@ Checks whether this common event is a sticky one. This API uses a promise to ret ...@@ -937,7 +942,7 @@ Checks whether this common event is a sticky one. This API uses a promise to ret
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
subscriber.isStickyCommonEvent().then((isSticky) => { subscriber.isStickyCommonEvent().then((isSticky) => {
console.info("isSticky " + JSON.stringify(isSticky)); console.info("isSticky " + JSON.stringify(isSticky));
...@@ -950,7 +955,7 @@ subscriber.isStickyCommonEvent().then((isSticky) => { ...@@ -950,7 +955,7 @@ subscriber.isStickyCommonEvent().then((isSticky) => {
abortCommonEvent(callback: AsyncCallback\<void>): void 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 a callback to return the result. 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 **System capability**: SystemCapability.Notification.CommonEvent
...@@ -963,7 +968,7 @@ Aborts this common event. After the abort, the common event is not sent to the n ...@@ -963,7 +968,7 @@ Aborts this common event. After the abort, the common event is not sent to the n
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
// Callback for common event aborting. // Callback for common event aborting.
function abortCallback(err) { function abortCallback(err) {
...@@ -993,7 +998,7 @@ Aborts this common event. After the abort, the common event is not sent to the n ...@@ -993,7 +998,7 @@ Aborts this common event. After the abort, the common event is not sent to the n
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
subscriber.abortCommonEvent().then(() => { subscriber.abortCommonEvent().then(() => {
console.info("abortCommonEvent"); console.info("abortCommonEvent");
...@@ -1006,7 +1011,7 @@ subscriber.abortCommonEvent().then(() => { ...@@ -1006,7 +1011,7 @@ subscriber.abortCommonEvent().then(() => {
clearAbortCommonEvent(callback: AsyncCallback\<void>): void clearAbortCommonEvent(callback: AsyncCallback\<void>): void
Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses a callback to return the result. 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 **System capability**: SystemCapability.Notification.CommonEvent
...@@ -1019,7 +1024,7 @@ Clears the aborted state of this common event. This API takes effect only for or ...@@ -1019,7 +1024,7 @@ Clears the aborted state of this common event. This API takes effect only for or
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
// Callback for clearing the aborted state of the current common event. // Callback for clearing the aborted state of the current common event.
function clearAbortCallback(err) { function clearAbortCallback(err) {
...@@ -1049,7 +1054,7 @@ Clears the aborted state of this common event. This API takes effect only for or ...@@ -1049,7 +1054,7 @@ Clears the aborted state of this common event. This API takes effect only for or
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
subscriber.clearAbortCommonEvent().then(() => { subscriber.clearAbortCommonEvent().then(() => {
console.info("clearAbortCommonEvent"); console.info("clearAbortCommonEvent");
...@@ -1062,7 +1067,7 @@ subscriber.clearAbortCommonEvent().then(() => { ...@@ -1062,7 +1067,7 @@ subscriber.clearAbortCommonEvent().then(() => {
getAbortCommonEvent(callback: AsyncCallback\<boolean>): void 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 a callback to return the result. 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 **System capability**: SystemCapability.Notification.CommonEvent
...@@ -1075,7 +1080,7 @@ Checks whether this common event is in the aborted state. This API takes effect ...@@ -1075,7 +1080,7 @@ Checks whether this common event is in the aborted state. This API takes effect
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
// Callback for checking whether the current common event is in the aborted state. // Callback for checking whether the current common event is in the aborted state.
function getAbortCallback(err, AbortCommonEvent) { function getAbortCallback(err, AbortCommonEvent) {
...@@ -1105,7 +1110,7 @@ Checks whether this common event is in the aborted state. This API takes effect ...@@ -1105,7 +1110,7 @@ Checks whether this common event is in the aborted state. This API takes effect
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
subscriber.getAbortCommonEvent().then((AbortCommonEvent) => { subscriber.getAbortCommonEvent().then((AbortCommonEvent) => {
console.info("AbortCommonEvent " + JSON.stringify(AbortCommonEvent)); console.info("AbortCommonEvent " + JSON.stringify(AbortCommonEvent));
...@@ -1118,7 +1123,7 @@ subscriber.getAbortCommonEvent().then((AbortCommonEvent) => { ...@@ -1118,7 +1123,7 @@ subscriber.getAbortCommonEvent().then((AbortCommonEvent) => {
getSubscribeInfo(callback: AsyncCallback\<CommonEventSubscribeInfo>): void getSubscribeInfo(callback: AsyncCallback\<CommonEventSubscribeInfo>): void
Obtains the subscriber information. This API uses a callback to return the result. Obtains the subscriber information. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -1131,7 +1136,7 @@ Obtains the subscriber information. This API uses a callback to return the resul ...@@ -1131,7 +1136,7 @@ Obtains the subscriber information. This API uses a callback to return the resul
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
// Callback for subscriber information obtaining. // Callback for subscriber information obtaining.
function getSubscribeInfoCallback(err, SubscribeInfo) { function getSubscribeInfoCallback(err, SubscribeInfo) {
...@@ -1161,7 +1166,7 @@ Obtains the subscriber information. This API uses a promise to return the result ...@@ -1161,7 +1166,7 @@ Obtains the subscriber information. This API uses a promise to return the result
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
subscriber.getSubscribeInfo().then((SubscribeInfo) => { subscriber.getSubscribeInfo().then((SubscribeInfo) => {
console.info("SubscribeInfo " + JSON.stringify(SubscribeInfo)); console.info("SubscribeInfo " + JSON.stringify(SubscribeInfo));
...@@ -1174,7 +1179,7 @@ subscriber.getSubscribeInfo().then((SubscribeInfo) => { ...@@ -1174,7 +1179,7 @@ subscriber.getSubscribeInfo().then((SubscribeInfo) => {
finishCommonEvent(callback: AsyncCallback\<void\>): void finishCommonEvent(callback: AsyncCallback\<void\>): void
Finishes this ordered common event. This API uses a callback to return the result. Finishes this ordered common event. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -1187,7 +1192,7 @@ Finishes this ordered common event. This API uses a callback to return the resul ...@@ -1187,7 +1192,7 @@ Finishes this ordered common event. This API uses a callback to return the resul
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
// Callback for ordered common event finishing. // Callback for ordered common event finishing.
function finishCommonEventCallback(err) { function finishCommonEventCallback(err) {
...@@ -1217,7 +1222,7 @@ Finishes this ordered common event. This API uses a promise to return the result ...@@ -1217,7 +1222,7 @@ Finishes this ordered common event. This API uses a promise to return the result
**Example** **Example**
```js ```js
var subscriber; // Subscriber object successfully created. let subscriber; // Subscriber object successfully created.
subscriber.finishCommonEvent().then(() => { subscriber.finishCommonEvent().then(() => {
console.info("FinishCommonEvent"); console.info("FinishCommonEvent");
......
...@@ -16,19 +16,6 @@ import emitter from '@ohos.events.emitter' ...@@ -16,19 +16,6 @@ import emitter from '@ohos.events.emitter'
None None
## EventPriority
Enumerates the event emit priority levels.
**System capability**: SystemCapability.Notification.Emitter
| Name | Value | Description |
| --------- | ---- | ------------------------------------------------- |
| IMMEDIATE | 0 | The event will be emitted immediately. |
| HIGH | 1 | The event will be emitted before low-priority events. |
| LOW | 2 | The event will be emitted before idle-priority events. By default, an event is in LOW priority. |
| IDLE | 3 | The event will be emitted after all the other events. |
## emitter.on ## emitter.on
on(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)\>): void on(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)\>): void
...@@ -39,21 +26,21 @@ Subscribes to an event in persistent manner. This API uses a callback to return ...@@ -39,21 +26,21 @@ Subscribes to an event in persistent manner. This API uses a callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | ------------------------ | | -------- | ----------------------------------- | ---- | --------------------------------------- |
| event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in persistent manner. | | event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in persistent manner. The **EventPriority** settings do not take effect.|
| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event.| | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event. |
**Example** **Example**
```javascript ```javascript
var innerEvent = { let innerEvent = {
eventId: 1 eventId: 1
}; };
var callback = (eventData) => { function EmitterCallback(eventData) {
console.info('callback'); console.info('callback');
}; }
emitter.on(innerEvent, callback); emitter.on(innerEvent, EmitterCallback);
``` ```
## emitter.once ## emitter.once
...@@ -66,21 +53,21 @@ Subscribes to an event in one-shot manner and unsubscribes from it after the eve ...@@ -66,21 +53,21 @@ Subscribes to an event in one-shot manner and unsubscribes from it after the eve
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | ------------------------ | | -------- | ----------------------------------- | ---- | --------------------------------------- |
| event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in one-shot manner. | | event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in one-shot manner. The **EventPriority** settings do not take effect.|
| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event.| | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event. |
**Example** **Example**
```javascript ```javascript
var innerEvent = { let innerEvent = {
eventId: 1 eventId: 1
}; };
var callback = (eventData) => { function EmitterCallback(eventData) {
console.info('once callback'); console.info('once callback');
}; };
emitter.once(innerEvent, callback); emitter.once(innerEvent, EmitterCallback);
``` ```
## emitter.off ## emitter.off
...@@ -121,18 +108,31 @@ Emits an event to the event queue. ...@@ -121,18 +108,31 @@ Emits an event to the event queue.
**Example** **Example**
```javascript ```javascript
var eventData = { let eventData = {
data: { data: {
"content": "c", "content": "c",
"id": 1, "id": 1,
}}; }};
var innerEvent = { let innerEvent = {
eventId: 1, eventId: 1,
priority: emitter.EventPriority.HIGH priority: emitter.EventPriority.HIGH
}; };
emitter.emit(innerEvent, eventData); emitter.emit(innerEvent, eventData);
``` ```
## EventPriority
Enumerates the event emit priority levels.
**System capability**: SystemCapability.Notification.Emitter
| Name | Value | Description |
| --------- | ---- | --------------------------------------------------- |
| IMMEDIATE | 0 | The event will be emitted immediately. |
| HIGH | 1 | The event will be emitted before low-priority events. |
| LOW | 2 | The event will be emitted before idle-priority events. By default, an event is in LOW priority.|
| IDLE | 3 | The event will be emitted after all the other events. |
## InnerEvent ## InnerEvent
Describes an in-process event. Describes an in-process event.
...@@ -141,7 +141,7 @@ Describes an in-process event. ...@@ -141,7 +141,7 @@ Describes an in-process event.
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| -------- | ------------------------------- | ---- | ---- | ---------------------------------- | | -------- | ------------------------------- | ---- | ---- | ---------------------------------- |
| eventId | number | Yes | Yes | Event ID, which is used to identify an event.| | eventId | number | Yes | Yes | Event ID.|
| priority | [EventPriority](#eventpriority) | Yes | Yes | Emit priority of the event. | | priority | [EventPriority](#eventpriority) | Yes | Yes | Emit priority of the event. |
## EventData ## EventData
......
...@@ -34,7 +34,11 @@ Publishes a notification. This API uses an asynchronous callback to return the r ...@@ -34,7 +34,11 @@ Publishes a notification. This API uses an asynchronous callback to return the r
```js ```js
// publish callback // publish callback
function publishCallback(err) { function publishCallback(err) {
console.info("==========================>publishCallback=======================>"); if (err.code) {
console.info("publish failed " + JSON.stringify(err));
} else {
console.info("publish success");
}
} }
// NotificationRequest object // NotificationRequest object
var notificationRequest = { var notificationRequest = {
...@@ -83,7 +87,7 @@ var notificationRequest = { ...@@ -83,7 +87,7 @@ var notificationRequest = {
} }
} }
Notification.publish(notificationRequest).then(() => { Notification.publish(notificationRequest).then(() => {
console.info("==========================>publishCallback=======================>"); console.info("publish sucess");
}); });
``` ```
...@@ -113,7 +117,11 @@ Publishes a notification. This API uses an asynchronous callback to return the r ...@@ -113,7 +117,11 @@ Publishes a notification. This API uses an asynchronous callback to return the r
```js ```js
// publish callback // publish callback
function publishCallback(err) { function publishCallback(err) {
console.info("==========================>publishCallback=======================>"); if (err.code) {
console.info("publish failed " + JSON.stringify(err));
} else {
console.info("publish success");
}
} }
// ID of the user who receives the notification // ID of the user who receives the notification
var userId = 1 var userId = 1
...@@ -169,7 +177,7 @@ var notificationRequest = { ...@@ -169,7 +177,7 @@ var notificationRequest = {
var userId = 1 var userId = 1
Notification.publish(notificationRequest, userId).then(() => { Notification.publish(notificationRequest, userId).then(() => {
console.info("==========================>publishCallback=======================>"); console.info("publish sucess");
}); });
``` ```
...@@ -195,7 +203,11 @@ Cancels a notification with the specified ID and label. This API uses an asynchr ...@@ -195,7 +203,11 @@ Cancels a notification with the specified ID and label. This API uses an asynchr
```js ```js
// cancel callback // cancel callback
function cancelCallback(err) { function cancelCallback(err) {
console.info("==========================>cancelCallback=======================>"); if (err.code) {
console.info("cancel failed " + JSON.stringify(err));
} else {
console.info("cancel success");
}
} }
Notification.cancel(0, "label", cancelCallback) Notification.cancel(0, "label", cancelCallback)
``` ```
...@@ -221,7 +233,7 @@ Cancels a notification with the specified ID and label. This API uses a promise ...@@ -221,7 +233,7 @@ Cancels a notification with the specified ID and label. This API uses a promise
```js ```js
Notification.cancel(0).then(() => { Notification.cancel(0).then(() => {
console.info("==========================>cancelCallback=======================>"); console.info("cancel sucess");
}); });
``` ```
...@@ -247,7 +259,11 @@ Cancels a notification with the specified ID. This API uses an asynchronous call ...@@ -247,7 +259,11 @@ Cancels a notification with the specified ID. This API uses an asynchronous call
```js ```js
// cancel callback // cancel callback
function cancelCallback(err) { function cancelCallback(err) {
console.info("==========================>cancelCallback=======================>"); if (err.code) {
console.info("cancel failed " + JSON.stringify(err));
} else {
console.info("cancel success");
}
} }
Notification.cancel(0, cancelCallback) Notification.cancel(0, cancelCallback)
``` ```
...@@ -273,7 +289,11 @@ Cancels all notifications. This API uses an asynchronous callback to return the ...@@ -273,7 +289,11 @@ Cancels all notifications. This API uses an asynchronous callback to return the
```js ```js
// cancel callback // cancel callback
function cancelAllCallback(err) { function cancelAllCallback(err) {
console.info("==========================>cancelAllCallback=======================>"); if (err.code) {
console.info("cancelAll failed " + JSON.stringify(err));
} else {
console.info("cancelAll success");
}
} }
Notification.cancelAll(cancelAllCallback) Notification.cancelAll(cancelAllCallback)
``` ```
...@@ -292,7 +312,7 @@ Cancels all notifications. This API uses a promise to return the result. ...@@ -292,7 +312,7 @@ Cancels all notifications. This API uses a promise to return the result.
```js ```js
Notification.cancelAll().then(() => { Notification.cancelAll().then(() => {
console.info("==========================>cancelAllCallback=======================>"); console.info("cancelAll sucess");
}); });
``` ```
...@@ -322,7 +342,11 @@ Adds a notification slot. This API uses an asynchronous callback to return the r ...@@ -322,7 +342,11 @@ Adds a notification slot. This API uses an asynchronous callback to return the r
```js ```js
// addSlot callback // addSlot callback
function addSlotCallBack(err) { function addSlotCallBack(err) {
console.info("==========================>addSlotCallBack=======================>"); if (err.code) {
console.info("addSlot failed " + JSON.stringify(err));
} else {
console.info("addSlot success");
}
} }
// NotificationSlot object // NotificationSlot object
var notificationSlot = { var notificationSlot = {
...@@ -359,7 +383,7 @@ var notificationSlot = { ...@@ -359,7 +383,7 @@ var notificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION type: Notification.SlotType.SOCIAL_COMMUNICATION
} }
Notification.addSlot(notificationSlot).then(() => { Notification.addSlot(notificationSlot).then(() => {
console.info("==========================>addSlotCallback=======================>"); console.info("addSlot sucess");
}); });
``` ```
...@@ -385,7 +409,11 @@ Adds a notification slot. This API uses an asynchronous callback to return the r ...@@ -385,7 +409,11 @@ Adds a notification slot. This API uses an asynchronous callback to return the r
```js ```js
// addSlot callback // addSlot callback
function addSlotCallBack(err) { function addSlotCallBack(err) {
console.info("==========================>addSlotCallBack=======================>"); if (err.code) {
console.info("addSlot failed " + JSON.stringify(err));
} else {
console.info("addSlot success");
}
} }
Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack) Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack)
``` ```
...@@ -410,7 +438,7 @@ Adds a notification slot. This API uses a promise to return the result. ...@@ -410,7 +438,7 @@ Adds a notification slot. This API uses a promise to return the result.
```js ```js
Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => { Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => {
console.info("==========================>addSlotCallback=======================>"); console.info("addSlot sucess");
}); });
``` ```
...@@ -440,7 +468,11 @@ Adds multiple notification slots. This API uses an asynchronous callback to retu ...@@ -440,7 +468,11 @@ Adds multiple notification slots. This API uses an asynchronous callback to retu
```js ```js
// addSlots callback // addSlots callback
function addSlotsCallBack(err) { function addSlotsCallBack(err) {
console.info("==========================>addSlotsCallBack=======================>"); if (err.code) {
console.info("addSlots failed " + JSON.stringify(err));
} else {
console.info("addSlots success");
}
} }
// NotificationSlot object // NotificationSlot object
var notificationSlot = { var notificationSlot = {
...@@ -485,7 +517,7 @@ var notificationSlotArray = new Array(); ...@@ -485,7 +517,7 @@ var notificationSlotArray = new Array();
notificationSlotArray[0] = notificationSlot; notificationSlotArray[0] = notificationSlot;
Notification.addSlots(notificationSlotArray).then(() => { Notification.addSlots(notificationSlotArray).then(() => {
console.info("==========================>addSlotCallback=======================>"); console.info("addSlots sucess");
}); });
``` ```
...@@ -511,7 +543,11 @@ Obtains a notification slot of the specified type. This API uses an asynchronous ...@@ -511,7 +543,11 @@ Obtains a notification slot of the specified type. This API uses an asynchronous
```js ```js
// getSlot callback // getSlot callback
function getSlotCallback(err,data) { function getSlotCallback(err,data) {
console.info("==========================>getSlotCallback=======================>"); if (err.code) {
console.info("getSlot failed " + JSON.stringify(err));
} else {
console.info("getSlot success");
}
} }
var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; var slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.getSlot(slotType, getSlotCallback) Notification.getSlot(slotType, getSlotCallback)
...@@ -544,7 +580,7 @@ Obtains a notification slot of the specified type. This API uses a promise to re ...@@ -544,7 +580,7 @@ Obtains a notification slot of the specified type. This API uses a promise to re
```js ```js
var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; var slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.getSlot(slotType).then((data) => { Notification.getSlot(slotType).then((data) => {
console.info("==========================>getSlotCallback=======================>"); console.info("getSlot sucess, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -569,7 +605,11 @@ Obtains all notification slots. This API uses an asynchronous callback to return ...@@ -569,7 +605,11 @@ Obtains all notification slots. This API uses an asynchronous callback to return
```js ```js
// getSlots callback // getSlots callback
function getSlotsCallback(err,data) { function getSlotsCallback(err,data) {
console.info("==========================>getSlotsCallback=======================>"); if (err.code) {
console.info("getSlots failed " + JSON.stringify(err));
} else {
console.info("getSlots success");
}
} }
Notification.getSlots(getSlotsCallback) Notification.getSlots(getSlotsCallback)
``` ```
...@@ -594,7 +634,7 @@ Obtains all notification slots of this application. This API uses a promise to r ...@@ -594,7 +634,7 @@ Obtains all notification slots of this application. This API uses a promise to r
```js ```js
Notification.getSlots().then((data) => { Notification.getSlots().then((data) => {
console.info("==========================>getSlotsCallback=======================>"); console.info("getSlots sucess, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -620,7 +660,11 @@ Removes a notification slot of the specified type. This API uses an asynchronous ...@@ -620,7 +660,11 @@ Removes a notification slot of the specified type. This API uses an asynchronous
```js ```js
// removeSlot callback // removeSlot callback
function removeSlotCallback(err) { function removeSlotCallback(err) {
console.info("==========================>removeSlotCallback=======================>"); if (err.code) {
console.info("removeSlot failed " + JSON.stringify(err));
} else {
console.info("removeSlot success");
}
} }
var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; var slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.removeSlot(slotType,removeSlotCallback) Notification.removeSlot(slotType,removeSlotCallback)
...@@ -647,7 +691,7 @@ Removes a notification slot of the specified type. This API uses a promise to re ...@@ -647,7 +691,7 @@ Removes a notification slot of the specified type. This API uses a promise to re
```js ```js
var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; var slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.removeSlot(slotType).then(() => { Notification.removeSlot(slotType).then(() => {
console.info("==========================>removeSlotCallback=======================>"); console.info("removeSlot sucess");
}); });
``` ```
...@@ -671,7 +715,11 @@ Removes all notification slots. This API uses an asynchronous callback to return ...@@ -671,7 +715,11 @@ Removes all notification slots. This API uses an asynchronous callback to return
```js ```js
function removeAllCallBack(err) { function removeAllCallBack(err) {
console.info("================>removeAllCallBack=======================>"); if (err.code) {
console.info("removeAllSlots failed " + JSON.stringify(err));
} else {
console.info("removeAllSlots success");
}
} }
Notification.removeAllSlots(removeAllCallBack) Notification.removeAllSlots(removeAllCallBack)
``` ```
...@@ -690,7 +738,7 @@ Removes all notification slots. This API uses a promise to return the result. ...@@ -690,7 +738,7 @@ Removes all notification slots. This API uses a promise to return the result.
```js ```js
Notification.removeAllSlots().then(() => { Notification.removeAllSlots().then(() => {
console.info("==========================>removeAllCallBack=======================>"); console.info("removeAllSlots sucess");
}); });
``` ```
...@@ -721,10 +769,14 @@ Subscribes to a notification with the subscription information specified. This A ...@@ -721,10 +769,14 @@ Subscribes to a notification with the subscription information specified. This A
```js ```js
// subscribe callback // subscribe callback
function subscribeCallback(err) { function subscribeCallback(err) {
console.info("==========================>subscribeCallback=======================>"); if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribe success");
}
} }
function onConsumeCallback(data) { function onConsumeCallback(data) {
console.info("==========================>onConsumeCallback=======================>"); console.info("Consume callback: " + JSON.stringify(data));
} }
var subscriber = { var subscriber = {
onConsume: onConsumeCallback onConsume: onConsumeCallback
...@@ -760,10 +812,14 @@ Subscribes to a notification with the subscription information specified. This A ...@@ -760,10 +812,14 @@ Subscribes to a notification with the subscription information specified. This A
```js ```js
function subscribeCallback(err) { function subscribeCallback(err) {
console.info("==========================>subscribeCallback=======================>"); if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribe success");
}
} }
function onConsumeCallback(data) { function onConsumeCallback(data) {
console.info("==========================>onConsumeCallback=======================>"); console.info("Consume callback: " + JSON.stringify(data));
} }
var subscriber = { var subscriber = {
onConsume: onConsumeCallback onConsume: onConsumeCallback
...@@ -796,13 +852,17 @@ Subscribes to a notification with the subscription information specified. This A ...@@ -796,13 +852,17 @@ Subscribes to a notification with the subscription information specified. This A
```js ```js
function onConsumeCallback(data) { function onConsumeCallback(data) {
console.info("==========================>onConsumeCallback=======================>"); if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribe success");
}
} }
var subscriber = { var subscriber = {
onConsume: onConsumeCallback onConsume: onConsumeCallback
}; };
Notification.subscribe(subscriber).then(() => { Notification.subscribe(subscriber).then(() => {
console.info("==========================>subscribeCallback=======================>"); console.info("subscribe sucess");
}); });
``` ```
...@@ -831,13 +891,17 @@ Unsubscribes from a notification. This API uses an asynchronous callback to retu ...@@ -831,13 +891,17 @@ Unsubscribes from a notification. This API uses an asynchronous callback to retu
```js ```js
function unsubscribeCallback(err) { function unsubscribeCallback(err) {
console.info("==========================>unsubscribeCallback=======================>"); if (err.code) {
console.info("unsubscribe failed " + JSON.stringify(err));
} else {
console.info("unsubscribe success");
}
} }
function onConsumeCallback(data) { function onCancelCallback(data) {
console.info("==========================>onConsumeCallback=======================>"); console.info("Cancel callback: " + JSON.stringify(data));
} }
var subscriber = { var subscriber = {
onConsume: onConsumeCallback onCancel: onCancelCallback
} }
Notification.unsubscribe(subscriber, unsubscribeCallback); Notification.unsubscribe(subscriber, unsubscribeCallback);
``` ```
...@@ -865,14 +929,14 @@ Unsubscribes from a notification. This API uses a promise to return the result. ...@@ -865,14 +929,14 @@ Unsubscribes from a notification. This API uses a promise to return the result.
**Example** **Example**
```js ```js
function onConsumeCallback(data) { function onCancelCallback(data) {
console.info("==========================>onConsumeCallback=======================>"); console.info("Cancel callback: " + JSON.stringify(data));
} }
var subscriber = { var subscriber = {
onConsume: onConsumeCallback onCancel: onCancelCallback
}; };
Notification.unsubscribe(subscriber).then(() => { Notification.unsubscribe(subscriber).then(() => {
console.info("==========================>unsubscribeCallback=======================>"); console.info("unsubscribe sucess");
}); });
``` ```
...@@ -902,7 +966,11 @@ Sets whether to enable notification for a specified bundle. This API uses an asy ...@@ -902,7 +966,11 @@ Sets whether to enable notification for a specified bundle. This API uses an asy
```js ```js
function enableNotificationCallback(err) { function enableNotificationCallback(err) {
console.info("==========================>enableNotificationCallback=======================>"); if (err.code) {
console.info("enableNotification failed " + JSON.stringify(err));
} else {
console.info("enableNotification success");
}
} }
var bundle = { var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
...@@ -938,7 +1006,7 @@ var bundle = { ...@@ -938,7 +1006,7 @@ var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
} }
Notification.enableNotification(bundle, false).then(() => { Notification.enableNotification(bundle, false).then(() => {
console.info("==========================>enableNotificationCallback=======================>"); console.info("enableNotification sucess");
}); });
``` ```
...@@ -967,7 +1035,11 @@ Checks whether notification is enabled for a specified bundle. This API uses an ...@@ -967,7 +1035,11 @@ Checks whether notification is enabled for a specified bundle. This API uses an
```js ```js
function isNotificationEnabledCallback(err, data) { function isNotificationEnabledCallback(err, data) {
console.info("==========================>isNotificationEnabledCallback=======================>"); if (err.code) {
console.info("isNotificationEnabled failed " + JSON.stringify(err));
} else {
console.info("isNotificationEnabled success");
}
} }
var bundle = { var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
...@@ -1008,7 +1080,7 @@ var bundle = { ...@@ -1008,7 +1080,7 @@ var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
} }
Notification.isNotificationEnabled(bundle).then((data) => { Notification.isNotificationEnabled(bundle).then((data) => {
console.info("==========================>isNotificationEnabledCallback=======================>"); console.info("isNotificationEnabled sucess, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -1036,7 +1108,11 @@ Checks whether notification is enabled for this application. This API uses an as ...@@ -1036,7 +1108,11 @@ Checks whether notification is enabled for this application. This API uses an as
```js ```js
function isNotificationEnabledCallback(err, data) { function isNotificationEnabledCallback(err, data) {
console.info("==========================>isNotificationEnabledCallback=======================>"); if (err.code) {
console.info("isNotificationEnabled failed " + JSON.stringify(err));
} else {
console.info("isNotificationEnabled success");
}
} }
Notification.isNotificationEnabled(isNotificationEnabledCallback); Notification.isNotificationEnabled(isNotificationEnabledCallback);
...@@ -1072,7 +1148,7 @@ Checks whether notification is enabled for this application. This API uses a pro ...@@ -1072,7 +1148,7 @@ Checks whether notification is enabled for this application. This API uses a pro
```js ```js
Notification.isNotificationEnabled().then((data) => { Notification.isNotificationEnabled().then((data) => {
console.info("==========================>isNotificationEnabledCallback=======================>"); console.info("isNotificationEnabled sucess, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -1102,7 +1178,11 @@ Sets whether to enable the notification badge for a specified bundle. This API u ...@@ -1102,7 +1178,11 @@ Sets whether to enable the notification badge for a specified bundle. This API u
```js ```js
function displayBadgeCallback(err) { function displayBadgeCallback(err) {
console.info("==========================>displayBadgeCallback=======================>"); if (err.code) {
console.info("displayBadge failed " + JSON.stringify(err));
} else {
console.info("displayBadge success");
}
} }
var bundle = { var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
...@@ -1138,7 +1218,7 @@ var bundle = { ...@@ -1138,7 +1218,7 @@ var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
} }
Notification.displayBadge(bundle, false).then(() => { Notification.displayBadge(bundle, false).then(() => {
console.info("==========================>displayBadgeCallback=======================>"); console.info("displayBadge sucess");
}); });
``` ```
...@@ -1167,7 +1247,11 @@ Checks whether the notification badge is enabled for a specified bundle. This AP ...@@ -1167,7 +1247,11 @@ Checks whether the notification badge is enabled for a specified bundle. This AP
```js ```js
function isBadgeDisplayedCallback(err, data) { function isBadgeDisplayedCallback(err, data) {
console.info("==========================>isBadgeDisplayedCallback=======================>"); if (err.code) {
console.info("isBadgeDisplayed failed " + JSON.stringify(err));
} else {
console.info("isBadgeDisplayed success");
}
} }
var bundle = { var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
...@@ -1208,7 +1292,7 @@ var bundle = { ...@@ -1208,7 +1292,7 @@ var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
} }
Notification.isBadgeDisplayed(bundle).then((data) => { Notification.isBadgeDisplayed(bundle).then((data) => {
console.info("==========================>isBadgeDisplayedCallback=======================>"); console.info("isBadgeDisplayed sucess, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -1238,7 +1322,11 @@ Sets the notification slot for a specified bundle. This API uses an asynchronous ...@@ -1238,7 +1322,11 @@ Sets the notification slot for a specified bundle. This API uses an asynchronous
```js ```js
function setSlotByBundleCallback(err) { function setSlotByBundleCallback(err) {
console.info("==========================>setSlotByBundleCallback=======================>"); if (err.code) {
console.info("setSlotByBundle failed " + JSON.stringify(err));
} else {
console.info("setSlotByBundle success");
}
} }
var bundle = { var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
...@@ -1280,7 +1368,7 @@ var notificationSlot = { ...@@ -1280,7 +1368,7 @@ var notificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION type: Notification.SlotType.SOCIAL_COMMUNICATION
} }
Notification.setSlotByBundle(bundle, notificationSlot).then(() => { Notification.setSlotByBundle(bundle, notificationSlot).then(() => {
console.info("==========================>setSlotByBundleCallback=======================>"); console.info("setSlotByBundle sucess");
}); });
``` ```
...@@ -1309,7 +1397,11 @@ Obtains the notification slots of a specified bundle. This API uses an asynchron ...@@ -1309,7 +1397,11 @@ Obtains the notification slots of a specified bundle. This API uses an asynchron
```js ```js
function getSlotsByBundleCallback(err, data) { function getSlotsByBundleCallback(err, data) {
console.info("==========================>getSlotsByBundleCallback=======================>"); if (err.code) {
console.info("getSlotsByBundle failed " + JSON.stringify(err));
} else {
console.info("getSlotsByBundle success");
}
} }
var bundle = { var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
...@@ -1350,7 +1442,7 @@ var bundle = { ...@@ -1350,7 +1442,7 @@ var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
} }
Notification.getSlotsByBundle(bundle).then((data) => { Notification.getSlotsByBundle(bundle).then((data) => {
console.info("==========================>getSlotsByBundleCallback=======================>"); console.info("getSlotsByBundle sucess, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -1379,7 +1471,11 @@ Obtains the number of notification slots of a specified bundle. This API uses an ...@@ -1379,7 +1471,11 @@ Obtains the number of notification slots of a specified bundle. This API uses an
```js ```js
function getSlotNumByBundleCallback(err, data) { function getSlotNumByBundleCallback(err, data) {
console.info("==========================>getSlotNumByBundleCallback=======================>"); if (err.code) {
console.info("getSlotNumByBundle failed " + JSON.stringify(err));
} else {
console.info("getSlotNumByBundle success");
}
} }
var bundle = { var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
...@@ -1420,7 +1516,7 @@ var bundle = { ...@@ -1420,7 +1516,7 @@ var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
} }
Notification.getSlotNumByBundle(bundle).then((data) => { Notification.getSlotNumByBundle(bundle).then((data) => {
console.info("==========================>getSlotNumByBundleCallback=======================>"); console.info("getSlotNumByBundle sucess, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -1428,7 +1524,7 @@ Notification.getSlotNumByBundle(bundle).then((data) => { ...@@ -1428,7 +1524,7 @@ Notification.getSlotNumByBundle(bundle).then((data) => {
## Notification.remove ## Notification.remove
remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback\<void\>): void remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason, callback: AsyncCallback\<void\>): void
Removes a notification for a specified bundle. This API uses an asynchronous callback to return the result. Removes a notification for a specified bundle. This API uses an asynchronous callback to return the result.
...@@ -1441,16 +1537,21 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal ...@@ -1441,16 +1537,21 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------------- | ----------------------------------- | ---- | -------------------- | | --------------- | ----------------------------------| ---- | -------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information. |
| notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | | notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. |
| reason | [RemoveReason](#removereason9) | Yes | Indicates the reason for deleting a notification. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
function removeCallback(err) { function removeCallback(err) {
console.info("==========================>removeCallback=======================>"); if (err.code) {
console.info("remove failed " + JSON.stringify(err));
} else {
console.info("remove success");
}
} }
var bundle = { var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
...@@ -1459,14 +1560,15 @@ var notificationKey = { ...@@ -1459,14 +1560,15 @@ var notificationKey = {
id: 0, id: 0,
label: "label", label: "label",
} }
Notification.remove(bundle, notificationKey, removeCallback); var reason = Notification.RemoveReason.CLICK_REASON_REMOVE;
Notification.remove(bundle, notificationKey, reason, removeCallback);
``` ```
## Notification.remove ## Notification.remove
remove(bundle: BundleOption, notificationKey: NotificationKey): Promise\<void\> remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason): Promise\<void\>
Removes a notification for a specified bundle. This API uses a promise to return the result. Removes a notification for a specified bundle. This API uses a promise to return the result.
...@@ -1482,6 +1584,7 @@ Removes a notification for a specified bundle. This API uses a promise to return ...@@ -1482,6 +1584,7 @@ Removes a notification for a specified bundle. This API uses a promise to return
| --------------- | --------------- | ---- | ---------- | | --------------- | --------------- | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| | bundle | [BundleOption](#bundleoption) | Yes | Bundle information.|
| notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | | notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. |
| reason | [RemoveReason](#removereason9) | Yes | Reason for deleting the notification. |
**Example** **Example**
...@@ -1493,8 +1596,9 @@ var notificationKey = { ...@@ -1493,8 +1596,9 @@ var notificationKey = {
id: 0, id: 0,
label: "label", label: "label",
} }
Notification.remove(bundle, notificationKey).then(() => { var reason = Notification.RemoveReason.CLICK_REASON_REMOVE;
console.info("==========================>removeCallback=======================>"); Notification.remove(bundle, notificationKey, reason).then(() => {
console.info("remove sucess");
}); });
``` ```
...@@ -1502,7 +1606,7 @@ Notification.remove(bundle, notificationKey).then(() => { ...@@ -1502,7 +1606,7 @@ Notification.remove(bundle, notificationKey).then(() => {
## Notification.remove ## Notification.remove
remove(hashCode: string, callback: AsyncCallback\<void\>): void remove(hashCode: string, reason: RemoveReason, callback: AsyncCallback\<void\>): void
Removes a notification for a specified bundle. This API uses an asynchronous callback to return the result. Removes a notification for a specified bundle. This API uses an asynchronous callback to return the result.
...@@ -1517,6 +1621,7 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal ...@@ -1517,6 +1621,7 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | -------------------- | | -------- | --------------------- | ---- | -------------------- |
| hashCode | string | Yes | Unique notification ID. | | hashCode | string | Yes | Unique notification ID. |
| reason | [RemoveReason](#removereason9) | Yes | Reason for removing the notification. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -1525,17 +1630,21 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal ...@@ -1525,17 +1630,21 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal
var hashCode = 'hashCode' var hashCode = 'hashCode'
function removeCallback(err) { function removeCallback(err) {
console.info("==========================>removeCallback=======================>"); if (err.code) {
console.info("remove failed " + JSON.stringify(err));
} else {
console.info("remove success");
}
} }
var reason = Notification.RemoveReason.CANCEL_REASON_REMOVE;
Notification.remove(hashCode, removeCallback); Notification.remove(hashCode, reason, removeCallback);
``` ```
## Notification.remove ## Notification.remove
remove(hashCode: string): Promise\<void\> remove(hashCode: string, reason: RemoveReason): Promise\<void\>
Removes a notification for a specified bundle. This API uses a promise to return the result. Removes a notification for a specified bundle. This API uses a promise to return the result.
...@@ -1550,14 +1659,15 @@ Removes a notification for a specified bundle. This API uses a promise to return ...@@ -1550,14 +1659,15 @@ Removes a notification for a specified bundle. This API uses a promise to return
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------- | ---- | ---------- | | -------- | ---------- | ---- | ---------- |
| hashCode | string | Yes | Unique notification ID.| | hashCode | string | Yes | Unique notification ID.|
| reason | [RemoveReason](#removereason9) | Yes | Reason for removing the notification. |
**Example** **Example**
```js ```js
var hashCode = 'hashCode' var hashCode = 'hashCode'
var reason = Notification.RemoveReason.CLICK_REASON_REMOVE;
Notification.remove(hashCode).then(() => { Notification.remove(hashCode, reason).then(() => {
console.info("==========================>removeCallback=======================>"); console.info("remove sucess");
}); });
``` ```
...@@ -1586,7 +1696,11 @@ Removes all notifications for a specified bundle. This API uses an asynchronous ...@@ -1586,7 +1696,11 @@ Removes all notifications for a specified bundle. This API uses an asynchronous
```js ```js
function removeAllCallback(err) { function removeAllCallback(err) {
console.info("==========================>removeAllCallback=======================>"); if (err.code) {
console.info("removeAll failed " + JSON.stringify(err));
} else {
console.info("removeAll success");
}
} }
var bundle = { var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
...@@ -1618,7 +1732,11 @@ Removes all notifications. This API uses an asynchronous callback to return the ...@@ -1618,7 +1732,11 @@ Removes all notifications. This API uses an asynchronous callback to return the
```js ```js
function removeAllCallback(err) { function removeAllCallback(err) {
console.info("==========================>removeAllCallback=======================>"); if (err.code) {
console.info("removeAll failed " + JSON.stringify(err));
} else {
console.info("removeAll success");
}
} }
Notification.removeAll(removeAllCallback); Notification.removeAll(removeAllCallback);
...@@ -1648,7 +1766,7 @@ Removes all notifications for a specified user. This API uses a promise to retur ...@@ -1648,7 +1766,7 @@ Removes all notifications for a specified user. This API uses a promise to retur
```js ```js
Notification.removeAll().then(() => { Notification.removeAll().then(() => {
console.info("==========================>removeAllCallback=======================>"); console.info("removeAll sucess");
}); });
``` ```
...@@ -1675,7 +1793,11 @@ Removes all notifications for a specified user. This API uses an asynchronous ca ...@@ -1675,7 +1793,11 @@ Removes all notifications for a specified user. This API uses an asynchronous ca
```js ```js
function removeAllCallback(err) { function removeAllCallback(err) {
console.info("==========================>removeAllCallback=======================>"); if (err.code) {
console.info("removeAll failed " + JSON.stringify(err));
} else {
console.info("removeAll success");
}
} }
var userId = 1 var userId = 1
...@@ -1705,7 +1827,11 @@ Removes all notifications for a specified user. This API uses a promise to retur ...@@ -1705,7 +1827,11 @@ Removes all notifications for a specified user. This API uses a promise to retur
```js ```js
function removeAllCallback(err) { function removeAllCallback(err) {
console.info("==========================>removeAllCallback=======================>"); if (err.code) {
console.info("removeAll failed " + JSON.stringify(err));
} else {
console.info("removeAll success");
}
} }
var userId = 1 var userId = 1
...@@ -1736,7 +1862,11 @@ Obtains all active notifications. This API uses an asynchronous callback to retu ...@@ -1736,7 +1862,11 @@ Obtains all active notifications. This API uses an asynchronous callback to retu
```js ```js
function getAllActiveNotificationsCallback(err, data) { function getAllActiveNotificationsCallback(err, data) {
console.info("==========================>getAllActiveNotificationsCallback=======================>"); if (err.code) {
console.info("getAllActiveNotifications failed " + JSON.stringify(err));
} else {
console.info("getAllActiveNotifications success");
}
} }
Notification.getAllActiveNotifications(getAllActiveNotificationsCallback); Notification.getAllActiveNotifications(getAllActiveNotificationsCallback);
...@@ -1766,7 +1896,7 @@ Obtains all active notifications. This API uses a promise to return the result. ...@@ -1766,7 +1896,7 @@ Obtains all active notifications. This API uses a promise to return the result.
```js ```js
Notification.getAllActiveNotifications().then((data) => { Notification.getAllActiveNotifications().then((data) => {
console.info("==========================>getAllActiveNotificationsCallback=======================>"); console.info("getAllActiveNotifications sucess, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -1790,7 +1920,11 @@ Obtains the number of active notifications. This API uses an asynchronous callba ...@@ -1790,7 +1920,11 @@ Obtains the number of active notifications. This API uses an asynchronous callba
```js ```js
function getActiveNotificationCountCallback(err, data) { function getActiveNotificationCountCallback(err, data) {
console.info("==========================>getActiveNotificationCountCallback=======================>"); if (err.code) {
console.info("getActiveNotificationCount failed " + JSON.stringify(err));
} else {
console.info("getActiveNotificationCount success");
}
} }
Notification.getActiveNotificationCount(getActiveNotificationCountCallback); Notification.getActiveNotificationCount(getActiveNotificationCountCallback);
...@@ -1816,7 +1950,7 @@ Obtains the number of active notifications. This API uses a promise to return th ...@@ -1816,7 +1950,7 @@ Obtains the number of active notifications. This API uses a promise to return th
```js ```js
Notification.getActiveNotificationCount().then((data) => { Notification.getActiveNotificationCount().then((data) => {
console.info("==========================>getActiveNotificationCountCallback=======================>"); console.info("getActiveNotificationCount sucess, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -1840,7 +1974,11 @@ Obtains active notifications of this application. This API uses an asynchronous ...@@ -1840,7 +1974,11 @@ Obtains active notifications of this application. This API uses an asynchronous
```js ```js
function getActiveNotificationsCallback(err, data) { function getActiveNotificationsCallback(err, data) {
console.info("==========================>getActiveNotificationsCallback=======================>"); if (err.code) {
console.info("getActiveNotifications failed " + JSON.stringify(err));
} else {
console.info("getActiveNotifications success");
}
} }
Notification.getActiveNotifications(getActiveNotificationsCallback); Notification.getActiveNotifications(getActiveNotificationsCallback);
...@@ -1866,7 +2004,7 @@ Obtains active notifications of this application. This API uses a promise to ret ...@@ -1866,7 +2004,7 @@ Obtains active notifications of this application. This API uses a promise to ret
```js ```js
Notification.getActiveNotifications().then((data) => { Notification.getActiveNotifications().then((data) => {
console.info("==========================>getActiveNotificationsCallback=======================>"); console.info("removeGroupByBundle sucess, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -1891,7 +2029,11 @@ Cancels a notification group of this application. This API uses an asynchronous ...@@ -1891,7 +2029,11 @@ Cancels a notification group of this application. This API uses an asynchronous
```js ```js
function cancelGroupCallback(err) { function cancelGroupCallback(err) {
console.info("==========================>cancelGroupCallback=======================>"); if (err.code) {
console.info("cancelGroup failed " + JSON.stringify(err));
} else {
console.info("cancelGroup success");
}
} }
var groupName = "GroupName"; var groupName = "GroupName";
...@@ -1920,7 +2062,7 @@ Cancels a notification group of this application. This API uses a promise to ret ...@@ -1920,7 +2062,7 @@ Cancels a notification group of this application. This API uses a promise to ret
```js ```js
var groupName = "GroupName"; var groupName = "GroupName";
Notification.cancelGroup(groupName).then(() => { Notification.cancelGroup(groupName).then(() => {
console.info("==========================>cancelGroupPromise=======================>"); console.info("cancelGroup sucess");
}); });
``` ```
...@@ -1950,7 +2092,11 @@ Removes a notification group for a specified bundle. This API uses an asynchrono ...@@ -1950,7 +2092,11 @@ Removes a notification group for a specified bundle. This API uses an asynchrono
```js ```js
function removeGroupByBundleCallback(err) { function removeGroupByBundleCallback(err) {
console.info("==========================>removeGroupByBundleCallback=======================>"); if (err.code) {
console.info("removeGroupByBundle failed " + JSON.stringify(err));
} else {
console.info("removeGroupByBundle success");
}
} }
var bundleOption = {bundle: "Bundle"}; var bundleOption = {bundle: "Bundle"};
...@@ -1986,7 +2132,7 @@ Removes a notification group for a specified bundle. This API uses a promise to ...@@ -1986,7 +2132,7 @@ Removes a notification group for a specified bundle. This API uses a promise to
var bundleOption = {bundle: "Bundle"}; var bundleOption = {bundle: "Bundle"};
var groupName = "GroupName"; var groupName = "GroupName";
Notification.removeGroupByBundle(bundleOption, groupName).then(() => { Notification.removeGroupByBundle(bundleOption, groupName).then(() => {
console.info("==========================>removeGroupByBundlePromise=======================>"); console.info("removeGroupByBundle sucess");
}); });
``` ```
...@@ -2015,7 +2161,11 @@ Sets the DND time. This API uses an asynchronous callback to return the result. ...@@ -2015,7 +2161,11 @@ Sets the DND time. This API uses an asynchronous callback to return the result.
```js ```js
function setDoNotDisturbDateCallback(err) { function setDoNotDisturbDateCallback(err) {
console.info("==========================>setDoNotDisturbDateCallback=======================>"); if (err.code) {
console.info("setDoNotDisturbDate failed " + JSON.stringify(err));
} else {
console.info("setDoNotDisturbDate success");
}
} }
var doNotDisturbDate = { var doNotDisturbDate = {
...@@ -2056,7 +2206,7 @@ var doNotDisturbDate = { ...@@ -2056,7 +2206,7 @@ var doNotDisturbDate = {
end: new Date(2021, 11, 15, 18, 0) end: new Date(2021, 11, 15, 18, 0)
} }
Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => { Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => {
console.info("==========================>setDoNotDisturbDatePromise=======================>"); console.info("setDoNotDisturbDate sucess");
}); });
``` ```
...@@ -2085,7 +2235,11 @@ Sets the DND time for a specified user. This API uses an asynchronous callback t ...@@ -2085,7 +2235,11 @@ Sets the DND time for a specified user. This API uses an asynchronous callback t
```js ```js
function setDoNotDisturbDateCallback(err) { function setDoNotDisturbDateCallback(err) {
console.info("==========================>setDoNotDisturbDateCallback=======================>"); if (err.code) {
console.info("setDoNotDisturbDate failed " + JSON.stringify(err));
} else {
console.info("setDoNotDisturbDate success");
}
} }
var doNotDisturbDate = { var doNotDisturbDate = {
...@@ -2132,7 +2286,7 @@ var doNotDisturbDate = { ...@@ -2132,7 +2286,7 @@ var doNotDisturbDate = {
var userId = 1 var userId = 1
Notification.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => { Notification.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => {
console.info("==========================>setDoNotDisturbDatePromise=======================>"); console.info("setDoNotDisturbDate sucess");
}); });
``` ```
...@@ -2159,7 +2313,11 @@ Obtains the DND time. This API uses an asynchronous callback to return the resul ...@@ -2159,7 +2313,11 @@ Obtains the DND time. This API uses an asynchronous callback to return the resul
```js ```js
function getDoNotDisturbDateCallback(err,data) { function getDoNotDisturbDateCallback(err,data) {
console.info("==========================>getDoNotDisturbDateCallback=======================>"); if (err.code) {
console.info("getDoNotDisturbDate failed " + JSON.stringify(err));
} else {
console.info("getDoNotDisturbDate success");
}
} }
Notification.getDoNotDisturbDate(getDoNotDisturbDateCallback); Notification.getDoNotDisturbDate(getDoNotDisturbDateCallback);
...@@ -2189,7 +2347,7 @@ Obtains the DND time. This API uses a promise to return the result. ...@@ -2189,7 +2347,7 @@ Obtains the DND time. This API uses a promise to return the result.
```js ```js
Notification.getDoNotDisturbDate().then((data) => { Notification.getDoNotDisturbDate().then((data) => {
console.info("==========================>getDoNotDisturbDatePromise=======================>"); console.info("getDoNotDisturbDate sucess, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -2217,7 +2375,11 @@ Obtains the DND time of a specified user. This API uses an asynchronous callback ...@@ -2217,7 +2375,11 @@ Obtains the DND time of a specified user. This API uses an asynchronous callback
```js ```js
function getDoNotDisturbDateCallback(err,data) { function getDoNotDisturbDateCallback(err,data) {
console.info("==========================>getDoNotDisturbDateCallback=======================>"); if (err.code) {
console.info("getDoNotDisturbDate failed " + JSON.stringify(err));
} else {
console.info("getDoNotDisturbDate success");
}
} }
var userId = 1 var userId = 1
...@@ -2257,7 +2419,7 @@ Obtains the DND time of a specified user. This API uses a promise to return the ...@@ -2257,7 +2419,7 @@ Obtains the DND time of a specified user. This API uses a promise to return the
var userId = 1 var userId = 1
Notification.getDoNotDisturbDate(userId).then((data) => { Notification.getDoNotDisturbDate(userId).then((data) => {
console.info("==========================>getDoNotDisturbDatePromise=======================>"); console.info("getDoNotDisturbDate sucess, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -2284,7 +2446,11 @@ Checks whether the DND mode is supported. This API uses an asynchronous callback ...@@ -2284,7 +2446,11 @@ Checks whether the DND mode is supported. This API uses an asynchronous callback
```js ```js
function supportDoNotDisturbModeCallback(err,data) { function supportDoNotDisturbModeCallback(err,data) {
console.info("==========================>supportDoNotDisturbModeCallback=======================>"); if (err.code) {
console.info("supportDoNotDisturbMode failed " + JSON.stringify(err));
} else {
console.info("supportDoNotDisturbMode success");
}
} }
Notification.supportDoNotDisturbMode(supportDoNotDisturbModeCallback); Notification.supportDoNotDisturbMode(supportDoNotDisturbModeCallback);
...@@ -2314,7 +2480,7 @@ Checks whether the DND mode is supported. This API uses a promise to return the ...@@ -2314,7 +2480,7 @@ Checks whether the DND mode is supported. This API uses a promise to return the
```js ```js
Notification.supportDoNotDisturbMode().then((data) => { Notification.supportDoNotDisturbMode().then((data) => {
console.info("==========================>supportDoNotDisturbModePromise=======================>"); console.info("supportDoNotDisturbMode sucess, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -2340,7 +2506,11 @@ Checks whether a specified template exists. This API uses an asynchronous callba ...@@ -2340,7 +2506,11 @@ Checks whether a specified template exists. This API uses an asynchronous callba
```javascript ```javascript
var templateName = 'process'; var templateName = 'process';
function isSupportTemplateCallback(err, data) { function isSupportTemplateCallback(err, data) {
console.info("isSupportTemplateCallback"); if (err.code) {
console.info("isSupportTemplate failed " + JSON.stringify(err));
} else {
console.info("isSupportTemplate success");
}
} }
Notification.isSupportTemplate(templateName, isSupportTemplateCallback); Notification.isSupportTemplate(templateName, isSupportTemplateCallback);
...@@ -2374,7 +2544,7 @@ Checks whether a specified template exists. This API uses a promise to return th ...@@ -2374,7 +2544,7 @@ Checks whether a specified template exists. This API uses a promise to return th
var templateName = 'process'; var templateName = 'process';
Notification.isSupportTemplate(templateName).then((data) => { Notification.isSupportTemplate(templateName).then((data) => {
console.info("isSupportTemplateCallback"); console.info("isSupportTemplate success, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -2398,7 +2568,11 @@ Requests notification to be enabled for this application. This API uses an async ...@@ -2398,7 +2568,11 @@ Requests notification to be enabled for this application. This API uses an async
```javascript ```javascript
function requestEnableNotificationCallback() { function requestEnableNotificationCallback() {
console.log('------------- requestEnabledNotification --------------'); if (err.code) {
console.info("requestEnableNotification failed " + JSON.stringify(err));
} else {
console.info("requestEnableNotification success");
}
}; };
Notification.requestEnableNotification(requestEnableNotificationCallback); Notification.requestEnableNotification(requestEnableNotificationCallback);
...@@ -2419,7 +2593,7 @@ Requests notification to be enabled for this application. This API uses a promis ...@@ -2419,7 +2593,7 @@ Requests notification to be enabled for this application. This API uses a promis
```javascript ```javascript
Notification.requestEnableNotification() Notification.requestEnableNotification()
.then(() => { .then(() => {
console.info("requestEnableNotification "); console.info("requestEnableNotification sucess");
}); });
``` ```
...@@ -2447,7 +2621,11 @@ Sets whether this device supports distributed notifications. This API uses an as ...@@ -2447,7 +2621,11 @@ Sets whether this device supports distributed notifications. This API uses an as
```javascript ```javascript
function enabledNotificationCallback() { function enabledNotificationCallback() {
console.log('----------- enableDistributed ------------'); if (err.code) {
console.info("enableDistributed failed " + JSON.stringify(err));
} else {
console.info("enableDistributed success");
}
}; };
var enable = true var enable = true
...@@ -2482,7 +2660,7 @@ var enable = true ...@@ -2482,7 +2660,7 @@ var enable = true
Notification.enableDistributed(enable) Notification.enableDistributed(enable)
.then(() => { .then(() => {
console.log('-------- enableDistributed ----------'); console.info("enableDistributed sucess");
}); });
``` ```
...@@ -2505,7 +2683,11 @@ Obtains whether this device supports distributed notifications. This API uses an ...@@ -2505,7 +2683,11 @@ Obtains whether this device supports distributed notifications. This API uses an
```javascript ```javascript
function isDistributedEnabledCallback() { function isDistributedEnabledCallback() {
console.log('----------- isDistributedEnabled ------------'); if (err.code) {
console.info("isDistributedEnabled failed " + JSON.stringify(err));
} else {
console.info("isDistributedEnabled success");
}
}; };
Notification.isDistributedEnabled(isDistributedEnabledCallback); Notification.isDistributedEnabled(isDistributedEnabledCallback);
...@@ -2532,7 +2714,7 @@ Obtains whether this device supports distributed notifications. This API uses a ...@@ -2532,7 +2714,7 @@ Obtains whether this device supports distributed notifications. This API uses a
```javascript ```javascript
Notification.isDistributedEnabled() Notification.isDistributedEnabled()
.then((data) => { .then((data) => {
console.log('-------- isDistributedEnabled ----------'); console.info("isDistributedEnabled sucess, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -2561,7 +2743,11 @@ Sets whether an application supports distributed notifications based on the bund ...@@ -2561,7 +2743,11 @@ Sets whether an application supports distributed notifications based on the bund
```javascript ```javascript
function enableDistributedByBundleCallback() { function enableDistributedByBundleCallback() {
console.log('----------- enableDistributedByBundle ------------'); if (err.code) {
console.info("enableDistributedByBundle failed " + JSON.stringify(err));
} else {
console.info("enableDistributedByBundle success");
}
}; };
var bundle = { var bundle = {
...@@ -2605,7 +2791,7 @@ var enable = true ...@@ -2605,7 +2791,7 @@ var enable = true
Notification.enableDistributedByBundle(bundle, enable) Notification.enableDistributedByBundle(bundle, enable)
.then(() => { .then(() => {
console.log('-------- enableDistributedByBundle ----------'); console.info("enableDistributedByBundle sucess");
}); });
``` ```
...@@ -2632,7 +2818,11 @@ Obtains whether an application supports distributed notifications based on the b ...@@ -2632,7 +2818,11 @@ Obtains whether an application supports distributed notifications based on the b
```javascript ```javascript
function isDistributedEnabledByBundleCallback(data) { function isDistributedEnabledByBundleCallback(data) {
console.log('----------- isDistributedEnabledByBundle ------------', data); if (err.code) {
console.info("isDistributedEnabledByBundle failed " + JSON.stringify(err));
} else {
console.info("isDistributedEnabledByBundle success");
}
}; };
var bundle = { var bundle = {
...@@ -2677,7 +2867,7 @@ var bundle = { ...@@ -2677,7 +2867,7 @@ var bundle = {
Notification.isDistributedEnabledByBundle(bundle) Notification.isDistributedEnabledByBundle(bundle)
.then((data) => { .then((data) => {
console.log('-------- isDistributedEnabledByBundle ----------', data); console.info("isDistributedEnabledByBundle sucess, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -2704,7 +2894,11 @@ Obtains the notification reminder type. This API uses an asynchronous callback t ...@@ -2704,7 +2894,11 @@ Obtains the notification reminder type. This API uses an asynchronous callback t
```javascript ```javascript
function getDeviceRemindTypeCallback(data) { function getDeviceRemindTypeCallback(data) {
console.log('----------- getDeviceRemindType ------------', data); if (err.code) {
console.info("getDeviceRemindType failed " + JSON.stringify(err));
} else {
console.info("getDeviceRemindType success");
}
}; };
Notification.getDeviceRemindType(getDeviceRemindTypeCallback); Notification.getDeviceRemindType(getDeviceRemindTypeCallback);
...@@ -2735,7 +2929,7 @@ Obtains the notification reminder type. This API uses a promise to return the re ...@@ -2735,7 +2929,7 @@ Obtains the notification reminder type. This API uses a promise to return the re
```javascript ```javascript
Notification.getDeviceRemindType() Notification.getDeviceRemindType()
.then((data) => { .then((data) => {
console.log('-------- getDeviceRemindType ----------', data); console.info("getDeviceRemindType sucess, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -2766,7 +2960,11 @@ Publishes an agent-powered notification. This API uses an asynchronous callback ...@@ -2766,7 +2960,11 @@ Publishes an agent-powered notification. This API uses an asynchronous callback
```js ```js
// Callback for publishAsBundle // Callback for publishAsBundle
function publishAsBundleCallback(err) { function publishAsBundleCallback(err) {
console.info("==========================>publishAsBundleCallback=======================>"); if (err.code) {
console.info("publishAsBundle failed " + JSON.stringify(err));
} else {
console.info("publishAsBundle success");
}
} }
// Bundle name of the application whose notification function is taken over by the reminder agent // Bundle name of the application whose notification function is taken over by the reminder agent
let representativeBundle = "com.example.demo" let representativeBundle = "com.example.demo"
...@@ -2830,7 +3028,7 @@ var notificationRequest = { ...@@ -2830,7 +3028,7 @@ var notificationRequest = {
} }
Notification.publishAsBundle(notificationRequest, representativeBundle, userId).then(() => { Notification.publishAsBundle(notificationRequest, representativeBundle, userId).then(() => {
console.info("==========================>publishAsBundleCallback=======================>"); console.info("publishAsBundle sucess");
}); });
``` ```
...@@ -2862,7 +3060,11 @@ Cancels a notification published by the reminder agent. This API uses an asynchr ...@@ -2862,7 +3060,11 @@ Cancels a notification published by the reminder agent. This API uses an asynchr
```js ```js
//cancelAsBundle //cancelAsBundle
function cancelAsBundleCallback(err) { function cancelAsBundleCallback(err) {
console.info("==========================>cancelAsBundleCallback=======================>"); if (err.code) {
console.info("cancelAsBundle failed " + JSON.stringify(err));
} else {
console.info("cancelAsBundle success");
}
} }
// Bundle name of the application whose notification function is taken over by the reminder agent // Bundle name of the application whose notification function is taken over by the reminder agent
let representativeBundle = "com.example.demo" let representativeBundle = "com.example.demo"
...@@ -2903,7 +3105,7 @@ let representativeBundle = "com.example.demo" ...@@ -2903,7 +3105,7 @@ let representativeBundle = "com.example.demo"
let userId = 100 let userId = 100
Notification.cancelAsBundle(0, representativeBundle, userId).then(() => { Notification.cancelAsBundle(0, representativeBundle, userId).then(() => {
console.info("==========================>cancelAsBundleCallback=======================>"); console.info("cancelAsBundle success");
}); });
``` ```
...@@ -2933,7 +3135,11 @@ Sets the enabled status for a notification slot of a specified type. This API us ...@@ -2933,7 +3135,11 @@ Sets the enabled status for a notification slot of a specified type. This API us
```js ```js
//enableNotificationSlot //enableNotificationSlot
function enableSlotCallback(err) { function enableSlotCallback(err) {
console.log('===================>enableSlotCallback==================>'); if (err.code) {
console.info("enableNotificationSlot failed " + JSON.stringify(err));
} else {
console.info("enableNotificationSlot success");
}
}; };
Notification.enableNotificationSlot( Notification.enableNotificationSlot(
...@@ -2971,7 +3177,7 @@ Notification.enableNotificationSlot( ...@@ -2971,7 +3177,7 @@ Notification.enableNotificationSlot(
{ bundle: "ohos.samples.notification", }, { bundle: "ohos.samples.notification", },
Notification.SlotType.SOCIAL_COMMUNICATION, Notification.SlotType.SOCIAL_COMMUNICATION,
true).then(() => { true).then(() => {
console.log('====================>enableNotificationSlot====================>'); console.info("enableNotificationSlot sucess");
}); });
``` ```
...@@ -3000,7 +3206,11 @@ Obtains the enabled status of the notification slot of a specified type. This AP ...@@ -3000,7 +3206,11 @@ Obtains the enabled status of the notification slot of a specified type. This AP
```js ```js
//isNotificationSlotEnabled //isNotificationSlotEnabled
function getEnableSlotCallback(err, data) { function getEnableSlotCallback(err, data) {
console.log('===================>getEnableSlotCallback=================='); if (err.code) {
console.info("isNotificationSlotEnabled failed " + JSON.stringify(err));
} else {
console.info("isNotificationSlotEnabled success");
}
}; };
Notification.isNotificationSlotEnabled( Notification.isNotificationSlotEnabled(
...@@ -3042,7 +3252,7 @@ Notification.isNotificationSlotEnabled( ...@@ -3042,7 +3252,7 @@ Notification.isNotificationSlotEnabled(
{ bundle: "ohos.samples.notification", }, { bundle: "ohos.samples.notification", },
Notification.SlotType.SOCIAL_COMMUNICATION Notification.SlotType.SOCIAL_COMMUNICATION
).then((data) => { ).then((data) => {
console.log('====================>isNotificationSlotEnabled====================>'); console.info("isNotificationSlotEnabled success, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -3074,7 +3284,11 @@ let userId = 100; ...@@ -3074,7 +3284,11 @@ let userId = 100;
let enable = true; let enable = true;
function setSyncNotificationEnabledWithoutAppCallback(err) { function setSyncNotificationEnabledWithoutAppCallback(err) {
console.log('setSyncNotificationEnabledWithoutAppCallback'); if (err.code) {
console.info("setSyncNotificationEnabledWithoutApp failed " + JSON.stringify(err));
} else {
console.info("setSyncNotificationEnabledWithoutApp success");
}
} }
Notification.setSyncNotificationEnabledWithoutApp(userId, enable, setSyncNotificationEnabledWithoutAppCallback); Notification.setSyncNotificationEnabledWithoutApp(userId, enable, setSyncNotificationEnabledWithoutAppCallback);
...@@ -3113,11 +3327,11 @@ let userId = 100; ...@@ -3113,11 +3327,11 @@ let userId = 100;
let enable = true; let enable = true;
Notification.setSyncNotificationEnabledWithoutApp(userId, enable) Notification.setSyncNotificationEnabledWithoutApp(userId, enable)
.then((data) => { .then(() => {
console.log('setSyncNotificationEnabledWithoutApp'); console.info('setSyncNotificationEnabledWithoutApp');
}) })
.catch((err) => { .catch((err) => {
console.log('setSyncNotificationEnabledWithoutApp, err:', err); console.info('setSyncNotificationEnabledWithoutApp, err:', err);
}); });
``` ```
...@@ -3148,9 +3362,9 @@ let userId = 100; ...@@ -3148,9 +3362,9 @@ let userId = 100;
function getSyncNotificationEnabledWithoutAppCallback(data, err) { function getSyncNotificationEnabledWithoutAppCallback(data, err) {
if (err) { if (err) {
console.log('getSyncNotificationEnabledWithoutAppCallback, err' + err); console.info('getSyncNotificationEnabledWithoutAppCallback, err' + err);
} else { } else {
console.log('getSyncNotificationEnabledWithoutAppCallback, data' + data); console.info('getSyncNotificationEnabledWithoutAppCallback, data' + data);
} }
} }
...@@ -3189,10 +3403,10 @@ let userId = 100; ...@@ -3189,10 +3403,10 @@ let userId = 100;
Notification.getSyncNotificationEnabledWithoutApp(userId) Notification.getSyncNotificationEnabledWithoutApp(userId)
.then((data) => { .then((data) => {
console.log('getSyncNotificationEnabledWithoutApp, data:', data); console.info('getSyncNotificationEnabledWithoutApp, data:', data);
}) })
.catch((err) => { .catch((err) => {
console.log('getSyncNotificationEnabledWithoutApp, err:', err); console.info('getSyncNotificationEnabledWithoutApp, err:', err);
}); });
``` ```
...@@ -3236,7 +3450,7 @@ function onConsumeCallback(data) { ...@@ -3236,7 +3450,7 @@ function onConsumeCallback(data) {
let wantAgent = data.wantAgent; let wantAgent = data.wantAgent;
wantAgent .getWant(wantAgent) wantAgent .getWant(wantAgent)
.then((data1) => { .then((data1) => {
console.log('===> getWant success want:' + JSON.stringify(data1)); console.info('===> getWant success want:' + JSON.stringify(data1));
}) })
.catch((err) => { .catch((err) => {
console.error('===> getWant failed because' + JSON.stringify(err)); console.error('===> getWant failed because' + JSON.stringify(err));
...@@ -3877,3 +4091,14 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -3877,3 +4091,14 @@ Notification.subscribe(subscriber, subscribeCallback);
| TYPE_NORMAL | 0 | Normal notification. | | TYPE_NORMAL | 0 | Normal notification. |
| TYPE_CONTINUOUS | 1 | Continuous notification. | | TYPE_CONTINUOUS | 1 | Continuous notification. |
| TYPE_TIMER | 2 | Timed notification. | | TYPE_TIMER | 2 | Timed notification. |
## RemoveReason<sup>9+</sup>
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Value | Description |
| -------------------- | --- | -------------------- |
| CLICK_REASON_REMOVE | 1 | The notification is removed due to a click on it. |
| CANCEL_REASON_REMOVE | 2 | The notification is removed by the user. |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册