“285f33e5607fa8583d8b74b1f20082c46026f9af”上不存在“paddle/fluid/git@gitcode.net:RobotFutures/Paddle.git”
提交 6805dd0f 编写于 作者: E esterzhou

update docs (12231)

Signed-off-by: Nesterzhou <ester.zhou@huawei.com>
上级 8c512bd4
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
The **Notification** module provides notification management capabilities, covering notifications, notification slots, notification subscription, notification enabled status, and notification badge status. The **Notification** module provides notification management capabilities, covering notifications, notification slots, notification subscription, notification enabled status, and notification badge status.
Generally, only system applications have the permission to subscribe to and unsubscribe from notifications.
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> Notification subscription and unsubscription APIs are available only to system applications.
## Modules to Import ## Modules to Import
...@@ -26,8 +26,8 @@ Publishes a notification. This API uses an asynchronous callback to return the r ...@@ -26,8 +26,8 @@ Publishes a notification. This API uses an asynchronous callback to return the r
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | ------------------------------------------- | | -------- | ------------------------------------------- | ---- | ------------------------------------------- |
| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| | request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -69,7 +69,7 @@ Publishes a notification. This API uses a promise to return the result. ...@@ -69,7 +69,7 @@ Publishes a notification. This API uses a promise to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | ------------------------------------------- | | -------- | ------------------------------------------- | ---- | ------------------------------------------- |
| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| | request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.|
**Example** **Example**
...@@ -87,7 +87,7 @@ var notificationRequest = { ...@@ -87,7 +87,7 @@ var notificationRequest = {
} }
} }
Notification.publish(notificationRequest).then(() => { Notification.publish(notificationRequest).then(() => {
console.info("publish sucess"); console.info("publish success");
}); });
``` ```
...@@ -96,7 +96,7 @@ Notification.publish(notificationRequest).then(() => { ...@@ -96,7 +96,7 @@ Notification.publish(notificationRequest).then(() => {
publish(request: NotificationRequest, userId: number, callback: AsyncCallback\<void\>): void publish(request: NotificationRequest, userId: number, callback: AsyncCallback\<void\>): void
Publishes a notification. This API uses an asynchronous callback to return the result. Publishes a notification to a specified user. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -108,8 +108,8 @@ Publishes a notification. This API uses an asynchronous callback to return the r ...@@ -108,8 +108,8 @@ Publishes a notification. This API uses an asynchronous callback to return the r
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------------------------- | | -------- | ----------------------------------------- | ---- | ------------------------------------------- |
| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| | request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.|
| userId | number | Yes | ID of the user who receives the notification. | | userId | number | Yes | User ID. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -123,7 +123,7 @@ function publishCallback(err) { ...@@ -123,7 +123,7 @@ function publishCallback(err) {
console.info("publish success"); console.info("publish success");
} }
} }
// ID of the user who receives the notification // User ID
var userId = 1 var userId = 1
// NotificationRequest object // NotificationRequest object
var notificationRequest = { var notificationRequest = {
...@@ -144,7 +144,7 @@ Notification.publish(notificationRequest, userId, publishCallback); ...@@ -144,7 +144,7 @@ Notification.publish(notificationRequest, userId, publishCallback);
publish(request: NotificationRequest, userId: number): Promise\<void\> publish(request: NotificationRequest, userId: number): Promise\<void\>
Publishes a notification. This API uses a promise to return the result. Publishes a notification to a specified user. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -156,8 +156,8 @@ Publishes a notification. This API uses a promise to return the result. ...@@ -156,8 +156,8 @@ Publishes a notification. This API uses a promise to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------------------------- | | -------- | ----------------------------------------- | ---- | ------------------------------------------- |
| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| | request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.|
| userId | number | Yes | ID of the user who receives the notification. | | userId | number | Yes | User ID. |
**Example** **Example**
...@@ -177,7 +177,7 @@ var notificationRequest = { ...@@ -177,7 +177,7 @@ var notificationRequest = {
var userId = 1 var userId = 1
Notification.publish(notificationRequest, userId).then(() => { Notification.publish(notificationRequest, userId).then(() => {
console.info("publish sucess"); console.info("publish success");
}); });
``` ```
...@@ -218,7 +218,7 @@ Notification.cancel(0, "label", cancelCallback) ...@@ -218,7 +218,7 @@ Notification.cancel(0, "label", cancelCallback)
cancel(id: number, label?: string): Promise\<void\> cancel(id: number, label?: string): Promise\<void\>
Cancels a notification with the specified ID and label. This API uses a promise to return the result. Cancels a notification with the specified ID and optional label. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -233,7 +233,7 @@ Cancels a notification with the specified ID and label. This API uses a promise ...@@ -233,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("cancel sucess"); console.info("cancel success");
}); });
``` ```
...@@ -312,7 +312,7 @@ Cancels all notifications. This API uses a promise to return the result. ...@@ -312,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("cancelAll sucess"); console.info("cancelAll success");
}); });
``` ```
...@@ -383,7 +383,7 @@ var notificationSlot = { ...@@ -383,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("addSlot sucess"); console.info("addSlot success");
}); });
``` ```
...@@ -393,7 +393,7 @@ Notification.addSlot(notificationSlot).then(() => { ...@@ -393,7 +393,7 @@ Notification.addSlot(notificationSlot).then(() => {
addSlot(type: SlotType, callback: AsyncCallback\<void\>): void addSlot(type: SlotType, callback: AsyncCallback\<void\>): void
Adds a notification slot. This API uses an asynchronous callback to return the result. Adds a notification slot of a specified type. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -424,7 +424,7 @@ Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack ...@@ -424,7 +424,7 @@ Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack
addSlot(type: SlotType): Promise\<void\> addSlot(type: SlotType): Promise\<void\>
Adds a notification slot. This API uses a promise to return the result. Adds a notification slot of a specified type. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -438,7 +438,7 @@ Adds a notification slot. This API uses a promise to return the result. ...@@ -438,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("addSlot sucess"); console.info("addSlot success");
}); });
``` ```
...@@ -448,7 +448,7 @@ Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => { ...@@ -448,7 +448,7 @@ Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => {
addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>): void addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>): void
Adds multiple notification slots. This API uses an asynchronous callback to return the result. Adds an array of notification slots. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -491,7 +491,7 @@ Notification.addSlots(notificationSlotArray, addSlotsCallBack) ...@@ -491,7 +491,7 @@ Notification.addSlots(notificationSlotArray, addSlotsCallBack)
addSlots(slots: Array\<NotificationSlot\>): Promise\<void\> addSlots(slots: Array\<NotificationSlot\>): Promise\<void\>
Adds multiple notification slots. This API uses a promise to return the result. Adds an array of notification slots. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -517,7 +517,7 @@ var notificationSlotArray = new Array(); ...@@ -517,7 +517,7 @@ var notificationSlotArray = new Array();
notificationSlotArray[0] = notificationSlot; notificationSlotArray[0] = notificationSlot;
Notification.addSlots(notificationSlotArray).then(() => { Notification.addSlots(notificationSlotArray).then(() => {
console.info("addSlots sucess"); console.info("addSlots success");
}); });
``` ```
...@@ -527,7 +527,7 @@ Notification.addSlots(notificationSlotArray).then(() => { ...@@ -527,7 +527,7 @@ Notification.addSlots(notificationSlotArray).then(() => {
getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>): void getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>): void
Obtains a notification slot of the specified type. This API uses an asynchronous callback to return the result. Obtains a notification slot of a specified type. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -542,7 +542,7 @@ Obtains a notification slot of the specified type. This API uses an asynchronous ...@@ -542,7 +542,7 @@ 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) {
if (err.code) { if (err.code) {
console.info("getSlot failed " + JSON.stringify(err)); console.info("getSlot failed " + JSON.stringify(err));
} else { } else {
...@@ -559,7 +559,7 @@ Notification.getSlot(slotType, getSlotCallback) ...@@ -559,7 +559,7 @@ Notification.getSlot(slotType, getSlotCallback)
getSlot(slotType: SlotType): Promise\<NotificationSlot\> getSlot(slotType: SlotType): Promise\<NotificationSlot\>
Obtains a notification slot of the specified type. This API uses a promise to return the result. Obtains a notification slot of a specified type. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -580,7 +580,7 @@ Obtains a notification slot of the specified type. This API uses a promise to re ...@@ -580,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("getSlot sucess, data: " + JSON.stringify(data)); console.info("getSlot success, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -604,7 +604,7 @@ Obtains all notification slots. This API uses an asynchronous callback to return ...@@ -604,7 +604,7 @@ 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) {
if (err.code) { if (err.code) {
console.info("getSlots failed " + JSON.stringify(err)); console.info("getSlots failed " + JSON.stringify(err));
} else { } else {
...@@ -634,7 +634,7 @@ Obtains all notification slots of this application. This API uses a promise to r ...@@ -634,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("getSlots sucess, data: " + JSON.stringify(data)); console.info("getSlots success, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -644,7 +644,7 @@ Notification.getSlots().then((data) => { ...@@ -644,7 +644,7 @@ Notification.getSlots().then((data) => {
removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>): void removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>): void
Removes a notification slot of the specified type. This API uses an asynchronous callback to return the result. Removes a notification slot of a specified type. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -676,7 +676,7 @@ Notification.removeSlot(slotType,removeSlotCallback) ...@@ -676,7 +676,7 @@ Notification.removeSlot(slotType,removeSlotCallback)
removeSlot(slotType: SlotType): Promise\<void\> removeSlot(slotType: SlotType): Promise\<void\>
Removes a notification slot of the specified type. This API uses a promise to return the result. Removes a notification slot of a specified type. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -691,7 +691,7 @@ Removes a notification slot of the specified type. This API uses a promise to re ...@@ -691,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("removeSlot sucess"); console.info("removeSlot success");
}); });
``` ```
...@@ -738,7 +738,7 @@ Removes all notification slots. This API uses a promise to return the result. ...@@ -738,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("removeAllSlots sucess"); console.info("removeAllSlots success");
}); });
``` ```
...@@ -761,7 +761,7 @@ Subscribes to a notification with the subscription information specified. This A ...@@ -761,7 +761,7 @@ Subscribes to a notification with the subscription information specified. This A
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | ------------------------- | ---- | ---------------- | | ---------- | ------------------------- | ---- | ---------------- |
| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. | | subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. |
| info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | Yes | Subscription information. | | info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | Yes | Notification subscription information.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -782,7 +782,7 @@ var subscriber = { ...@@ -782,7 +782,7 @@ var subscriber = {
onConsume: onConsumeCallback onConsume: onConsumeCallback
} }
var info = { var info = {
bundleNames: ["bundleName1","bundleName2"] bundleNames: ["bundleName1", "bundleName2"]
} }
Notification.subscribe(subscriber, info, subscribeCallback); Notification.subscribe(subscriber, info, subscribeCallback);
``` ```
...@@ -793,7 +793,7 @@ Notification.subscribe(subscriber, info, subscribeCallback); ...@@ -793,7 +793,7 @@ Notification.subscribe(subscriber, info, subscribeCallback);
subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>): void subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>): void
Subscribes to a notification with the subscription information specified. This API uses an asynchronous callback to return the result. Subscribes to notifications of all applications under this user. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -846,7 +846,7 @@ Subscribes to a notification with the subscription information specified. This A ...@@ -846,7 +846,7 @@ Subscribes to a notification with the subscription information specified. This A
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | ------------------------- | ---- | ------------ | | ---------- | ------------------------- | ---- | ------------ |
| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber.| | subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber.|
| info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | No | Subscription information. | | info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | No | Notification subscription information. |
**Example** **Example**
...@@ -858,7 +858,7 @@ var subscriber = { ...@@ -858,7 +858,7 @@ var subscriber = {
onConsume: onConsumeCallback onConsume: onConsumeCallback
}; };
Notification.subscribe(subscriber).then(() => { Notification.subscribe(subscriber).then(() => {
console.info("subscribe sucess"); console.info("subscribe success");
}); });
``` ```
...@@ -893,11 +893,11 @@ function unsubscribeCallback(err) { ...@@ -893,11 +893,11 @@ function unsubscribeCallback(err) {
console.info("unsubscribe success"); console.info("unsubscribe success");
} }
} }
function onCancelCallback(data) { function onDisconnectCallback(data) {
console.info("Cancel callback: " + JSON.stringify(data)); console.info("Cancel callback: " + JSON.stringify(data));
} }
var subscriber = { var subscriber = {
onCancel: onCancelCallback onDisconnect: onDisconnectCallback
} }
Notification.unsubscribe(subscriber, unsubscribeCallback); Notification.unsubscribe(subscriber, unsubscribeCallback);
``` ```
...@@ -925,14 +925,14 @@ Unsubscribes from a notification. This API uses a promise to return the result. ...@@ -925,14 +925,14 @@ Unsubscribes from a notification. This API uses a promise to return the result.
**Example** **Example**
```js ```js
function onCancelCallback(data) { function onDisconnectCallback(data) {
console.info("Cancel callback: " + JSON.stringify(data)); console.info("Cancel callback: " + JSON.stringify(data));
} }
var subscriber = { var subscriber = {
onCancel: onCancelCallback onDisconnect: onDisconnectCallback
}; };
Notification.unsubscribe(subscriber).then(() => { Notification.unsubscribe(subscriber).then(() => {
console.info("unsubscribe sucess"); console.info("unsubscribe success");
}); });
``` ```
...@@ -942,7 +942,7 @@ Notification.unsubscribe(subscriber).then(() => { ...@@ -942,7 +942,7 @@ Notification.unsubscribe(subscriber).then(() => {
enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void
Sets whether to enable notification for a specified bundle. This API uses an asynchronous callback to return the result. Sets whether to enable notification for a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -954,7 +954,7 @@ Sets whether to enable notification for a specified bundle. This API uses an asy ...@@ -954,7 +954,7 @@ Sets whether to enable notification for a specified bundle. This API uses an asy
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | -------------------- | | -------- | --------------------- | ---- | -------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| enable | boolean | Yes | Whether to enable notification. | | enable | boolean | Yes | Whether to enable notification. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
...@@ -980,7 +980,7 @@ Notification.enableNotification(bundle, false, enableNotificationCallback); ...@@ -980,7 +980,7 @@ Notification.enableNotification(bundle, false, enableNotificationCallback);
enableNotification(bundle: BundleOption, enable: boolean): Promise\<void\> enableNotification(bundle: BundleOption, enable: boolean): Promise\<void\>
Sets whether to enable notification for a specified bundle. This API uses a promise to return the result. Sets whether to enable notification for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -992,7 +992,7 @@ Sets whether to enable notification for a specified bundle. This API uses a prom ...@@ -992,7 +992,7 @@ Sets whether to enable notification for a specified bundle. This API uses a prom
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- | | ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.|
| enable | boolean | Yes | Whether to enable notification. | | enable | boolean | Yes | Whether to enable notification. |
**Example** **Example**
...@@ -1002,7 +1002,7 @@ var bundle = { ...@@ -1002,7 +1002,7 @@ var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
} }
Notification.enableNotification(bundle, false).then(() => { Notification.enableNotification(bundle, false).then(() => {
console.info("enableNotification sucess"); console.info("enableNotification success");
}); });
``` ```
...@@ -1012,7 +1012,7 @@ Notification.enableNotification(bundle, false).then(() => { ...@@ -1012,7 +1012,7 @@ Notification.enableNotification(bundle, false).then(() => {
isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void
Checks whether notification is enabled for a specified bundle. This API uses an asynchronous callback to return the result. Checks whether notification is enabled for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -1024,7 +1024,7 @@ Checks whether notification is enabled for a specified bundle. This API uses an ...@@ -1024,7 +1024,7 @@ Checks whether notification is enabled for a specified bundle. This API uses an
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------------ | | -------- | --------------------- | ---- | ------------------------ |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -1049,7 +1049,7 @@ Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback); ...@@ -1049,7 +1049,7 @@ Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback);
isNotificationEnabled(bundle: BundleOption): Promise\<boolean\> isNotificationEnabled(bundle: BundleOption): Promise\<boolean\>
Checks whether notification is enabled for a specified bundle. This API uses a promise to return the result. Checks whether notification is enabled for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -1061,12 +1061,12 @@ Checks whether notification is enabled for a specified bundle. This API uses a p ...@@ -1061,12 +1061,12 @@ Checks whether notification is enabled for a specified bundle. This API uses a p
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- | | ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ------------------ | --------------------------------------------------- |
| Promise\<boolean\> | Promise used to return the result.| | Promise\<boolean\> | Promise used to return the result.|
**Example** **Example**
...@@ -1076,7 +1076,7 @@ var bundle = { ...@@ -1076,7 +1076,7 @@ var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
} }
Notification.isNotificationEnabled(bundle).then((data) => { Notification.isNotificationEnabled(bundle).then((data) => {
console.info("isNotificationEnabled sucess, data: " + JSON.stringify(data)); console.info("isNotificationEnabled success, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -1132,7 +1132,7 @@ Checks whether notification is enabled for this application. This API uses a pro ...@@ -1132,7 +1132,7 @@ Checks whether notification is enabled for this application. This API uses a pro
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- | | ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.|
**Return value** **Return value**
...@@ -1144,7 +1144,7 @@ Checks whether notification is enabled for this application. This API uses a pro ...@@ -1144,7 +1144,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("isNotificationEnabled sucess, data: " + JSON.stringify(data)); console.info("isNotificationEnabled success, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -1154,7 +1154,7 @@ Notification.isNotificationEnabled().then((data) => { ...@@ -1154,7 +1154,7 @@ Notification.isNotificationEnabled().then((data) => {
displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void
Sets whether to enable the notification badge for a specified bundle. This API uses an asynchronous callback to return the result. Sets whether to enable the notification badge for a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -1166,7 +1166,7 @@ Sets whether to enable the notification badge for a specified bundle. This API u ...@@ -1166,7 +1166,7 @@ Sets whether to enable the notification badge for a specified bundle. This API u
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | -------------------- | | -------- | --------------------- | ---- | -------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| enable | boolean | Yes | Whether to enable notification. | | enable | boolean | Yes | Whether to enable notification. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
...@@ -1192,7 +1192,7 @@ Notification.displayBadge(bundle, false, displayBadgeCallback); ...@@ -1192,7 +1192,7 @@ Notification.displayBadge(bundle, false, displayBadgeCallback);
displayBadge(bundle: BundleOption, enable: boolean): Promise\<void\> displayBadge(bundle: BundleOption, enable: boolean): Promise\<void\>
Sets the notification slot for a specified bundle. This API uses a promise to return the result. Sets whether to enable the notification badge for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -1204,7 +1204,7 @@ Sets the notification slot for a specified bundle. This API uses a promise to re ...@@ -1204,7 +1204,7 @@ Sets the notification slot for a specified bundle. This API uses a promise to re
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- | | ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.|
| enable | boolean | Yes | Whether to enable notification. | | enable | boolean | Yes | Whether to enable notification. |
**Example** **Example**
...@@ -1214,7 +1214,7 @@ var bundle = { ...@@ -1214,7 +1214,7 @@ var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
} }
Notification.displayBadge(bundle, false).then(() => { Notification.displayBadge(bundle, false).then(() => {
console.info("displayBadge sucess"); console.info("displayBadge success");
}); });
``` ```
...@@ -1224,7 +1224,7 @@ Notification.displayBadge(bundle, false).then(() => { ...@@ -1224,7 +1224,7 @@ Notification.displayBadge(bundle, false).then(() => {
isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void
Checks whether the notification badge is enabled for a specified bundle. This API uses an asynchronous callback to return the result. Checks whether the notification badge is enabled for a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -1236,7 +1236,7 @@ Checks whether the notification badge is enabled for a specified bundle. This AP ...@@ -1236,7 +1236,7 @@ Checks whether the notification badge is enabled for a specified bundle. This AP
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------------ | | -------- | --------------------- | ---- | ------------------------ |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -1261,7 +1261,7 @@ Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback); ...@@ -1261,7 +1261,7 @@ Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback);
isBadgeDisplayed(bundle: BundleOption): Promise\<boolean\> isBadgeDisplayed(bundle: BundleOption): Promise\<boolean\>
Checks whether the notification badge is enabled for a specified bundle. This API uses a promise to return the result. Checks whether the notification badge is enabled for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -1273,7 +1273,7 @@ Checks whether the notification badge is enabled for a specified bundle. This AP ...@@ -1273,7 +1273,7 @@ Checks whether the notification badge is enabled for a specified bundle. This AP
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- | | ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.|
**Return value** **Return value**
...@@ -1288,7 +1288,7 @@ var bundle = { ...@@ -1288,7 +1288,7 @@ var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
} }
Notification.isBadgeDisplayed(bundle).then((data) => { Notification.isBadgeDisplayed(bundle).then((data) => {
console.info("isBadgeDisplayed sucess, data: " + JSON.stringify(data)); console.info("isBadgeDisplayed success, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -1298,7 +1298,7 @@ Notification.isBadgeDisplayed(bundle).then((data) => { ...@@ -1298,7 +1298,7 @@ Notification.isBadgeDisplayed(bundle).then((data) => {
setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\<void\>): void setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\<void\>): void
Sets the notification slot for a specified bundle. This API uses an asynchronous callback to return the result. Sets the notification slot for a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -1310,7 +1310,7 @@ Sets the notification slot for a specified bundle. This API uses an asynchronous ...@@ -1310,7 +1310,7 @@ Sets the notification slot for a specified bundle. This API uses an asynchronous
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | -------------------- | | -------- | --------------------- | ---- | -------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| slot | [NotificationSlot](#notificationslot) | Yes | Notification slot. | | slot | [NotificationSlot](#notificationslot) | Yes | Notification slot. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
...@@ -1339,7 +1339,7 @@ Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback); ...@@ -1339,7 +1339,7 @@ Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback);
setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\<void\> setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\<void\>
Sets the notification slot for a specified bundle. This API uses a promise to return the result. Sets the notification slot for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -1351,8 +1351,8 @@ Sets the notification slot for a specified bundle. This API uses a promise to re ...@@ -1351,8 +1351,8 @@ Sets the notification slot for a specified bundle. This API uses a promise to re
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- | | ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.|
| slot | [NotificationSlot](#notificationslot) | Yes | Whether to enable notification. | | slot | [NotificationSlot](#notificationslot) | Yes | Notification slot.|
**Example** **Example**
...@@ -1364,7 +1364,7 @@ var notificationSlot = { ...@@ -1364,7 +1364,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("setSlotByBundle sucess"); console.info("setSlotByBundle success");
}); });
``` ```
...@@ -1374,7 +1374,7 @@ Notification.setSlotByBundle(bundle, notificationSlot).then(() => { ...@@ -1374,7 +1374,7 @@ Notification.setSlotByBundle(bundle, notificationSlot).then(() => {
getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback<Array\<NotificationSlot\>>): void getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback<Array\<NotificationSlot\>>): void
Obtains the notification slots of a specified bundle. This API uses an asynchronous callback to return the result. Obtains the notification slots of a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -1386,7 +1386,7 @@ Obtains the notification slots of a specified bundle. This API uses an asynchron ...@@ -1386,7 +1386,7 @@ Obtains the notification slots of a specified bundle. This API uses an asynchron
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | -------------------- | | -------- | ---------------------------------------- | ---- | -------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| callback | AsyncCallback<Array\<[NotificationSlot](#notificationslot)\>> | Yes | Callback used to return the result.| | callback | AsyncCallback<Array\<[NotificationSlot](#notificationslot)\>> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -1411,7 +1411,7 @@ Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback); ...@@ -1411,7 +1411,7 @@ Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback);
getSlotsByBundle(bundle: BundleOption): Promise<Array\<NotificationSlot\>> getSlotsByBundle(bundle: BundleOption): Promise<Array\<NotificationSlot\>>
Obtains the notification slots of a specified bundle. This API uses a promise to return the result. Obtains the notification slots of a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -1423,7 +1423,7 @@ Obtains the notification slots of a specified bundle. This API uses a promise to ...@@ -1423,7 +1423,7 @@ Obtains the notification slots of a specified bundle. This API uses a promise to
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- | | ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.|
**Return value** **Return value**
...@@ -1438,7 +1438,7 @@ var bundle = { ...@@ -1438,7 +1438,7 @@ var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
} }
Notification.getSlotsByBundle(bundle).then((data) => { Notification.getSlotsByBundle(bundle).then((data) => {
console.info("getSlotsByBundle sucess, data: " + JSON.stringify(data)); console.info("getSlotsByBundle success, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -1448,7 +1448,7 @@ Notification.getSlotsByBundle(bundle).then((data) => { ...@@ -1448,7 +1448,7 @@ Notification.getSlotsByBundle(bundle).then((data) => {
getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<number\>): void getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<number\>): void
Obtains the number of notification slots of a specified bundle. This API uses an asynchronous callback to return the result. Obtains the number of notification slots of a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -1460,7 +1460,7 @@ Obtains the number of notification slots of a specified bundle. This API uses an ...@@ -1460,7 +1460,7 @@ Obtains the number of notification slots of a specified bundle. This API uses an
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------- | | -------- | ------------------------- | ---- | ---------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| callback | AsyncCallback\<number\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<number\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -1485,7 +1485,7 @@ Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback); ...@@ -1485,7 +1485,7 @@ Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback);
getSlotNumByBundle(bundle: BundleOption): Promise\<number\> getSlotNumByBundle(bundle: BundleOption): Promise\<number\>
Obtains the number of notification slots of a specified bundle. This API uses a promise to return the result. Obtains the number of notification slots of a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -1497,7 +1497,7 @@ Obtains the number of notification slots of a specified bundle. This API uses a ...@@ -1497,7 +1497,7 @@ Obtains the number of notification slots of a specified bundle. This API uses a
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- | | ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.|
**Return value** **Return value**
...@@ -1512,7 +1512,7 @@ var bundle = { ...@@ -1512,7 +1512,7 @@ var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
} }
Notification.getSlotNumByBundle(bundle).then((data) => { Notification.getSlotNumByBundle(bundle).then((data) => {
console.info("getSlotNumByBundle sucess, data: " + JSON.stringify(data)); console.info("getSlotNumByBundle success, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -1534,7 +1534,7 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal ...@@ -1534,7 +1534,7 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------------- | ----------------------------------| ---- | -------------------- | | --------------- | ----------------------------------| ---- | -------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | | notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. |
| reason | [RemoveReason](#removereason9) | Yes | Indicates the reason for deleting a notification. | | 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.|
...@@ -1578,7 +1578,7 @@ Removes a notification for a specified bundle. This API uses a promise to return ...@@ -1578,7 +1578,7 @@ Removes a notification for a specified bundle. This API uses a promise to return
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------------- | --------------- | ---- | ---------- | | --------------- | --------------- | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.|
| notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | | notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. |
| reason | [RemoveReason](#removereason9) | Yes | Reason for deleting the notification. | | reason | [RemoveReason](#removereason9) | Yes | Reason for deleting the notification. |
...@@ -1594,7 +1594,7 @@ var notificationKey = { ...@@ -1594,7 +1594,7 @@ var notificationKey = {
} }
var reason = Notification.RemoveReason.CLICK_REASON_REMOVE; var reason = Notification.RemoveReason.CLICK_REASON_REMOVE;
Notification.remove(bundle, notificationKey, reason).then(() => { Notification.remove(bundle, notificationKey, reason).then(() => {
console.info("remove sucess"); console.info("remove success");
}); });
``` ```
...@@ -1616,7 +1616,7 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal ...@@ -1616,7 +1616,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. It is the **hashCode** in the [NotificationRequest](#notificationrequest) object of [SubscribeCallbackData](#subscribecallbackdata) of the [onConsume](#onconsume) callback.|
| reason | [RemoveReason](#removereason9) | Yes | Indicates the reason for deleting a notification. | | 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.|
...@@ -1663,7 +1663,7 @@ Removes a notification for a specified bundle. This API uses a promise to return ...@@ -1663,7 +1663,7 @@ Removes a notification for a specified bundle. This API uses a promise to return
var hashCode = 'hashCode' var hashCode = 'hashCode'
var reason = Notification.RemoveReason.CLICK_REASON_REMOVE; var reason = Notification.RemoveReason.CLICK_REASON_REMOVE;
Notification.remove(hashCode, reason).then(() => { Notification.remove(hashCode, reason).then(() => {
console.info("remove sucess"); console.info("remove success");
}); });
``` ```
...@@ -1673,7 +1673,7 @@ Notification.remove(hashCode, reason).then(() => { ...@@ -1673,7 +1673,7 @@ Notification.remove(hashCode, reason).then(() => {
removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>): void removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>): void
Removes all notifications for a specified bundle. This API uses an asynchronous callback to return the result. Removes all notifications for a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -1685,7 +1685,7 @@ Removes all notifications for a specified bundle. This API uses an asynchronous ...@@ -1685,7 +1685,7 @@ Removes all notifications for a specified bundle. This API uses an asynchronous
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ---------------------------- | | -------- | --------------------- | ---- | ---------------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -1744,7 +1744,7 @@ Notification.removeAll(removeAllCallback); ...@@ -1744,7 +1744,7 @@ Notification.removeAll(removeAllCallback);
removeAll(bundle?: BundleOption): Promise\<void\> removeAll(bundle?: BundleOption): Promise\<void\>
Removes all notifications for a specified user. This API uses a promise to return the result. Removes all notifications for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -1756,13 +1756,14 @@ Removes all notifications for a specified user. This API uses a promise to retur ...@@ -1756,13 +1756,14 @@ Removes all notifications for a specified user. This API uses a promise to retur
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- | | ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | No | Bundle information.| | bundle | [BundleOption](#bundleoption) | No | Bundle information of the application.|
**Example** **Example**
```js ```js
// If no application is specified, notifications of all applications are deleted.
Notification.removeAll().then(() => { Notification.removeAll().then(() => {
console.info("removeAll sucess"); console.info("removeAll success");
}); });
``` ```
...@@ -1782,7 +1783,7 @@ Removes all notifications for a specified user. This API uses an asynchronous ca ...@@ -1782,7 +1783,7 @@ Removes all notifications for a specified user. This API uses an asynchronous ca
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- | | ------ | ------------ | ---- | ---------- |
| userId | number | Yes | ID of the user who receives the notification.| | userId | number | Yes | User ID.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -1797,7 +1798,6 @@ function removeAllCallback(err) { ...@@ -1797,7 +1798,6 @@ function removeAllCallback(err) {
} }
var userId = 1 var userId = 1
Notification.removeAll(userId, removeAllCallback); Notification.removeAll(userId, removeAllCallback);
``` ```
...@@ -1817,22 +1817,15 @@ Removes all notifications for a specified user. This API uses a promise to retur ...@@ -1817,22 +1817,15 @@ Removes all notifications for a specified user. This API uses a promise to retur
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- | | ------ | ------------ | ---- | ---------- |
| userId | number | Yes | ID of the user who receives the notification.| | userId | number | Yes | User ID.|
**Example** **Example**
```js ```js
function removeAllCallback(err) {
if (err.code) {
console.info("removeAll failed " + JSON.stringify(err));
} else {
console.info("removeAll success");
}
}
var userId = 1 var userId = 1
Notification.removeAll(userId).then(() => {
Notification.removeAll(userId, removeAllCallback); console.info("removeAll success");
});
``` ```
...@@ -1892,7 +1885,7 @@ Obtains all active notifications. This API uses a promise to return the result. ...@@ -1892,7 +1885,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("getAllActiveNotifications sucess, data: " + JSON.stringify(data)); console.info("getAllActiveNotifications success, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -1902,7 +1895,7 @@ Notification.getAllActiveNotifications().then((data) => { ...@@ -1902,7 +1895,7 @@ Notification.getAllActiveNotifications().then((data) => {
getActiveNotificationCount(callback: AsyncCallback\<number\>): void getActiveNotificationCount(callback: AsyncCallback\<number\>): void
Obtains the number of active notifications. This API uses an asynchronous callback to return the result. Obtains the number of active notifications of this application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -1932,21 +1925,21 @@ Notification.getActiveNotificationCount(getActiveNotificationCountCallback); ...@@ -1932,21 +1925,21 @@ Notification.getActiveNotificationCount(getActiveNotificationCountCallback);
getActiveNotificationCount(): Promise\<number\> getActiveNotificationCount(): Promise\<number\>
Obtains the number of active notifications. This API uses a promise to return the result. Obtains the number of active notifications of this application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ----------------- | ------------------------------------------- |
| Promise\<number\> | Promise used to return the result.| | Promise\<number\> | Promise used to return the result.|
**Example** **Example**
```js ```js
Notification.getActiveNotificationCount().then((data) => { Notification.getActiveNotificationCount().then((data) => {
console.info("getActiveNotificationCount sucess, data: " + JSON.stringify(data)); console.info("getActiveNotificationCount success, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -1992,15 +1985,15 @@ Obtains active notifications of this application. This API uses a promise to ret ...@@ -1992,15 +1985,15 @@ Obtains active notifications of this application. This API uses a promise to ret
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ------------------------------------------------------------ | --------------------------------------- |
| Promise\<Array\<[NotificationRequest](#notificationrequest)\>\> | Promise used to return the result.| | Promise\<Array\<[NotificationRequest](#notificationrequest)\>\> | Promise used to return the result.|
**Example** **Example**
```js ```js
Notification.getActiveNotifications().then((data) => { Notification.getActiveNotifications().then((data) => {
console.info("removeGroupByBundle sucess, data: " + JSON.stringify(data)); console.info("removeGroupByBundle success, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -2010,7 +2003,7 @@ Notification.getActiveNotifications().then((data) => { ...@@ -2010,7 +2003,7 @@ Notification.getActiveNotifications().then((data) => {
cancelGroup(groupName: string, callback: AsyncCallback\<void\>): void cancelGroup(groupName: string, callback: AsyncCallback\<void\>): void
Cancels a notification group of this application. This API uses an asynchronous callback to return the result. Cancels notifications under a notification group of this application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -2018,7 +2011,7 @@ Cancels a notification group of this application. This API uses an asynchronous ...@@ -2018,7 +2011,7 @@ Cancels a notification group of this application. This API uses an asynchronous
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | --------------------- | ---- | ---------------------------- | | --------- | --------------------- | ---- | ---------------------------- |
| groupName | string | Yes | Name of the notification group. | | groupName | string | Yes | Name of the notification group, which is specified through [NotificationRequest](#notificationrequest) when the notification is published.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -2043,7 +2036,7 @@ Notification.cancelGroup(groupName, cancelGroupCallback); ...@@ -2043,7 +2036,7 @@ Notification.cancelGroup(groupName, cancelGroupCallback);
cancelGroup(groupName: string): Promise\<void\> cancelGroup(groupName: string): Promise\<void\>
Cancels a notification group of this application. This API uses a promise to return the result. Cancels notifications under a notification group of this application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -2058,7 +2051,7 @@ Cancels a notification group of this application. This API uses a promise to ret ...@@ -2058,7 +2051,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("cancelGroup sucess"); console.info("cancelGroup success");
}); });
``` ```
...@@ -2068,7 +2061,7 @@ Notification.cancelGroup(groupName).then(() => { ...@@ -2068,7 +2061,7 @@ Notification.cancelGroup(groupName).then(() => {
removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\<void\>): void removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\<void\>): void
Removes a notification group for a specified bundle. This API uses an asynchronous callback to return the result. Removes notifications under a notification group of a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -2080,7 +2073,7 @@ Removes a notification group for a specified bundle. This API uses an asynchrono ...@@ -2080,7 +2073,7 @@ Removes a notification group for a specified bundle. This API uses an asynchrono
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | --------------------- | ---- | ---------------------------- | | --------- | --------------------- | ---- | ---------------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| groupName | string | Yes | Name of the notification group. | | groupName | string | Yes | Name of the notification group. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
...@@ -2107,7 +2100,7 @@ Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCal ...@@ -2107,7 +2100,7 @@ Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCal
removeGroupByBundle(bundle: BundleOption, groupName: string): Promise\<void\> removeGroupByBundle(bundle: BundleOption, groupName: string): Promise\<void\>
Removes a notification group for a specified bundle. This API uses a promise to return the result. Removes notifications under a notification group of a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -2119,7 +2112,7 @@ Removes a notification group for a specified bundle. This API uses a promise to ...@@ -2119,7 +2112,7 @@ Removes a notification group for a specified bundle. This API uses a promise to
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ------------ | ---- | -------------- | | --------- | ------------ | ---- | -------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| groupName | string | Yes | Name of the notification group.| | groupName | string | Yes | Name of the notification group.|
**Example** **Example**
...@@ -2128,7 +2121,7 @@ Removes a notification group for a specified bundle. This API uses a promise to ...@@ -2128,7 +2121,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("removeGroupByBundle sucess"); console.info("removeGroupByBundle success");
}); });
``` ```
...@@ -2202,7 +2195,7 @@ var doNotDisturbDate = { ...@@ -2202,7 +2195,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("setDoNotDisturbDate sucess"); console.info("setDoNotDisturbDate success");
}); });
``` ```
...@@ -2224,7 +2217,7 @@ Sets the DND time for a specified user. This API uses an asynchronous callback t ...@@ -2224,7 +2217,7 @@ Sets the DND time for a specified user. This API uses an asynchronous callback t
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ---------------------- | | -------- | --------------------- | ---- | ---------------------- |
| date | [DoNotDisturbDate](#donotdisturbdate8) | Yes | DND time to set. | | date | [DoNotDisturbDate](#donotdisturbdate8) | Yes | DND time to set. |
| userId | number | Yes | User ID.| | userId | number | Yes | ID of the user for whom you want to set the DND time.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -2245,7 +2238,6 @@ var doNotDisturbDate = { ...@@ -2245,7 +2238,6 @@ var doNotDisturbDate = {
} }
var userId = 1 var userId = 1
Notification.setDoNotDisturbDate(doNotDisturbDate, userId, setDoNotDisturbDateCallback); Notification.setDoNotDisturbDate(doNotDisturbDate, userId, setDoNotDisturbDateCallback);
``` ```
...@@ -2268,7 +2260,7 @@ Sets the DND time for a specified user. This API uses a promise to return the re ...@@ -2268,7 +2260,7 @@ Sets the DND time for a specified user. This API uses a promise to return the re
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------ | ---------------- | ---- | -------------- | | ------ | ---------------- | ---- | -------------- |
| date | [DoNotDisturbDate](#donotdisturbdate8) | Yes | DND time to set.| | date | [DoNotDisturbDate](#donotdisturbdate8) | Yes | DND time to set.|
| userId | number | Yes | User ID.| | userId | number | Yes | ID of the user for whom you want to set the DND time.|
**Example** **Example**
...@@ -2282,7 +2274,7 @@ var doNotDisturbDate = { ...@@ -2282,7 +2274,7 @@ var doNotDisturbDate = {
var userId = 1 var userId = 1
Notification.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => { Notification.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => {
console.info("setDoNotDisturbDate sucess"); console.info("setDoNotDisturbDate success");
}); });
``` ```
...@@ -2308,7 +2300,7 @@ Obtains the DND time. This API uses an asynchronous callback to return the resul ...@@ -2308,7 +2300,7 @@ Obtains the DND time. This API uses an asynchronous callback to return the resul
**Example** **Example**
```js ```js
function getDoNotDisturbDateCallback(err,data) { function getDoNotDisturbDateCallback(err, data) {
if (err.code) { if (err.code) {
console.info("getDoNotDisturbDate failed " + JSON.stringify(err)); console.info("getDoNotDisturbDate failed " + JSON.stringify(err));
} else { } else {
...@@ -2335,15 +2327,15 @@ Obtains the DND time. This API uses a promise to return the result. ...@@ -2335,15 +2327,15 @@ Obtains the DND time. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ------------------------------------------------- | ----------------------------------------- |
| Promise\<[DoNotDisturbDate](#donotdisturbdate8)\> | Promise used to return the result.| | Promise\<[DoNotDisturbDate](#donotdisturbdate8)\> | Promise used to return the result.|
**Example** **Example**
```js ```js
Notification.getDoNotDisturbDate().then((data) => { Notification.getDoNotDisturbDate().then((data) => {
console.info("getDoNotDisturbDate sucess, data: " + JSON.stringify(data)); console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -2405,8 +2397,8 @@ Obtains the DND time of a specified user. This API uses a promise to return the ...@@ -2405,8 +2397,8 @@ Obtains the DND time of a specified user. This API uses a promise to return the
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ------------------------------------------------- | ----------------------------------------- |
| Promise\<[DoNotDisturbDate](#donotdisturbdate8)\> | Promise used to return the result.| | Promise\<[DoNotDisturbDate](#donotdisturbdate8)\> | Promise used to return the result.|
**Example** **Example**
...@@ -2415,7 +2407,7 @@ Obtains the DND time of a specified user. This API uses a promise to return the ...@@ -2415,7 +2407,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("getDoNotDisturbDate sucess, data: " + JSON.stringify(data)); console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -2424,7 +2416,7 @@ Notification.getDoNotDisturbDate(userId).then((data) => { ...@@ -2424,7 +2416,7 @@ Notification.getDoNotDisturbDate(userId).then((data) => {
supportDoNotDisturbMode(callback: AsyncCallback\<boolean\>): void supportDoNotDisturbMode(callback: AsyncCallback\<boolean\>): void
Checks whether the DND mode is supported. This API uses an asynchronous callback to return the result. Checks whether DND mode is supported. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -2458,7 +2450,7 @@ Notification.supportDoNotDisturbMode(supportDoNotDisturbModeCallback); ...@@ -2458,7 +2450,7 @@ Notification.supportDoNotDisturbMode(supportDoNotDisturbModeCallback);
supportDoNotDisturbMode(): Promise\<boolean\> supportDoNotDisturbMode(): Promise\<boolean\>
Checks whether the DND mode is supported. This API uses a promise to return the result. Checks whether DND mode is supported. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -2476,7 +2468,7 @@ Checks whether the DND mode is supported. This API uses a promise to return the ...@@ -2476,7 +2468,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("supportDoNotDisturbMode sucess, data: " + JSON.stringify(data)); console.info("supportDoNotDisturbMode success, data: " + JSON.stringify(data));
}); });
``` ```
...@@ -2567,7 +2559,7 @@ function requestEnableNotificationCallback(err) { ...@@ -2567,7 +2559,7 @@ function requestEnableNotificationCallback(err) {
if (err.code) { if (err.code) {
console.info("requestEnableNotification failed " + JSON.stringify(err)); console.info("requestEnableNotification failed " + JSON.stringify(err));
} else { } else {
console.info("requestEnableNotification success");
} }
}; };
...@@ -2587,10 +2579,9 @@ Requests notification to be enabled for this application. This API uses a promis ...@@ -2587,10 +2579,9 @@ Requests notification to be enabled for this application. This API uses a promis
**Example** **Example**
```javascript ```javascript
Notification.requestEnableNotification() Notification.requestEnableNotification().then(() => {
.then(() => { console.info("requestEnableNotification success");
console.info("requestEnableNotification sucess"); });
});
``` ```
...@@ -2610,7 +2601,7 @@ Sets whether this device supports distributed notifications. This API uses an as ...@@ -2610,7 +2601,7 @@ Sets whether this device supports distributed notifications. This API uses an as
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- | | -------- | ------------------------ | ---- | -------------------------- |
| enable | boolean | Yes | Whether the device supports distributed notifications.<br>**true**: The device supports distributed notifications.<br>**false**: The device does not support distributed notifications.| | enable | boolean | Yes | Whether the device supports distributed notifications.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -2647,17 +2638,15 @@ Sets whether this device supports distributed notifications. This API uses a pro ...@@ -2647,17 +2638,15 @@ Sets whether this device supports distributed notifications. This API uses a pro
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- | | -------- | ------------------------ | ---- | -------------------------- |
| enable | boolean | Yes | Whether the device supports distributed notifications.<br>**true**: The device supports distributed notifications.<br>**false**: The device does not support distributed notifications.| | enable | boolean | Yes | Whether the device supports distributed notifications.|
**Example** **Example**
```javascript ```javascript
var enable = true var enable = true
Notification.enableDistributed(enable).then(() => {
Notification.enableDistributed(enable) console.info("enableDistributed success");
.then(() => { });
console.info("enableDistributed sucess");
});
``` ```
...@@ -2665,7 +2654,7 @@ Notification.enableDistributed(enable) ...@@ -2665,7 +2654,7 @@ Notification.enableDistributed(enable)
isDistributedEnabled(callback: AsyncCallback\<boolean>): void isDistributedEnabled(callback: AsyncCallback\<boolean>): void
Obtains whether this device supports distributed notifications. This API uses an asynchronous callback to return the result. Checks whether this device supports distributed notifications. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -2695,23 +2684,22 @@ Notification.isDistributedEnabled(isDistributedEnabledCallback); ...@@ -2695,23 +2684,22 @@ Notification.isDistributedEnabled(isDistributedEnabledCallback);
isDistributedEnabled(): Promise\<boolean> isDistributedEnabled(): Promise\<boolean>
Obtains whether this device supports distributed notifications. This API uses a promise to return the result. Checks whether this device supports distributed notifications. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------ | --------------- | | ------------------ | --------------------------------------------- |
| Promise\<boolean\> | Promise used to return the result.<br>**true**: The device supports distributed notifications.<br>**false**: The device does not support distributed notifications.| | Promise\<boolean\> | Promise used to return the result.|
**Example** **Example**
```javascript ```javascript
Notification.isDistributedEnabled() Notification.isDistributedEnabled().then((data) => {
.then((data) => { console.info("isDistributedEnabled success, data: " + JSON.stringify(data));
console.info("isDistributedEnabled sucess, data: " + JSON.stringify(data)); });
});
``` ```
...@@ -2719,7 +2707,7 @@ Notification.isDistributedEnabled() ...@@ -2719,7 +2707,7 @@ Notification.isDistributedEnabled()
enableDistributedByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void>): void enableDistributedByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void>): void
Sets whether an application supports distributed notifications based on the bundle. This API uses an asynchronous callback to return the result. Sets whether a specified application supports distributed notifications. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -2731,7 +2719,7 @@ Sets whether an application supports distributed notifications based on the bund ...@@ -2731,7 +2719,7 @@ Sets whether an application supports distributed notifications based on the bund
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- | | -------- | ------------------------ | ---- | -------------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Application bundle. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| enable | boolean | Yes | Whether the device supports distributed notifications. | | enable | boolean | Yes | Whether the device supports distributed notifications. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
...@@ -2761,7 +2749,7 @@ Notification.enableDistributedByBundle(bundle, enable, enableDistributedByBundle ...@@ -2761,7 +2749,7 @@ Notification.enableDistributedByBundle(bundle, enable, enableDistributedByBundle
enableDistributedByBundle(bundle: BundleOption, enable: boolean): Promise\<void> enableDistributedByBundle(bundle: BundleOption, enable: boolean): Promise\<void>
Sets whether an application supports distributed notifications based on the bundle. This API uses a promise to return the result. Sets whether a specified application supports distributed notifications. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -2784,11 +2772,9 @@ var bundle = { ...@@ -2784,11 +2772,9 @@ var bundle = {
} }
var enable = true var enable = true
Notification.enableDistributedByBundle(bundle, enable).then(() => {
Notification.enableDistributedByBundle(bundle, enable) console.info("enableDistributedByBundle success");
.then(() => { });
console.info("enableDistributedByBundle sucess");
});
``` ```
## Notification.isDistributedEnabledByBundle<sup>8+</sup> ## Notification.isDistributedEnabledByBundle<sup>8+</sup>
...@@ -2834,7 +2820,7 @@ Notification.isDistributedEnabledByBundle(bundle, isDistributedEnabledByBundleCa ...@@ -2834,7 +2820,7 @@ Notification.isDistributedEnabledByBundle(bundle, isDistributedEnabledByBundleCa
isDistributedEnabledByBundle(bundle: BundleOption): Promise\<boolean> isDistributedEnabledByBundle(bundle: BundleOption): Promise\<boolean>
Obtains whether an application supports distributed notifications based on the bundle. This API uses a promise to return the result. Checks whether a specified application supports distributed notifications. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -2850,9 +2836,9 @@ Obtains whether an application supports distributed notifications based on the b ...@@ -2850,9 +2836,9 @@ Obtains whether an application supports distributed notifications based on the b
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------ | --------------- | | ------------------ | ------------------------------------------------- |
| Promise\<boolean\> | Promise used to return the result.<br>**true**: The device supports distributed notifications.<br>**false**: The device does not support distributed notifications.| | Promise\<boolean\> | Promise used to return the result.|
**Example** **Example**
...@@ -2861,10 +2847,9 @@ var bundle = { ...@@ -2861,10 +2847,9 @@ var bundle = {
bundle: "bundleName1", bundle: "bundleName1",
} }
Notification.isDistributedEnabledByBundle(bundle) Notification.isDistributedEnabledByBundle(bundle).then((data) => {
.then((data) => { console.info("isDistributedEnabledByBundle success, data: " + JSON.stringify(data));
console.info("isDistributedEnabledByBundle sucess, data: " + JSON.stringify(data)); });
});
``` ```
...@@ -2923,10 +2908,9 @@ Obtains the notification reminder type. This API uses a promise to return the re ...@@ -2923,10 +2908,9 @@ Obtains the notification reminder type. This API uses a promise to return the re
**Example** **Example**
```javascript ```javascript
Notification.getDeviceRemindType() Notification.getDeviceRemindType().then((data) => {
.then((data) => { console.info("getDeviceRemindType success, data: " + JSON.stringify(data));
console.info("getDeviceRemindType sucess, data: " + JSON.stringify(data)); });
});
``` ```
...@@ -2944,18 +2928,18 @@ Publishes an agent-powered notification. This API uses an asynchronous callback ...@@ -2944,18 +2928,18 @@ Publishes an agent-powered notification. This API uses an asynchronous callback
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------------------- | ------------------------------------------- | ---- | --------------------------------------------- | | -------------------- | ------------------------------------------- | ---- | ---------------------------------------- |
| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| | request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.|
| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | | representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. |
| userId | number | Yes | ID of the user who receives the notification. | | userId | number | Yes | User ID. |
| callback | AsyncCallback | Yes | Callback used to return the result. | | callback | AsyncCallback | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
// Callback for publishAsBundle // publishAsBundle callback
function publishAsBundleCallback(err) { function callback(err) {
if (err.code) { if (err.code) {
console.info("publishAsBundle failed " + JSON.stringify(err)); console.info("publishAsBundle failed " + JSON.stringify(err));
} else { } else {
...@@ -2964,10 +2948,10 @@ function publishAsBundleCallback(err) { ...@@ -2964,10 +2948,10 @@ function publishAsBundleCallback(err) {
} }
// 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"
// ID of the user who receives the notification // User ID
let userId = 100 let userId = 100
// NotificationRequest object // NotificationRequest object
let notificationRequest = { let request = {
id: 1, id: 1,
content: { content: {
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
...@@ -2979,7 +2963,7 @@ let notificationRequest = { ...@@ -2979,7 +2963,7 @@ let notificationRequest = {
} }
} }
Notification.publishAsBundle(notificationRequest, representativeBundle, userId, publishAsBundleCallback); Notification.publishAsBundle(request, representativeBundle, userId, callback);
``` ```
## Notification.publishAsBundle<sup>9+</sup> ## Notification.publishAsBundle<sup>9+</sup>
...@@ -2999,19 +2983,19 @@ Publishes a notification through the reminder agent. This API uses a promise to ...@@ -2999,19 +2983,19 @@ Publishes a notification through the reminder agent. This API uses a promise to
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------------------- | ------------------------------------------- | ---- | --------------------------------------------- | | -------------------- | ------------------------------------------- | ---- | --------------------------------------------- |
| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| | request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.|
| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | | representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. |
| userId | number | Yes | ID of the user who receives the notification. | | userId | number | Yes | User ID. |
**Example** **Example**
```js ```js
// 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"
// ID of the user who receives the notification // User ID
let userId = 100 let userId = 100
// NotificationRequest object // NotificationRequest object
var notificationRequest = { var request = {
id: 1, id: 1,
content: { content: {
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
...@@ -3023,8 +3007,8 @@ var notificationRequest = { ...@@ -3023,8 +3007,8 @@ var notificationRequest = {
} }
} }
Notification.publishAsBundle(notificationRequest, representativeBundle, userId).then(() => { Notification.publishAsBundle(request, representativeBundle, userId).then(() => {
console.info("publishAsBundle sucess"); console.info("publishAsBundle success");
}); });
``` ```
...@@ -3048,13 +3032,13 @@ Cancels a notification published by the reminder agent. This API uses an asynchr ...@@ -3048,13 +3032,13 @@ Cancels a notification published by the reminder agent. This API uses an asynchr
| -------------------- | ------------- | ---- | ------------------------ | | -------------------- | ------------- | ---- | ------------------------ |
| id | number | Yes | Notification ID. | | id | number | Yes | Notification ID. |
| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | | representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. |
| userId | number | Yes | ID of the user who receives the notification. | | userId | number | Yes | User ID. |
| callback | AsyncCallback | Yes | Callback used to return the result.| | callback | AsyncCallback | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
//cancelAsBundle // cancelAsBundle
function cancelAsBundleCallback(err) { function cancelAsBundleCallback(err) {
if (err.code) { if (err.code) {
console.info("cancelAsBundle failed " + JSON.stringify(err)); console.info("cancelAsBundle failed " + JSON.stringify(err));
...@@ -3064,7 +3048,7 @@ function cancelAsBundleCallback(err) { ...@@ -3064,7 +3048,7 @@ function cancelAsBundleCallback(err) {
} }
// 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"
// ID of the user who receives the notification // User ID
let userId = 100 let userId = 100
Notification.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallback); Notification.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallback);
...@@ -3074,7 +3058,7 @@ Notification.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallb ...@@ -3074,7 +3058,7 @@ Notification.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallb
cancelAsBundle(id: number, representativeBundle: string, userId: number): Promise\<void\> cancelAsBundle(id: number, representativeBundle: string, userId: number): Promise\<void\>
Publishes a notification through the reminder agent. This API uses a promise to return the result. Cancels a notification published by the reminder agent. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -3090,14 +3074,14 @@ Publishes a notification through the reminder agent. This API uses a promise to ...@@ -3090,14 +3074,14 @@ Publishes a notification through the reminder agent. This API uses a promise to
| -------------------- | ------ | ---- | ------------------ | | -------------------- | ------ | ---- | ------------------ |
| id | number | Yes | Notification ID. | | id | number | Yes | Notification ID. |
| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent.| | representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent.|
| userId | number | Yes | ID of the user who receives the notification.| | userId | number | Yes | User ID.|
**Example** **Example**
```js ```js
// 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"
// ID of the user who receives the notification // User ID
let userId = 100 let userId = 100
Notification.cancelAsBundle(0, representativeBundle, userId).then(() => { Notification.cancelAsBundle(0, representativeBundle, userId).then(() => {
...@@ -3109,7 +3093,7 @@ Notification.cancelAsBundle(0, representativeBundle, userId).then(() => { ...@@ -3109,7 +3093,7 @@ Notification.cancelAsBundle(0, representativeBundle, userId).then(() => {
enableNotificationSlot(bundle: BundleOption, type: SlotType, enable: boolean, callback: AsyncCallback\<void>): void enableNotificationSlot(bundle: BundleOption, type: SlotType, enable: boolean, callback: AsyncCallback\<void>): void
Sets the enabled status for a notification slot of a specified type. This API uses an asynchronous callback to return the result. Sets the enabled status of a notification slot type for a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -3121,7 +3105,7 @@ Sets the enabled status for a notification slot of a specified type. This API us ...@@ -3121,7 +3105,7 @@ Sets the enabled status for a notification slot of a specified type. This API us
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------- | ---- | ---------------------- | | -------- | ----------------------------- | ---- | ---------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| type | [SlotType](#slottype) | Yes | Notification slot type. | | type | [SlotType](#slottype) | Yes | Notification slot type. |
| enable | boolean | Yes | Whether to enable notification. | | enable | boolean | Yes | Whether to enable notification. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
...@@ -3129,7 +3113,7 @@ Sets the enabled status for a notification slot of a specified type. This API us ...@@ -3129,7 +3113,7 @@ Sets the enabled status for a notification slot of a specified type. This API us
**Example** **Example**
```js ```js
//enableNotificationSlot // enableNotificationSlot
function enableSlotCallback(err) { function enableSlotCallback(err) {
if (err.code) { if (err.code) {
console.info("enableNotificationSlot failed " + JSON.stringify(err)); console.info("enableNotificationSlot failed " + JSON.stringify(err));
...@@ -3149,7 +3133,7 @@ Notification.enableNotificationSlot( ...@@ -3149,7 +3133,7 @@ Notification.enableNotificationSlot(
enableNotificationSlot(bundle: BundleOption, type: SlotType, enable: boolean): Promise\<void> enableNotificationSlot(bundle: BundleOption, type: SlotType, enable: boolean): Promise\<void>
Sets the enabled status for a notification slot of a specified type. This API uses a promise to return the result. Sets the enabled status of a notification slot type for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -3161,27 +3145,25 @@ Sets the enabled status for a notification slot of a specified type. This API us ...@@ -3161,27 +3145,25 @@ Sets the enabled status for a notification slot of a specified type. This API us
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | -------------- | | ------ | ----------------------------- | ---- | -------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| type | [SlotType](#slottype) | Yes | Notification slot type.| | type | [SlotType](#slottype) | Yes | Notification slot type.|
| enable | boolean | Yes | Whether to enable notification. | | enable | boolean | Yes | Whether to enable notification. |
**Example** **Example**
```js ```js
//enableNotificationSlot // enableNotificationSlot
Notification.enableNotificationSlot( Notification.enableNotificationSlot({ bundle: "ohos.samples.notification", },
{ bundle: "ohos.samples.notification", }, Notification.SlotType.SOCIAL_COMMUNICATION,true).then(() => {
Notification.SlotType.SOCIAL_COMMUNICATION, console.info("enableNotificationSlot success");
true).then(() => { });
console.info("enableNotificationSlot sucess");
});
``` ```
## Notification.isNotificationSlotEnabled <sup>9+</sup> ## Notification.isNotificationSlotEnabled <sup>9+</sup>
isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncCallback\<boolean\>): void isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncCallback\<boolean\>): void
Obtains the enabled status of the notification slot of a specified type. This API uses an asynchronous callback to return the result. Checks whether a specified notification slot type is enabled for a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -3193,14 +3175,14 @@ Obtains the enabled status of the notification slot of a specified type. This AP ...@@ -3193,14 +3175,14 @@ Obtains the enabled status of the notification slot of a specified type. This AP
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------- | ---- | ---------------------- | | -------- | ----------------------------- | ---- | ---------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| type | [SlotType](#slottype) | Yes | Notification slot type. | | type | [SlotType](#slottype) | Yes | Notification slot type. |
| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
//isNotificationSlotEnabled // isNotificationSlotEnabled
function getEnableSlotCallback(err, data) { function getEnableSlotCallback(err, data) {
if (err.code) { if (err.code) {
console.info("isNotificationSlotEnabled failed " + JSON.stringify(err)); console.info("isNotificationSlotEnabled failed " + JSON.stringify(err));
...@@ -3219,7 +3201,7 @@ Notification.isNotificationSlotEnabled( ...@@ -3219,7 +3201,7 @@ Notification.isNotificationSlotEnabled(
isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise\<boolean\> isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise\<boolean\>
Obtains the enabled status of the notification slot of a specified type. This API uses a promise to return the result. Checks whether a specified notification slot type is enabled for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -3231,25 +3213,23 @@ Obtains the enabled status of the notification slot of a specified type. This AP ...@@ -3231,25 +3213,23 @@ Obtains the enabled status of the notification slot of a specified type. This AP
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | -------------- | | ------ | ----------------------------- | ---- | -------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | | bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| type | [SlotType](#slottype) | Yes | Notification slot type.| | type | [SlotType](#slottype) | Yes | Notification slot type.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ------------------ | ------------------------------- |
| Promise\<boolean\> | Promise used to return the enabled status of the notification slot of the specified type.| | Promise\<boolean\> | Promise used to return the result.|
**Example** **Example**
```js ```js
//isNotificationSlotEnabled // isNotificationSlotEnabled
Notification.isNotificationSlotEnabled( Notification.isNotificationSlotEnabled({ bundle: "ohos.samples.notification", },
{ bundle: "ohos.samples.notification", }, Notification.SlotType.SOCIAL_COMMUNICATION).then((data) => {
Notification.SlotType.SOCIAL_COMMUNICATION console.info("isNotificationSlotEnabled success, data: " + JSON.stringify(data));
).then((data) => { });
console.info("isNotificationSlotEnabled success, data: " + JSON.stringify(data));
});
``` ```
...@@ -3257,7 +3237,7 @@ Notification.isNotificationSlotEnabled( ...@@ -3257,7 +3237,7 @@ Notification.isNotificationSlotEnabled(
setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean, callback: AsyncCallback\<void\>): void setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean, callback: AsyncCallback\<void\>): void
Sets whether to sync notifications to devices where the application is not installed. This API uses an asynchronous callback to return the result. Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -3270,7 +3250,7 @@ Sets whether to sync notifications to devices where the application is not insta ...@@ -3270,7 +3250,7 @@ Sets whether to sync notifications to devices where the application is not insta
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | -------------- | | ------ | ----------------------------- | ---- | -------------- |
| userId | number | Yes | User ID. | | userId | number | Yes | User ID. |
| enable | boolean | Yes | Whether the feature is enabled.<br>**true**: enabled<br>**false**: disabled | | enable | boolean | Yes | Whether the feature is enabled. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -3279,7 +3259,7 @@ Sets whether to sync notifications to devices where the application is not insta ...@@ -3279,7 +3259,7 @@ Sets whether to sync notifications to devices where the application is not insta
let userId = 100; let userId = 100;
let enable = true; let enable = true;
function setSyncNotificationEnabledWithoutAppCallback(err) { function callback(err) {
if (err.code) { if (err.code) {
console.info("setSyncNotificationEnabledWithoutApp failed " + JSON.stringify(err)); console.info("setSyncNotificationEnabledWithoutApp failed " + JSON.stringify(err));
} else { } else {
...@@ -3287,7 +3267,7 @@ function setSyncNotificationEnabledWithoutAppCallback(err) { ...@@ -3287,7 +3267,7 @@ function setSyncNotificationEnabledWithoutAppCallback(err) {
} }
} }
Notification.setSyncNotificationEnabledWithoutApp(userId, enable, setSyncNotificationEnabledWithoutAppCallback); Notification.setSyncNotificationEnabledWithoutApp(userId, enable, callback);
``` ```
...@@ -3295,7 +3275,7 @@ Notification.setSyncNotificationEnabledWithoutApp(userId, enable, setSyncNotific ...@@ -3295,7 +3275,7 @@ Notification.setSyncNotificationEnabledWithoutApp(userId, enable, setSyncNotific
setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): Promise\<void> setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): Promise\<void>
Sets whether to sync notifications to devices where the application is not installed. This API uses a promise to return the result. Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -3308,7 +3288,7 @@ Sets whether to sync notifications to devices where the application is not insta ...@@ -3308,7 +3288,7 @@ Sets whether to sync notifications to devices where the application is not insta
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | -------------- | | ------ | ----------------------------- | ---- | -------------- |
| userId | number | Yes | User ID. | | userId | number | Yes | User ID. |
| enable | boolean | Yes | Whether the feature is enabled.<br>**true**: enabled<br>**false**: disabled | | enable | boolean | Yes | Whether the feature is enabled. |
**Return value** **Return value**
...@@ -3322,13 +3302,11 @@ Sets whether to sync notifications to devices where the application is not insta ...@@ -3322,13 +3302,11 @@ Sets whether to sync notifications to devices where the application is not insta
let userId = 100; let userId = 100;
let enable = true; let enable = true;
Notification.setSyncNotificationEnabledWithoutApp(userId, enable) Notification.setSyncNotificationEnabledWithoutApp(userId, enable).then(() => {
.then(() => { console.info('setSyncNotificationEnabledWithoutApp success');
console.info('setSyncNotificationEnabledWithoutApp'); }).catch((err) => {
}) console.info('setSyncNotificationEnabledWithoutApp, err:' + JSON.stringify(err));
.catch((err) => { });
console.info('setSyncNotificationEnabledWithoutApp, err:', err);
});
``` ```
...@@ -3336,7 +3314,7 @@ Notification.setSyncNotificationEnabledWithoutApp(userId, enable) ...@@ -3336,7 +3314,7 @@ Notification.setSyncNotificationEnabledWithoutApp(userId, enable)
getSyncNotificationEnabledWithoutApp(userId: number, callback: AsyncCallback\<boolean>): void getSyncNotificationEnabledWithoutApp(userId: number, callback: AsyncCallback\<boolean>): void
Obtains whether notifications are synced to devices where the application is not installed. This API uses an asynchronous callback to return the result. Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -3349,18 +3327,18 @@ Obtains whether notifications are synced to devices where the application is not ...@@ -3349,18 +3327,18 @@ Obtains whether notifications are synced to devices where the application is not
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | -------------- | | ------ | ----------------------------- | ---- | -------------- |
| userId | number | Yes | User ID. | | userId | number | Yes | User ID. |
| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.<br>**true**: Notifications are synced to devices where the application is not installed.<br>**false**: Notifications are not synced to devices where the application is not installed.| | callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
let userId = 100; let userId = 100;
function getSyncNotificationEnabledWithoutAppCallback(data, err) { function getSyncNotificationEnabledWithoutAppCallback(err, data) {
if (err) { if (err) {
console.info('getSyncNotificationEnabledWithoutAppCallback, err' + err); console.info('getSyncNotificationEnabledWithoutAppCallback, err:' + err);
} else { } else {
console.info('getSyncNotificationEnabledWithoutAppCallback, data' + data); console.info('getSyncNotificationEnabledWithoutAppCallback, data:' + data);
} }
} }
...@@ -3372,7 +3350,7 @@ Notification.getSyncNotificationEnabledWithoutApp(userId, getSyncNotificationEna ...@@ -3372,7 +3350,7 @@ Notification.getSyncNotificationEnabledWithoutApp(userId, getSyncNotificationEna
getSyncNotificationEnabledWithoutApp(userId: number): Promise\<boolean> getSyncNotificationEnabledWithoutApp(userId: number): Promise\<boolean>
Obtains whether notifications are synced to devices where the application is not installed. This API uses a promise to return the result. Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -3388,29 +3366,26 @@ Obtains whether notifications are synced to devices where the application is not ...@@ -3388,29 +3366,26 @@ Obtains whether notifications are synced to devices where the application is not
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ------------------ | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.<br>**true**: Notifications are synced to devices where the application is not installed.<br>**false**: Notifications are not synced to devices where the application is not installed.| | Promise\<boolean\> | Promise used to return the result.|
**Example** **Example**
```js ```js
let userId = 100; let userId = 100;
Notification.getSyncNotificationEnabledWithoutApp(userId).then((data) => {
Notification.getSyncNotificationEnabledWithoutApp(userId) console.info('getSyncNotificationEnabledWithoutApp, data:' + data);
.then((data) => { }).catch((err) => {
console.info('getSyncNotificationEnabledWithoutApp, data:', data); console.info('getSyncNotificationEnabledWithoutApp, err:' + err);
}) });
.catch((err) => {
console.info('getSyncNotificationEnabledWithoutApp, err:', err);
});
``` ```
## NotificationSubscriber ## NotificationSubscriber
Provides callbacks for receiving or removing notifications. Provides callbacks for receiving or removing notifications and serves as the input parameter of [subscribe](#notificationsubscribe).
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
...@@ -3428,7 +3403,7 @@ Callback for receiving notifications. ...@@ -3428,7 +3403,7 @@ Callback for receiving notifications.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------------ | ------------------------ | ---- | -------------------------- | | ------------ | ------------------------ | ---- | -------------------------- |
| data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Notification information returned.| | data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Information about the notification received.|
**Example** **Example**
...@@ -3442,7 +3417,6 @@ function subscribeCallback(err) { ...@@ -3442,7 +3417,6 @@ function subscribeCallback(err) {
}; };
function onConsumeCallback(data) { function onConsumeCallback(data) {
console.info('===> onConsume in test');
let req = data.request; let req = data.request;
console.info('===> onConsume callback req.id:' + req.id); console.info('===> onConsume callback req.id:' + req.id);
}; };
...@@ -3458,7 +3432,7 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -3458,7 +3432,7 @@ Notification.subscribe(subscriber, subscribeCallback);
onCancel?:(data: [SubscribeCallbackData](#subscribecallbackdata)) => void onCancel?:(data: [SubscribeCallbackData](#subscribecallbackdata)) => void
Callback for removing notifications. Callback for canceling notifications.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -3468,7 +3442,7 @@ Callback for removing notifications. ...@@ -3468,7 +3442,7 @@ Callback for removing notifications.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------------ | ------------------------ | ---- | -------------------------- | | ------------ | ------------------------ | ---- | -------------------------- |
| data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Notification information returned.| | data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Information about the notification to cancel.|
**Example** **Example**
...@@ -3482,7 +3456,6 @@ function subscribeCallback(err) { ...@@ -3482,7 +3456,6 @@ function subscribeCallback(err) {
}; };
function onCancelCallback(data) { function onCancelCallback(data) {
console.info('===> onCancel in test');
let req = data.request; let req = data.request;
console.info('===> onCancel callback req.id:' + req.id); console.info('===> onCancel callback req.id:' + req.id);
} }
...@@ -3508,7 +3481,7 @@ Callback for notification sorting updates. ...@@ -3508,7 +3481,7 @@ Callback for notification sorting updates.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------------ | ------------------------ | ---- | -------------------------- | | ------------ | ------------------------ | ---- | -------------------------- |
| data | [NotificationSortingMap](#notificationsortingmap) | Yes| Notification information returned.| | data | [NotificationSortingMap](#notificationsortingmap) | Yes| Latest notification sorting list.|
**Example** **Example**
...@@ -3521,8 +3494,8 @@ function subscribeCallback(err) { ...@@ -3521,8 +3494,8 @@ function subscribeCallback(err) {
} }
}; };
function onUpdateCallback() { function onUpdateCallback(map) {
console.info('===> onUpdate in test'); console.info('===> onUpdateCallback map:' + JSON.stringify(map));
} }
var subscriber = { var subscriber = {
...@@ -3584,16 +3557,30 @@ function subscribeCallback(err) { ...@@ -3584,16 +3557,30 @@ function subscribeCallback(err) {
console.info("subscribeCallback"); console.info("subscribeCallback");
} }
}; };
function unsubscribeCallback(err) {
if (err.code) {
console.info("unsubscribe failed " + JSON.stringify(err));
} else {
console.info("unsubscribeCallback");
}
};
function onConnectCallback() {
console.info('===> onConnect in test');
}
function onDisconnectCallback() { function onDisconnectCallback() {
console.info('===> onDisconnect in test'); console.info('===> onDisconnect in test');
} }
var subscriber = { var subscriber = {
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback onDisconnect: onDisconnectCallback
}; };
// The onConnect callback is invoked when subscription to the notification is complete.
Notification.subscribe(subscriber, subscribeCallback); Notification.subscribe(subscriber, subscribeCallback);
// The onDisconnect callback is invoked when unsubscription to the notification is complete.
Notification.unsubscribe(subscriber, unsubscribeCallback);
``` ```
### onDestroy ### onDestroy
...@@ -3654,15 +3641,24 @@ function subscribeCallback(err) { ...@@ -3654,15 +3641,24 @@ function subscribeCallback(err) {
} }
}; };
function onDoNotDisturbDateChangeCallback() { function onDoNotDisturbDateChangeCallback(mode) {
console.info('===> onDoNotDisturbDateChange in test'); console.info('===> onDoNotDisturbDateChange:' + mode);
} }
var subscriber = { var subscriber = {
onDoNotDisturbDateChange: onDoNotDisturbDateChangeCallback onDoNotDisturbDateChange: onDoNotDisturbDateChangeCallback
}; };
Notification.subscribe(subscriber, subscribeCallback); Notification.subscribe(subscriber, subscribeCallback);
var doNotDisturbDate = {
type: Notification.DoNotDisturbType.TYPE_ONCE,
begin: new Date(),
end: new Date(2021, 11, 15, 18, 0)
}
// Set the onDoNotDisturbDateChange callback for DND time setting updates.
Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => {
console.info("setDoNotDisturbDate sucess");
});
``` ```
...@@ -3670,7 +3666,7 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -3670,7 +3666,7 @@ Notification.subscribe(subscriber, subscribeCallback);
onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](#enablednotificationcallbackdata8)) => void onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](#enablednotificationcallbackdata8)) => void
Listens for the notification enable status changes. This API uses an asynchronous callback to return the result. Listens for the notification enabled status changes. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -3694,16 +3690,23 @@ function subscribeCallback(err) { ...@@ -3694,16 +3690,23 @@ function subscribeCallback(err) {
}; };
function onEnabledNotificationChangedCallback(callbackData) { function onEnabledNotificationChangedCallback(callbackData) {
console.info("bundle: ", callbackData.bundle); console.info("bundle: " + callbackData.bundle);
console.info("uid: ", callbackData.uid); console.info("uid: " + callbackData.uid);
console.info("enable: ", callbackData.enable); console.info("enable: " + callbackData.enable);
}; };
var subscriber = { var subscriber = {
onEnabledNotificationChanged: onEnabledNotificationChangedCallback onEnabledNotificationChanged: onEnabledNotificationChangedCallback
}; };
Notification.subscribe(subscriber, subscribeCallback); Notification.subscribe(subscriber, subscribeCallback);
var bundle = {
bundle: "bundleName1",
}
// Set the onEnabledNotificationChanged callback that is triggered when the notification enabled status changes.
Notification.enableNotification(bundle, false).then(() => {
console.info("enableNotification sucess");
});
``` ```
## SubscribeCallbackData ## SubscribeCallbackData
...@@ -3740,13 +3743,11 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -3740,13 +3743,11 @@ Notification.subscribe(subscriber, subscribeCallback);
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ----- ------------------------------------- || ---- | --- | ------------------------ | | ----- | -------------------------------------- | ---- | ---- | ---------------------- |
| type | [DoNotDisturbType](#donotdisturbtype8) | Yes | No | DND time type.| | type | [DoNotDisturbType](#donotdisturbtype8) | Yes | Yes | DND time type.|
| begin | Date | Yes | No | DND start time.| | begin | Date | Yes | Yes | DND start time.|
| end | Date | Yes | No | DND end time.| | end | Date | Yes | Yes | DND end time.|
## DoNotDisturbType<sup>8+</sup> ## DoNotDisturbType<sup>8+</sup>
...@@ -3793,7 +3794,7 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -3793,7 +3794,7 @@ Notification.subscribe(subscriber, subscribeCallback);
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------ | ------ |---- | --- | ------ | | ------ | ------ |---- | --- | ------ |
| bundle | string | Yes | Yes | Bundle name. | | bundle | string | Yes | Yes | Bundle information of the application.|
| uid | number | Yes | Yes | User ID.| | uid | number | Yes | Yes | User ID.|
...@@ -3823,14 +3824,14 @@ Notification.subscribe(subscriber, subscribeCallback); ...@@ -3823,14 +3824,14 @@ Notification.subscribe(subscriber, subscribeCallback);
## NotificationActionButton ## NotificationActionButton
Enumerates the buttons in the notification. Describes the button displayed in the notification.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| --------- | ----------------------------------------------- | --- | ---- | ------------------------- | | --------- | ----------------------------------------------- | --- | ---- | ------------------------- |
| title | string | Yes | Yes | Button title. | | title | string | Yes | Yes | Button title. |
| wantAgent | WantAgent | Yes | Yes | **WantAgent** of the button.| | wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** of the button.|
| extras | { [key: string]: any } | Yes | Yes | Extra information of the button. | | extras | { [key: string]: any } | Yes | Yes | Extra information of the button. |
| userInput<sup>8+</sup> | [NotificationUserInput](#notificationuserinput8) | Yes | Yes | User input object. | | userInput<sup>8+</sup> | [NotificationUserInput](#notificationuserinput8) | Yes | Yes | User input object. |
...@@ -3893,7 +3894,7 @@ Describes the picture-attached notification. ...@@ -3893,7 +3894,7 @@ Describes the picture-attached notification.
| additionalText | string | Yes | Yes | Additional information of the notification.| | additionalText | string | Yes | Yes | Additional information of the notification.|
| briefText | string | Yes | Yes | Brief text of the notification.| | briefText | string | Yes | Yes | Brief text of the notification.|
| expandedTitle | string | Yes | Yes | Title of the notification in the expanded state. | | expandedTitle | string | Yes | Yes | Title of the notification in the expanded state. |
| picture | image.PixelMap | Yes | Yes | Picture attached to the notification. | | picture | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Picture attached to the notification. |
## NotificationContent ## NotificationContent
...@@ -3934,8 +3935,8 @@ Enumerates notification flags. ...@@ -3934,8 +3935,8 @@ Enumerates notification flags.
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ---------------- | ---------------------- | ---- | ---- | --------------------------------- | | ---------------- | ---------------------- | ---- | ---- | --------------------------------- |
| soundEnabled | NotificationFlagStatus | Yes | No | Whether to enable the sound alert for the notification. | | soundEnabled | [NotificationFlagStatus](#notificationflagstatus8) | Yes | No | Whether to enable the sound alert for the notification. |
| vibrationEnabled | NotificationFlagStatus | Yes | No | Whether to enable vibration for the notification. | | vibrationEnabled | [NotificationFlagStatus](#notificationflagstatus8) | Yes | No | Whether to enable vibration for the notification. |
## NotificationRequest ## NotificationRequest
...@@ -3954,48 +3955,47 @@ Describes the notification request. ...@@ -3954,48 +3955,47 @@ Describes the notification request.
| deliveryTime | number | Yes | Yes | Time when the notification is sent. | | deliveryTime | number | Yes | Yes | Time when the notification is sent. |
| tapDismissed | boolean | Yes | Yes | Whether the notification is automatically cleared. | | tapDismissed | boolean | Yes | Yes | Whether the notification is automatically cleared. |
| autoDeletedTime | number | Yes | Yes | Time when the notification is automatically cleared. | | autoDeletedTime | number | Yes | Yes | Time when the notification is automatically cleared. |
| wantAgent | WantAgent | Yes | Yes | **WantAgent** instance to which the notification will be redirected after being clicked. | | wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** instance to which the notification will be redirected after being clicked. |
| extraInfo | {[key: string]: any} | Yes | Yes | Extended parameters. | | extraInfo | {[key: string]: any} | Yes | Yes | Extended parameters. |
| color | number | Yes | Yes | Background color of the notification. Not supported currently. | | color | number | Yes | Yes | Background color of the notification. Not supported currently.|
| colorEnabled | boolean | Yes | Yes | Whether the notification background color is enabled. Not supported currently. | | colorEnabled | boolean | Yes | Yes | Whether the notification background color is enabled. Not supported currently.|
| isAlertOnce | boolean | Yes | Yes | Whether the notification triggers an alert only once.| | isAlertOnce | boolean | Yes | Yes | Whether the notification triggers an alert only once.|
| isStopwatch | boolean | Yes | Yes | Whether to display the stopwatch. | | isStopwatch | boolean | Yes | Yes | Whether to display the stopwatch. |
| isCountDown | boolean | Yes | Yes | Whether to display the countdown time. | | isCountDown | boolean | Yes | Yes | Whether to display the countdown time. |
| isFloatingIcon | boolean | Yes | Yes | Whether the notification is displayed as a floating icon. | | isFloatingIcon | boolean | Yes | Yes | Whether the notification is displayed as a floating icon in the status bar. |
| label | string | Yes | Yes | Notification label. | | label | string | Yes | Yes | Notification label. |
| badgeIconStyle | number | Yes | Yes | Notification badge type. | | badgeIconStyle | number | Yes | Yes | Notification badge type. |
| showDeliveryTime | boolean | Yes | Yes | Whether to display the time when the notification is delivered. | | showDeliveryTime | boolean | Yes | Yes | Whether to display the time when the notification is delivered. |
| actionButtons | Array\<[NotificationActionButton](#notificationactionbutton)\> | Yes | Yes | Buttons in the notification. Up to two buttons are allowed. | | actionButtons | Array\<[NotificationActionButton](#notificationactionbutton)\> | Yes | Yes | Buttons in the notification. Up to two buttons are allowed. |
| smallIcon | PixelMap | Yes | Yes | Small notification icon. | | smallIcon | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Small notification icon. This field is optional, and the icon size cannot exceed 30 KB.|
| largeIcon | PixelMap | Yes | Yes | Large notification icon. | | largeIcon | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Large notification icon. This field is optional, and the icon size cannot exceed 30 KB.|
| creatorBundleName | string | Yes | No | Name of the bundle that creates the notification. | | creatorBundleName | string | Yes | No | Name of the bundle that creates the notification. |
| creatorUid | number | Yes | No | UID used for creating the notification. | | creatorUid | number | Yes | No | UID used for creating the notification. |
| creatorPid | number | Yes | No | PID used for creating the notification. | | creatorPid | number | Yes | No | PID used for creating the notification. |
| creatorUserId<sup>8+</sup>| number | Yes | No | ID of the user who creates the notification. | | creatorUserId<sup>8+</sup>| number | Yes | No | ID of the user who creates the notification. |
| hashCode | string | Yes | No | Unique ID of the notification. | | hashCode | string | Yes | No | Unique ID of the notification. |
| classification | string | Yes | Yes | Notification category.<br>**System API**: This is a system API and cannot be called by third-party applications. | | classification | string | Yes | Yes | Notification category.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| groupName<sup>8+</sup>| string | Yes | Yes | Group notification name. | | groupName<sup>8+</sup>| string | Yes | Yes | Notification group name. |
| template<sup>8+</sup> | [NotificationTemplate](#notificationtemplate8) | Yes | Yes | Notification template. | | template<sup>8+</sup> | [NotificationTemplate](#notificationtemplate8) | Yes | Yes | Notification template. |
| isRemoveAllowed<sup>8+</sup> | boolean | Yes | No | Whether the notification can be removed.<br>**System API**: This is a system API and cannot be called by third-party applications. | | isRemoveAllowed<sup>8+</sup> | boolean | Yes | No | Whether the notification can be removed.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| source<sup>8+</sup> | number | Yes | No | Notification source.<br>**System API**: This is a system API and cannot be called by third-party applications. | | source<sup>8+</sup> | number | Yes | No | Notification source.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| distributedOption<sup>8+</sup> | [DistributedOptions](#distributedoptions8) | Yes | Yes | Option of distributed notification. | | distributedOption<sup>8+</sup> | [DistributedOptions](#distributedoptions8) | Yes | Yes | Distributed notification options. |
| deviceId<sup>8+</sup> | string | Yes | No | Device ID of the notification source.<br>**System API**: This is a system API and cannot be called by third-party applications. | | deviceId<sup>8+</sup> | string | Yes | No | Device ID of the notification source.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| notificationFlags<sup>8+</sup> | [NotificationFlags](#notificationflags8) | Yes | No | Notification flags. | | notificationFlags<sup>8+</sup> | [NotificationFlags](#notificationflags8) | Yes | No | Notification flags. |
| removalWantAgent<sup>9+</sup> | WantAgent | Yes | Yes | **WantAgent** instance to which the notification will be redirected when it is removed. | | removalWantAgent<sup>9+</sup> | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** instance to which the notification will be redirected when it is removed. |
| badgeNumber<sup>9+</sup> | number | Yes | Yes | Number of notifications displayed on the application icon. | | badgeNumber<sup>9+</sup> | number | Yes | Yes | Number of notifications displayed on the application icon. |
## DistributedOptions<sup>8+</sup> ## DistributedOptions<sup>8+</sup>
Describes distributed options. Describes distributed notifications options.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ---------------------- | -------------- | ---- | ---- | ---------------------------------- | | ---------------------- | -------------- | ---- | ---- | ---------------------------------- |
| isDistributed | boolean | Yes | Yes | Whether the notification is a distributed notification. | | isDistributed | boolean | Yes | Yes | Whether the notification is a distributed notification. |
| supportDisplayDevices | Array\<string> | Yes | Yes | Types of the devices to which the notification can be synchronized. | | supportDisplayDevices | Array\<string> | Yes | Yes | List of the devices to which the notification can be synchronized. |
| supportOperateDevices | Array\<string> | Yes | Yes | Devices on which notification can be enabled. | | supportOperateDevices | Array\<string> | Yes | Yes | List of the devices on which the notification can be opened. |
| remindType | number | Yes | No | Notification reminder type.<br>**System API**: This is a system API and cannot be called by third-party applications. | | remindType | number | Yes | No | Notification reminder type.<br>**System API**: This is a system API and cannot be called by third-party applications. |
...@@ -4011,14 +4011,14 @@ Describes the notification slot. ...@@ -4011,14 +4011,14 @@ Describes the notification slot.
| level | number | Yes | Yes | Notification level. If this parameter is not set, the default value is used based on the notification slot type.| | level | number | Yes | Yes | Notification level. If this parameter is not set, the default value is used based on the notification slot type.|
| desc | string | Yes | Yes | Notification slot description. | | desc | string | Yes | Yes | Notification slot description. |
| badgeFlag | boolean | Yes | Yes | Whether to display the badge. | | badgeFlag | boolean | Yes | Yes | Whether to display the badge. |
| bypassDnd | boolean | Yes | Yes | Whether to bypass the DND mode in the system. | | bypassDnd | boolean | Yes | Yes | Whether to bypass DND mode in the system. |
| lockscreenVisibility | number | Yes | Yes | Mode for displaying the notification on the lock screen. | | lockscreenVisibility | number | Yes | Yes | Mode for displaying the notification on the lock screen. |
| vibrationEnabled | boolean | Yes | Yes | Whether vibration is supported for the notification. | | vibrationEnabled | boolean | Yes | Yes | Whether vibration is enabled for the notification. |
| sound | string | Yes | Yes | Notification alert tone. | | sound | string | Yes | Yes | Notification alert tone. |
| lightEnabled | boolean | Yes | Yes | Whether the indicator blinks for the notification. | | lightEnabled | boolean | Yes | Yes | Whether the indicator blinks for the notification. |
| lightColor | number | Yes | Yes | Indicator color of the notification. | | lightColor | number | Yes | Yes | Indicator color of the notification. |
| vibrationValues | Array\<number\> | Yes | Yes | Vibration mode of the notification. | | vibrationValues | Array\<number\> | Yes | Yes | Vibration mode of the notification. |
| enabled<sup>9+</sup> | boolean | Yes | No | Enabled status of the notification slot. | | enabled<sup>9+</sup> | boolean | Yes | No | Whether the notification slot is enabled. |
## NotificationSorting ## NotificationSorting
...@@ -4066,7 +4066,7 @@ Provides the information about the publisher for notification subscription. ...@@ -4066,7 +4066,7 @@ Provides the information about the publisher for notification subscription.
## NotificationTemplate<sup>8+</sup> ## NotificationTemplate<sup>8+</sup>
Notification template. Describes the notification template.
**System capability**: SystemCapability.Notification.Notification **System capability**: SystemCapability.Notification.Notification
...@@ -4121,5 +4121,5 @@ Provides the notification user input. ...@@ -4121,5 +4121,5 @@ Provides the notification user input.
| Name | Value | Description | | Name | Value | Description |
| -------------------- | --- | -------------------- | | -------------------- | --- | -------------------- |
| CLICK_REASON_REMOVE | 1 | The notification is removed due to a click on it. | | CLICK_REASON_REMOVE | 1 | The notification is removed after a click on it. |
| CANCEL_REASON_REMOVE | 2 | The notification is removed by the user. | | CANCEL_REASON_REMOVE | 2 | The notification is removed by the user. |
# @ohos.notificationManager
The **notificationManager** module provides notification management capabilities, covering notifications, notification slots, notification enabled status, and notification badge status.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import Notification from '@ohos.notificationManager';
```
## Notification.publish
publish(request: NotificationRequest, callback: AsyncCallback\<void\>): void
Publishes a notification. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | ------------------------------------------- |
| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600004 | Notification is not enabled. |
| 1600005 | Notification slot is not enabled. |
| 1600009 | Over max number notifications per second. |
**Example**
```js
// publish callback
function publishCallback(err) {
if (err) {
console.info("publish failed " + JSON.stringify(err));
} else {
console.info("publish success");
}
}
// NotificationRequest object
var notificationRequest = {
id: 1,
content: {
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
title: "test_title",
text: "test_text",
additionalText: "test_additionalText"
}
}
}
Notification.publish(notificationRequest, publishCallback)
```
## Notification.publish
publish(request: NotificationRequest): Promise\<void\>
Publishes a notification. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | ------------------------------------------- |
| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600004 | Notification is not enabled. |
| 1600005 | Notification slot is not enabled. |
| 1600009 | Over max number notifications per second. |
**Example**
```js
// NotificationRequest object
var notificationRequest = {
notificationId: 1,
content: {
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
title: "test_title",
text: "test_text",
additionalText: "test_additionalText"
}
}
}
Notification.publish(notificationRequest).then(() => {
console.info("publish success");
});
```
## Notification.publish
publish(request: NotificationRequest, userId: number, callback: AsyncCallback\<void\>): void
Publishes a notification to a specified user. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------------------------- |
| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.|
| userId | number | Yes | User ID. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600004 | Notification is not enabled. |
| 1600005 | Notification slot is not enabled. |
| 1600008 | The user is not exist. |
| 1600009 | Over max number notifications per second. |
**Example**
```js
// publish callback
function publishCallback(err) {
if (err) {
console.info("publish failed " + JSON.stringify(err));
} else {
console.info("publish success");
}
}
// User ID
var userId = 1
// NotificationRequest object
var notificationRequest = {
id: 1,
content: {
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
title: "test_title",
text: "test_text",
additionalText: "test_additionalText"
}
}
}
Notification.publish(notificationRequest, userId, publishCallback);
```
## Notification.publish
publish(request: NotificationRequest, userId: number): Promise\<void\>
Publishes a notification to a specified user. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------------------------- |
| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.|
| userId | number | Yes | User ID. |
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600004 | Notification is not enabled. |
| 1600005 | Notification slot is not enabled. |
| 1600008 | The user is not exist. |
| 1600009 | Over max number notifications per second. |
**Example**
```js
var notificationRequest = {
notificationId: 1,
content: {
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
title: "test_title",
text: "test_text",
additionalText: "test_additionalText"
}
}
}
var userId = 1
Notification.publish(notificationRequest, userId).then(() => {
console.info("publish success");
});
```
## Notification.cancel
cancel(id: number, label: string, callback: AsyncCallback\<void\>): void
Cancels a notification with the specified ID and label. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | -------------------- |
| id | number | Yes | Notification ID. |
| label | string | Yes | Notification label. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600007 | The notification is not exist. |
**Example**
```js
// cancel callback
function cancelCallback(err) {
if (err) {
console.info("cancel failed " + JSON.stringify(err));
} else {
console.info("cancel success");
}
}
Notification.cancel(0, "label", cancelCallback)
```
## Notification.cancel
cancel(id: number, label?: string): Promise\<void\>
Cancels a notification with the specified ID and optional label. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| ----- | ------ | ---- | -------- |
| id | number | Yes | Notification ID. |
| label | string | No | Notification label.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600007 | The notification is not exist. |
**Example**
```js
Notification.cancel(0).then(() => {
console.info("cancel success");
});
```
## Notification.cancel
cancel(id: number, callback: AsyncCallback\<void\>): void
Cancels a notification with the specified ID. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | -------------------- |
| id | number | Yes | Notification ID. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600007 | The notification is not exist. |
**Example**
```js
// cancel callback
function cancelCallback(err) {
if (err) {
console.info("cancel failed " + JSON.stringify(err));
} else {
console.info("cancel success");
}
}
Notification.cancel(0, cancelCallback)
```
## Notification.cancelAll
cancelAll(callback: AsyncCallback\<void\>): void
Cancels all notifications. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example**
```js
// cancel callback
function cancelAllCallback(err) {
if (err) {
console.info("cancelAll failed " + JSON.stringify(err));
} else {
console.info("cancelAll success");
}
}
Notification.cancelAll(cancelAllCallback)
```
## Notification.cancelAll
cancelAll(): Promise\<void\>
Cancels all notifications. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
Notification.cancelAll().then(() => {
console.info("cancelAll success");
});
```
## Notification.addSlot
addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>): void
Adds a notification slot. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | -------------------- |
| slot | [NotificationSlot](#notificationslot) | Yes | Notification slot to add.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
// addSlot callback
function addSlotCallBack(err) {
if (err) {
console.info("addSlot failed " + JSON.stringify(err));
} else {
console.info("addSlot success");
}
}
// NotificationSlot object
var notificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION
}
Notification.addSlot(notificationSlot, addSlotCallBack)
```
## Notification.addSlot
addSlot(slot: NotificationSlot): Promise\<void\>
Adds a notification slot. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type | Mandatory| Description |
| ---- | ---------------- | ---- | -------------------- |
| slot | [NotificationSlot](#notificationslot) | Yes | Notification slot to add.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
// NotificationSlot object
var notificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION
}
Notification.addSlot(notificationSlot).then(() => {
console.info("addSlot success");
});
```
## Notification.addSlot
addSlot(type: SlotType, callback: AsyncCallback\<void\>): void
Adds a notification slot of a specified type. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ---------------------- |
| type | [SlotType](#slottype) | Yes | Type of the notification slot to add.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
// addSlot callback
function addSlotCallBack(err) {
if (err) {
console.info("addSlot failed " + JSON.stringify(err));
} else {
console.info("addSlot success");
}
}
Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack)
```
## Notification.addSlot
addSlot(type: SlotType): Promise\<void\>
Adds a notification slot of a specified type. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name| Type | Mandatory| Description |
| ---- | -------- | ---- | ---------------------- |
| type | [SlotType](#slottype) | Yes | Type of the notification slot to add.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => {
console.info("addSlot success");
});
```
## Notification.addSlots
addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>): void
Adds an array of notification slots. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------ |
| slots | Array\<[NotificationSlot](#notificationslot)\> | Yes | Notification slots to add.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
// addSlots callback
function addSlotsCallBack(err) {
if (err) {
console.info("addSlots failed " + JSON.stringify(err));
} else {
console.info("addSlots success");
}
}
// NotificationSlot object
var notificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION
}
// NotificationSlotArray object
var notificationSlotArray = new Array();
notificationSlotArray[0] = notificationSlot;
Notification.addSlots(notificationSlotArray, addSlotsCallBack)
```
## Notification.addSlots
addSlots(slots: Array\<NotificationSlot\>): Promise\<void\>
Adds an array of notification slots. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ----- | ------------------------- | ---- | ------------------------ |
| slots | Array\<[NotificationSlot](#notificationslot)\> | Yes | Notification slots to add.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
// NotificationSlot object
var notificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION
}
// NotificationSlotArray object
var notificationSlotArray = new Array();
notificationSlotArray[0] = notificationSlot;
Notification.addSlots(notificationSlotArray).then(() => {
console.info("addSlots success");
});
```
## Notification.getSlot
getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>): void
Obtains a notification slot of a specified type. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | ----------------------------------------------------------- |
| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| callback | AsyncCallback\<[NotificationSlot](#notificationslot)\> | Yes | Callback used to return the result. |
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
// getSlot callback
function getSlotCallback(err,data) {
if (err) {
console.info("getSlot failed " + JSON.stringify(err));
} else {
console.info("getSlot success");
}
}
var slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.getSlot(slotType, getSlotCallback)
```
## Notification.getSlot
getSlot(slotType: SlotType): Promise\<NotificationSlot\>
Obtains a notification slot of a specified type. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ----------------------------------------------------------- |
| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<NotificationSlot\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
var slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.getSlot(slotType).then((data) => {
console.info("getSlot success, data: " + JSON.stringify(data));
});
```
## Notification.getSlots
getSlots(callback: AsyncCallback<Array\<NotificationSlot\>>): void
Obtains all notification slots of this application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | -------------------- |
| callback | AsyncCallback\<Array\<[NotificationSlot](#notificationslot)\>\> | Yes | Callback used to return all notification slots of the current application.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
// getSlots callback
function getSlotsCallback(err,data) {
if (err) {
console.info("getSlots failed " + JSON.stringify(err));
} else {
console.info("getSlots success");
}
}
Notification.getSlots(getSlotsCallback)
```
## Notification.getSlots
getSlots(): Promise\<Array\<NotificationSlot\>>
Obtains all notification slots of this application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<Array\<[NotificationSlot](#notificationslot)\>\> | Promise used to return all notification slots of the current application.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
Notification.getSlots().then((data) => {
console.info("getSlots success, data: " + JSON.stringify(data));
});
```
## Notification.removeSlot
removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>): void
Removes a notification slot of a specified type. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ----------------------------------------------------------- |
| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
// removeSlot callback
function removeSlotCallback(err) {
if (err) {
console.info("removeSlot failed " + JSON.stringify(err));
} else {
console.info("removeSlot success");
}
}
var slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.removeSlot(slotType,removeSlotCallback)
```
## Notification.removeSlot
removeSlot(slotType: SlotType): Promise\<void\>
Removes a notification slot of a specified type. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ----------------------------------------------------------- |
| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
var slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.removeSlot(slotType).then(() => {
console.info("removeSlot success");
});
```
## Notification.removeAllSlots
removeAllSlots(callback: AsyncCallback\<void\>): void
Removes all notification slots. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
function removeAllCallBack(err) {
if (err) {
console.info("removeAllSlots failed " + JSON.stringify(err));
} else {
console.info("removeAllSlots success");
}
}
Notification.removeAllSlots(removeAllCallBack)
```
## Notification.removeAllSlots
removeAllSlots(): Promise\<void\>
Removes all notification slots. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
Notification.removeAllSlots().then(() => {
console.info("removeAllSlots success");
});
```
## Notification.setNotificationEnable
setNotificationEnable(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void
Sets whether to enable notification for a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | -------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. |
| enable | boolean | Yes | Whether to enable notification. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
function setNotificationEnablenCallback(err) {
if (err) {
console.info("setNotificationEnablenCallback failed " + JSON.stringify(err));
} else {
console.info("setNotificationEnablenCallback success");
}
}
var bundle = {
bundle: "bundleName1",
}
Notification.setNotificationEnable(bundle, false, setNotificationEnablenCallback);
```
## Notification.setNotificationEnable
setNotificationEnable(bundle: BundleOption, enable: boolean): Promise\<void\>
Sets whether to enable notification for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.|
| enable | boolean | Yes | Whether to enable notification. |
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
var bundle = {
bundle: "bundleName1",
}
Notification.setNotificationEnable(bundle, false).then(() => {
console.info("setNotificationEnable success");
});
```
## Notification.isNotificationEnabled
isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void
Checks whether notification is enabled for a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------------ |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
function isNotificationEnabledCallback(err, data) {
if (err) {
console.info("isNotificationEnabled failed " + JSON.stringify(err));
} else {
console.info("isNotificationEnabled success");
}
}
var bundle = {
bundle: "bundleName1",
}
Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback);
```
## Notification.isNotificationEnabled
isNotificationEnabled(bundle: BundleOption): Promise\<boolean\>
Checks whether notification is enabled for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.|
**Return value**
| Type | Description |
| ------------------ | --------------------------------------------------- |
| Promise\<boolean\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
var bundle = {
bundle: "bundleName1",
}
Notification.isNotificationEnabled(bundle).then((data) => {
console.info("isNotificationEnabled success, data: " + JSON.stringify(data));
});
```
## Notification.isNotificationEnabled
isNotificationEnabled(callback: AsyncCallback\<boolean\>): void
Checks whether notification is enabled for this application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------------ |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
function isNotificationEnabledCallback(err, data) {
if (err) {
console.info("isNotificationEnabled failed " + JSON.stringify(err));
} else {
console.info("isNotificationEnabled success");
}
}
Notification.isNotificationEnabled(isNotificationEnabledCallback);
```
## Notification.isNotificationEnabled
isNotificationEnabled(): Promise\<boolean\>
Checks whether notification is enabled for the current application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.|
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
Notification.isNotificationEnabled().then((data) => {
console.info("isNotificationEnabled success, data: " + JSON.stringify(data));
});
```
## Notification.displayBadge
displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void\>): void
Sets whether to enable the notification badge for a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | -------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. |
| enable | boolean | Yes | Whether to enable notification. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
function displayBadgeCallback(err) {
if (err) {
console.info("displayBadge failed " + JSON.stringify(err));
} else {
console.info("displayBadge success");
}
}
var bundle = {
bundle: "bundleName1",
}
Notification.displayBadge(bundle, false, displayBadgeCallback);
```
## Notification.displayBadge
displayBadge(bundle: BundleOption, enable: boolean): Promise\<void\>
Sets whether to enable the notification badge for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.|
| enable | boolean | Yes | Whether to enable notification. |
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
var bundle = {
bundle: "bundleName1",
}
Notification.displayBadge(bundle, false).then(() => {
console.info("displayBadge success");
});
```
## Notification.isBadgeDisplayed
isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void
Checks whether the notification badge is enabled for a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------------ |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
function isBadgeDisplayedCallback(err, data) {
if (err) {
console.info("isBadgeDisplayed failed " + JSON.stringify(err));
} else {
console.info("isBadgeDisplayed success");
}
}
var bundle = {
bundle: "bundleName1",
}
Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback);
```
## Notification.isBadgeDisplayed
isBadgeDisplayed(bundle: BundleOption): Promise\<boolean\>
Checks whether the notification badge is enabled for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.|
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
var bundle = {
bundle: "bundleName1",
}
Notification.isBadgeDisplayed(bundle).then((data) => {
console.info("isBadgeDisplayed success, data: " + JSON.stringify(data));
});
```
## Notification.setSlotByBundle
setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\<void\>): void
Sets the notification slot for a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | -------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. |
| slot | [NotificationSlot](#notificationslot) | Yes | Notification slot. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
function setSlotByBundleCallback(err) {
if (err) {
console.info("setSlotByBundle failed " + JSON.stringify(err));
} else {
console.info("setSlotByBundle success");
}
}
var bundle = {
bundle: "bundleName1",
}
var notificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION
}
Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback);
```
## Notification.setSlotByBundle
setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\<void\>
Sets the notification slot for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.|
| slot | [NotificationSlot](#notificationslot) | Yes | Notification slot.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
var bundle = {
bundle: "bundleName1",
}
var notificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION
}
Notification.setSlotByBundle(bundle, notificationSlot).then(() => {
console.info("setSlotByBundle success");
});
```
## Notification.getSlotsByBundle
getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback<Array\<NotificationSlot\>>): void
Obtains the notification slots of a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | -------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. |
| callback | AsyncCallback<Array\<[NotificationSlot](#notificationslot)\>> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
function getSlotsByBundleCallback(err, data) {
if (err) {
console.info("getSlotsByBundle failed " + JSON.stringify(err));
} else {
console.info("getSlotsByBundle success");
}
}
var bundle = {
bundle: "bundleName1",
}
Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback);
```
## Notification.getSlotsByBundle
getSlotsByBundle(bundle: BundleOption): Promise<Array\<NotificationSlot\>>
Obtains the notification slots of a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.|
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise<Array\<[NotificationSlot](#notificationslot)\>> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
var bundle = {
bundle: "bundleName1",
}
Notification.getSlotsByBundle(bundle).then((data) => {
console.info("getSlotsByBundle success, data: " + JSON.stringify(data));
});
```
## Notification.getSlotNumByBundle
getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<number\>): void
Obtains the number of notification slots of a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. |
| callback | AsyncCallback\<number\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
function getSlotNumByBundleCallback(err, data) {
if (err) {
console.info("getSlotNumByBundle failed " + JSON.stringify(err));
} else {
console.info("getSlotNumByBundle success");
}
}
var bundle = {
bundle: "bundleName1",
}
Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback);
```
## Notification.getSlotNumByBundle
getSlotNumByBundle(bundle: BundleOption): Promise\<number\>
Obtains the number of notification slots of a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.|
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<number\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
var bundle = {
bundle: "bundleName1",
}
Notification.getSlotNumByBundle(bundle).then((data) => {
console.info("getSlotNumByBundle success, data: " + JSON.stringify(data));
});
```
## Notification.getAllActiveNotifications
getAllActiveNotifications(callback: AsyncCallback<Array\<NotificationRequest\>>): void
Obtains all active notifications. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | -------------------- |
| callback | AsyncCallback<Array\<[NotificationRequest](#notificationrequest)\>> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
function getAllActiveNotificationsCallback(err, data) {
if (err) {
console.info("getAllActiveNotifications failed " + JSON.stringify(err));
} else {
console.info("getAllActiveNotifications success");
}
}
Notification.getAllActiveNotifications(getAllActiveNotificationsCallback);
```
## Notification.getAllActiveNotifications
getAllActiveNotifications(): Promise\<Array\<[NotificationRequest](#notificationrequest)\>\>
Obtains all active notifications. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<Array\<[NotificationRequest](#notificationrequest)\>\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
Notification.getAllActiveNotifications().then((data) => {
console.info("getAllActiveNotifications success, data: " + JSON.stringify(data));
});
```
## Notification.getActiveNotificationCount
getActiveNotificationCount(callback: AsyncCallback\<number\>): void
Obtains the number of active notifications of this application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ---------------------- |
| callback | AsyncCallback\<number\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
function getActiveNotificationCountCallback(err, data) {
if (err) {
console.info("getActiveNotificationCount failed " + JSON.stringify(err));
} else {
console.info("getActiveNotificationCount success");
}
}
Notification.getActiveNotificationCount(getActiveNotificationCountCallback);
```
## Notification.getActiveNotificationCount
getActiveNotificationCount(): Promise\<number\>
Obtains the number of active notifications of this application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Return value**
| Type | Description |
| ----------------- | ------------------------------------------- |
| Promise\<number\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
Notification.getActiveNotificationCount().then((data) => {
console.info("getActiveNotificationCount success, data: " + JSON.stringify(data));
});
```
## Notification.getActiveNotifications
getActiveNotifications(callback: AsyncCallback<Array\<NotificationRequest\>>): void
Obtains active notifications of this application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------ |
| callback | AsyncCallback<Array\<[NotificationRequest](#notificationrequest)\>> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
function getActiveNotificationsCallback(err, data) {
if (err) {
console.info("getActiveNotifications failed " + JSON.stringify(err));
} else {
console.info("getActiveNotifications success");
}
}
Notification.getActiveNotifications(getActiveNotificationsCallback);
```
## Notification.getActiveNotifications
getActiveNotifications(): Promise\<Array\<[NotificationRequest](#notificationrequest)\>\>
Obtains active notifications of this application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Return value**
| Type | Description |
| ------------------------------------------------------------ | --------------------------------------- |
| Promise\<Array\<[NotificationRequest](#notificationrequest)\>\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
Notification.getActiveNotifications().then((data) => {
console.info("removeGroupByBundle success, data: " + JSON.stringify(data));
});
```
## Notification.cancelGroup
cancelGroup(groupName: string, callback: AsyncCallback\<void\>): void
Cancels notifications under a notification group of this application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | --------------------- | ---- | ---------------------------- |
| groupName | string | Yes | Name of the notification group, which is specified through [NotificationRequest](#notificationrequest) when the notification is published.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
function cancelGroupCallback(err) {
if (err) {
console.info("cancelGroup failed " + JSON.stringify(err));
} else {
console.info("cancelGroup success");
}
}
var groupName = "GroupName";
Notification.cancelGroup(groupName, cancelGroupCallback);
```
## Notification.cancelGroup
cancelGroup(groupName: string): Promise\<void\>
Cancels notifications under a notification group of this application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | -------------- |
| groupName | string | Yes | Name of the notification group.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
var groupName = "GroupName";
Notification.cancelGroup(groupName).then(() => {
console.info("cancelGroup success");
});
```
## Notification.removeGroupByBundle
removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\<void\>): void
Removes notifications under a notification group of a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | --------------------- | ---- | ---------------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| groupName | string | Yes | Name of the notification group. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
function removeGroupByBundleCallback(err) {
if (err) {
console.info("removeGroupByBundle failed " + JSON.stringify(err));
} else {
console.info("removeGroupByBundle success");
}
}
var bundleOption = {bundle: "Bundle"};
var groupName = "GroupName";
Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCallback);
```
## Notification.removeGroupByBundle
removeGroupByBundle(bundle: BundleOption, groupName: string): Promise\<void\>
Removes notifications under a notification group of a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------ | ---- | -------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| groupName | string | Yes | Name of the notification group.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
var bundleOption = {bundle: "Bundle"};
var groupName = "GroupName";
Notification.removeGroupByBundle(bundleOption, groupName).then(() => {
console.info("removeGroupByBundle success");
});
```
## Notification.setDoNotDisturbDate
setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\<void\>): void
Sets the DND time. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ---------------------- |
| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
function setDoNotDisturbDateCallback(err) {
if (err) {
console.info("setDoNotDisturbDate failed " + JSON.stringify(err));
} else {
console.info("setDoNotDisturbDate success");
}
}
var doNotDisturbDate = {
type: Notification.DoNotDisturbType.TYPE_ONCE,
begin: new Date(),
end: new Date(2021, 11, 15, 18, 0)
}
Notification.setDoNotDisturbDate(doNotDisturbDate, setDoNotDisturbDateCallback);
```
## Notification.setDoNotDisturbDate
setDoNotDisturbDate(date: DoNotDisturbDate): Promise\<void\>
Sets the DND time. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type | Mandatory| Description |
| ---- | ---------------- | ---- | -------------- |
| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
var doNotDisturbDate = {
type: Notification.DoNotDisturbType.TYPE_ONCE,
begin: new Date(),
end: new Date(2021, 11, 15, 18, 0)
}
Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => {
console.info("setDoNotDisturbDate success");
});
```
## Notification.setDoNotDisturbDate
setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallback\<void\>): void
Sets the DND time for a specified user. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ---------------------- |
| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set. |
| userId | number | Yes | ID of the user for whom you want to set the DND time.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600008 | The user is not exist. |
**Example**
```js
function setDoNotDisturbDateCallback(err) {
if (err) {
console.info("setDoNotDisturbDate failed " + JSON.stringify(err));
} else {
console.info("setDoNotDisturbDate success");
}
}
var doNotDisturbDate = {
type: Notification.DoNotDisturbType.TYPE_ONCE,
begin: new Date(),
end: new Date(2021, 11, 15, 18, 0)
}
var userId = 1
Notification.setDoNotDisturbDate(doNotDisturbDate, userId, setDoNotDisturbDateCallback);
```
## Notification.setDoNotDisturbDate
setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise\<void\>
Sets the DND time for a specified user. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ---------------- | ---- | -------------- |
| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set.|
| userId | number | Yes | ID of the user for whom you want to set the DND time.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600008 | The user is not exist. |
**Example**
```js
var doNotDisturbDate = {
type: Notification.DoNotDisturbType.TYPE_ONCE,
begin: new Date(),
end: new Date(2021, 11, 15, 18, 0)
}
var userId = 1
Notification.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => {
console.info("setDoNotDisturbDate success");
});
```
## Notification.getDoNotDisturbDate
getDoNotDisturbDate(callback: AsyncCallback\<DoNotDisturbDate\>): void
Obtains the DND time. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | ---------------------- |
| callback | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate)\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
function getDoNotDisturbDateCallback(err,data) {
if (err) {
console.info("getDoNotDisturbDate failed " + JSON.stringify(err));
} else {
console.info("getDoNotDisturbDate success");
}
}
Notification.getDoNotDisturbDate(getDoNotDisturbDateCallback);
```
## Notification.getDoNotDisturbDate
getDoNotDisturbDate(): Promise\<DoNotDisturbDate\>
Obtains the DND time. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Return value**
| Type | Description |
| ------------------------------------------------ | ----------------------------------------- |
| Promise\<[DoNotDisturbDate](#donotdisturbdate)\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
Notification.getDoNotDisturbDate().then((data) => {
console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data));
});
```
## Notification.getDoNotDisturbDate
getDoNotDisturbDate(userId: number, callback: AsyncCallback\<DoNotDisturbDate\>): void
Obtains the DND time of a specified user. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | ---------------------- |
| callback | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate)\> | Yes | Callback used to return the result.|
| userId | number | Yes | User ID.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600008 | The user is not exist. |
**Example**
```js
function getDoNotDisturbDateCallback(err,data) {
if (err) {
console.info("getDoNotDisturbDate failed " + JSON.stringify(err));
} else {
console.info("getDoNotDisturbDate success");
}
}
var userId = 1
Notification.getDoNotDisturbDate(userId, getDoNotDisturbDateCallback);
```
## Notification.getDoNotDisturbDate
getDoNotDisturbDate(userId: number): Promise\<DoNotDisturbDate\>
Obtains the DND time of a specified user. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | ---------------------- |
| userId | number | Yes | User ID.|
**Return value**
| Type | Description |
| ------------------------------------------------ | ----------------------------------------- |
| Promise\<[DoNotDisturbDate](#donotdisturbdate)\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600008 | The user is not exist. |
**Example**
```js
var userId = 1
Notification.getDoNotDisturbDate(userId).then((data) => {
console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data));
});
```
## Notification.supportDoNotDisturbMode
supportDoNotDisturbMode(callback: AsyncCallback\<boolean\>): void
Checks whether DND mode is supported. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------------- |
| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
function supportDoNotDisturbModeCallback(err,data) {
if (err) {
console.info("supportDoNotDisturbMode failed " + JSON.stringify(err));
} else {
console.info("supportDoNotDisturbMode success");
}
}
Notification.supportDoNotDisturbMode(supportDoNotDisturbModeCallback);
```
## Notification.supportDoNotDisturbMode
supportDoNotDisturbMode(): Promise\<boolean\>
Checks whether DND mode is supported. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
Notification.supportDoNotDisturbMode().then((data) => {
console.info("supportDoNotDisturbMode success, data: " + JSON.stringify(data));
});
```
## Notification.isSupportTemplate
isSupportTemplate(templateName: string, callback: AsyncCallback\<boolean\>): void
Checks whether a specified template is supported. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | ------------------------ | ---- | -------------------------- |
| templateName | string | Yes | Template name. |
| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600011 | Read template config failed. |
**Example**
```javascript
var templateName = 'process';
function isSupportTemplateCallback(err, data) {
if (err) {
console.info("isSupportTemplate failed " + JSON.stringify(err));
} else {
console.info("isSupportTemplate success");
}
}
Notification.isSupportTemplate(templateName, isSupportTemplateCallback);
```
## Notification.isSupportTemplate
isSupportTemplate(templateName: string): Promise\<boolean\>
Checks whether a specified template is supported. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | ------ | ---- | -------- |
| templateName | string | Yes | Template name.|
**Return value**
| Type | Description |
| ------------------ | --------------- |
| Promise\<boolean\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600011 | Read template config failed. |
**Example**
```javascript
var templateName = 'process';
Notification.isSupportTemplate(templateName).then((data) => {
console.info("isSupportTemplate success, data: " + JSON.stringify(data));
});
```
## Notification.requestEnableNotification
requestEnableNotification(callback: AsyncCallback\<void\>): void
Requests notification to be enabled for this application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```javascript
function requestEnableNotificationCallback(err) {
if (err) {
console.info("requestEnableNotification failed " + JSON.stringify(err));
} else {
console.info("requestEnableNotification success");
}
};
Notification.requestEnableNotification(requestEnableNotificationCallback);
```
## Notification.requestEnableNotification
requestEnableNotification(): Promise\<void\>
Requests notification to be enabled for this application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```javascript
Notification.requestEnableNotification().then(() => {
console.info("requestEnableNotification success");
});
```
## Notification.setDistributedEnable
setDistributedEnable(enable: boolean, callback: AsyncCallback\<void\>): void
Sets whether this device supports distributed notifications. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- |
| enable | boolean | Yes | Whether the device supports distributed notifications.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600010 | Distributed operation failed. |
**Example**
```javascript
function setDistributedEnableCallback() {
if (err) {
console.info("setDistributedEnable failed " + JSON.stringify(err));
} else {
console.info("setDistributedEnable success");
}
};
var enable = true
Notification.setDistributedEnable(enable, setDistributedEnableCallback);
```
## Notification.setDistributedEnable
setDistributedEnable(enable: boolean): Promise\<void>
Sets whether this device supports distributed notifications. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- |
| enable | boolean | Yes | Whether the device supports distributed notifications.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600010 | Distributed operation failed. |
**Example**
```javascript
var enable = true
Notification.setDistributedEnable(enable).then(() => {
console.info("setDistributedEnable success");
});
```
## Notification.isDistributedEnabled
isDistributedEnabled(callback: AsyncCallback\<boolean>): void
Checks whether this device supports distributed notifications. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- |
| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600010 | Distributed operation failed. |
**Example**
```javascript
function isDistributedEnabledCallback(err, data) {
if (err) {
console.info("isDistributedEnabled failed " + JSON.stringify(err));
} else {
console.info("isDistributedEnabled success " + JSON.stringify(data));
}
};
Notification.isDistributedEnabled(isDistributedEnabledCallback);
```
## Notification.isDistributedEnabled
isDistributedEnabled(): Promise\<boolean>
Checks whether this device supports distributed notifications. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Return value**
| Type | Description |
| ------------------ | --------------------------------------------- |
| Promise\<boolean\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600010 | Distributed operation failed. |
**Example**
```javascript
Notification.isDistributedEnabled()
.then((data) => {
console.info("isDistributedEnabled success, data: " + JSON.stringify(data));
});
```
## Notification.setDistributedEnableByBundle
setDistributedEnableByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<void>): void
Sets whether a specified application supports distributed notifications. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| enable | boolean | Yes | Whether the application supports distributed notifications. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600010 | Distributed operation failed. |
| 17700001 | The specified bundle name was not found. |
**Example**
```javascript
function setDistributedEnableByBundleCallback(err) {
if (err) {
console.info("enableDistributedByBundle failed " + JSON.stringify(err));
} else {
console.info("enableDistributedByBundle success");
}
};
var bundle = {
bundle: "bundleName1",
}
var enable = true
Notification.setDistributedEnableByBundle(bundle, enable, setDistributedEnableByBundleCallback);
```
## Notification.setDistributedEnableByBundle
setDistributedEnableByBundle(bundle: BundleOption, enable: boolean): Promise\<void>
Sets whether a specified application supports distributed notifications. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| enable | boolean | Yes | Whether the application supports distributed notifications. |
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600010 | Distributed operation failed. |
| 17700001 | The specified bundle name was not found. |
**Example**
```javascript
var bundle = {
bundle: "bundleName1",
}
var enable = true
Notification.setDistributedEnableByBundle(bundle, enable).then(() => {
console.info("setDistributedEnableByBundle success");
});
```
## Notification.isDistributedEnabledByBundle
isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback\<boolean>): void
Checks whether a specified application supports distributed notifications. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600010 | Distributed operation failed. |
| 17700001 | The specified bundle name was not found. |
**Example**
```javascript
function isDistributedEnabledByBundleCallback(data) {
if (err) {
console.info("isDistributedEnabledByBundle failed " + JSON.stringify(err));
} else {
console.info("isDistributedEnabledByBundle success" + JSON.stringify(data));
}
};
var bundle = {
bundle: "bundleName1",
}
Notification.isDistributedEnabledByBundle(bundle, isDistributedEnabledByBundleCallback);
```
## Notification.isDistributedEnabledByBundle
isDistributedEnabledByBundle(bundle: BundleOption): Promise\<boolean>
Checks whether a specified application supports distributed notifications. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
**Return value**
| Type | Description |
| ------------------ | ------------------------------------------------- |
| Promise\<boolean\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600010 | Distributed operation failed. |
| 17700001 | The specified bundle name was not found. |
**Example**
```javascript
var bundle = {
bundle: "bundleName1",
}
Notification.isDistributedEnabledByBundle(bundle).then((data) => {
console.info("isDistributedEnabledByBundle success, data: " + JSON.stringify(data));
});
```
## Notification.getDeviceRemindType
getDeviceRemindType(callback: AsyncCallback\<DeviceRemindType\>): void
Obtains the notification reminder type. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback\<[DeviceRemindType](#deviceremindtype)\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```javascript
function getDeviceRemindTypeCallback(err, data) {
if (err) {
console.info("getDeviceRemindType failed " + JSON.stringify(err));
} else {
console.info("getDeviceRemindType success");
}
};
Notification.getDeviceRemindType(getDeviceRemindTypeCallback);
```
## Notification.getDeviceRemindType
getDeviceRemindType(): Promise\<DeviceRemindType\>
Obtains the notification reminder type. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Return value**
| Type | Description |
| ------------------ | --------------- |
| Promise\<[DeviceRemindType](#deviceremindtype)\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```javascript
Notification.getDeviceRemindType().then((data) => {
console.info("getDeviceRemindType success, data: " + JSON.stringify(data));
});
```
## Notification.publishAsBundle
publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number, callback: AsyncCallback\<void\>): void
Publishes a notification through the reminder agent. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------------------- | ------------------------------------------- | ---- | ---------------------------------------- |
| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.|
| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. |
| userId | number | Yes | User ID. |
| callback | AsyncCallback | Yes | Callback used to return the result. |
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600004 | Notification is not enabled. |
| 1600005 | Notification slot is not enabled. |
| 1600008 | The user is not exist. |
| 1600009 | Over max number notifications per second. |
**Example**
```js
// publishAsBundle callback
function callback(err) {
if (err) {
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
let representativeBundle = "com.example.demo"
// User ID
let userId = 100
// NotificationRequest object
let request = {
id: 1,
content: {
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
title: "test_title",
text: "test_text",
additionalText: "test_additionalText"
}
}
}
Notification.publishAsBundle(request, representativeBundle, userId, callback);
```
## Notification.publishAsBundle
publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number): Promise\<void\>
Publishes a notification through the reminder agent. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------------------- | ------------------------------------------- | ---- | --------------------------------------------- |
| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.|
| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. |
| userId | number | Yes | User ID. |
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600004 | Notification is not enabled. |
| 1600005 | Notification slot is not enabled. |
| 1600008 | The user is not exist. |
| 1600009 | Over max number notifications per second. |
**Example**
```js
// Bundle name of the application whose notification function is taken over by the reminder agent
let representativeBundle = "com.example.demo"
// User ID
let userId = 100
// NotificationRequest object
var request = {
id: 1,
content: {
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
title: "test_title",
text: "test_text",
additionalText: "test_additionalText"
}
}
}
Notification.publishAsBundle(request, representativeBundle, userId).then(() => {
console.info("publishAsBundle success");
});
```
## Notification.cancelAsBundle
cancelAsBundle(id: number, representativeBundle: string, userId: number, callback: AsyncCallback\<void\>): void
Cancels a notification published by the reminder agent. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------------------- | ------------- | ---- | ------------------------ |
| id | number | Yes | Notification ID. |
| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. |
| userId | number | Yes | User ID. |
| callback | AsyncCallback | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600007 | The notification is not exist. |
| 1600008 | The user is not exist. |
**Example**
```js
// cancelAsBundle
function cancelAsBundleCallback(err) {
if (err) {
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
let representativeBundle = "com.example.demo"
// User ID
let userId = 100
Notification.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallback);
```
## Notification.cancelAsBundle
cancelAsBundle(id: number, representativeBundle: string, userId: number): Promise\<void\>
Cancels a notification published by the reminder agent. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------------------- | ------ | ---- | ------------------ |
| id | number | Yes | Notification ID. |
| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent.|
| userId | number | Yes | User ID.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600007 | The notification is not exist. |
| 1600008 | The user is not exist. |
**Example**
```js
// Bundle name of the application whose notification function is taken over by the reminder agent
let representativeBundle = "com.example.demo"
// User ID
let userId = 100
Notification.cancelAsBundle(0, representativeBundle, userId).then(() => {
console.info("cancelAsBundle success");
});
```
## Notification.setNotificationEnableSlot
setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean, callback: AsyncCallback\<void>): void
Sets whether to enable a specified notification slot type for a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------- | ---- | ---------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| type | [SlotType](#slottype) | Yes | Notification slot type. |
| enable | boolean | Yes | Whether to enable the notification slot type. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
// setNotificationEnableSlot
function setNotificationEnableSlotCallback(err) {
if (err) {
console.info("setNotificationEnableSlot failed " + JSON.stringify(err));
} else {
console.info("setNotificationEnableSlot success");
}
};
Notification.setNotificationEnableSlot(
{ bundle: "ohos.samples.notification", },
Notification.SlotType.SOCIAL_COMMUNICATION,
true,
setNotificationEnableSlotCallback);
```
## Notification.setNotificationEnableSlot
setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean): Promise\<void>
Sets whether to enable a specified notification slot type for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | -------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| type | [SlotType](#slottype) | Yes | Notification slot type.|
| enable | boolean | Yes | Whether to enable the notification slot type. |
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
// setNotificationEnableSlot
Notification.setNotificationEnableSlot(
{ bundle: "ohos.samples.notification", },
Notification.SlotType.SOCIAL_COMMUNICATION,
true).then(() => {
console.info("setNotificationEnableSlot success");
});
```
## Notification.isNotificationSlotEnabled
isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncCallback\<boolean\>): void
Checks whether a specified notification slot type is enabled for a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------- | ---- | ---------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| type | [SlotType](#slottype) | Yes | Notification slot type. |
| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
// isNotificationSlotEnabled
function getEnableSlotCallback(err, data) {
if (err) {
console.info("isNotificationSlotEnabled failed " + JSON.stringify(err));
} else {
console.info("isNotificationSlotEnabled success");
}
};
Notification.isNotificationSlotEnabled(
{ bundle: "ohos.samples.notification", },
Notification.SlotType.SOCIAL_COMMUNICATION,
getEnableSlotCallback);
```
## Notification.isNotificationSlotEnabled
isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise\<boolean\>
Checks whether a specified notification slot type is enabled for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | -------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| type | [SlotType](#slottype) | Yes | Notification slot type.|
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
// isNotificationSlotEnabled
Notification.isNotificationSlotEnabled({ bundle: "ohos.samples.notification", },
Notification.SlotType.SOCIAL_COMMUNICATION).then((data) => {
console.info("isNotificationSlotEnabled success, data: " + JSON.stringify(data));
});
```
## Notification.setSyncNotificationEnabledWithoutApp
setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean, callback: AsyncCallback\<void\>): void
Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | -------------- |
| userId | number | Yes | User ID. |
| enable | boolean | Yes | Whether the feature is enabled. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600008 | The user is not exist. |
**Example**
```js
let userId = 100;
let enable = true;
function callback(err) {
if (err) {
console.info("setSyncNotificationEnabledWithoutApp failed " + JSON.stringify(err));
} else {
console.info("setSyncNotificationEnabledWithoutApp success");
}
}
Notification.setSyncNotificationEnabledWithoutApp(userId, enable, callback);
```
## Notification.setSyncNotificationEnabledWithoutApp
setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): Promise\<void>
Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | -------------- |
| userId | number | Yes | User ID. |
| enable | boolean | Yes | Whether the feature is enabled. |
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<void\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600008 | The user is not exist. |
**Example**
```js
let userId = 100;
let enable = true;
Notification.setSyncNotificationEnabledWithoutApp(userId, enable).then(() => {
console.info('setSyncNotificationEnabledWithoutApp success');
}).catch((err) => {
console.info('setSyncNotificationEnabledWithoutApp, err:' + JSON.stringify(err));
});
```
## Notification.getSyncNotificationEnabledWithoutApp
getSyncNotificationEnabledWithoutApp(userId: number, callback: AsyncCallback\<boolean>): void
Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | -------------- |
| userId | number | Yes | User ID. |
| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600008 | The user is not exist. |
**Example**
```js
let userId = 100;
function getSyncNotificationEnabledWithoutAppCallback(err, data) {
if (err) {
console.info('getSyncNotificationEnabledWithoutAppCallback, err:' + err);
} else {
console.info('getSyncNotificationEnabledWithoutAppCallback, data:' + data);
}
}
Notification.getSyncNotificationEnabledWithoutApp(userId, getSyncNotificationEnabledWithoutAppCallback);
```
## Notification.getSyncNotificationEnabledWithoutApp
getSyncNotificationEnabledWithoutApp(userId: number): Promise\<boolean>
Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | -------------- |
| userId | number | Yes | User ID. |
**Return value**
| Type | Description |
| ------------------ | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600008 | The user is not exist. |
**Example**
```js
let userId = 100;
Notification.getSyncNotificationEnabledWithoutApp(userId).then((data) => {
console.info('getSyncNotificationEnabledWithoutApp, data:' + data);
}).catch((err) => {
console.info('getSyncNotificationEnabledWithoutApp, err:' + err);
});
.catch((err) => {
console.info('getSyncNotificationEnabledWithoutApp, err:', err);
});
```
## DoNotDisturbDate
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Readable| Writable| Description |
| ----- | ------------------------------------- | ---- | ---- | ---------------------- |
| type | [DoNotDisturbType](#donotdisturbtype) | Yes | Yes | DND time type.|
| begin | Date | Yes | Yes | DND start time.|
| end | Date | Yes | Yes | DND end time.|
## DoNotDisturbType
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Value | Description |
| ------------ | ---------------- | ------------------------------------------ |
| TYPE_NONE | 0 | Non-DND. |
| TYPE_ONCE | 1 | One-shot DND at the specified time segment (only considering the hour and minute).|
| TYPE_DAILY | 2 | Daily DND at the specified time segment (only considering the hour and minute).|
| TYPE_CLEARLY | 3 | DND at the specified time segment (considering the year, month, day, hour, and minute). |
## ContentType
**System capability**: SystemCapability.Notification.Notification
| Name | Value | Description |
| --------------------------------- | ----------- | ------------------ |
| NOTIFICATION_CONTENT_BASIC_TEXT | NOTIFICATION_CONTENT_BASIC_TEXT | Normal text notification. |
| NOTIFICATION_CONTENT_LONG_TEXT | NOTIFICATION_CONTENT_LONG_TEXT | Long text notification. |
| NOTIFICATION_CONTENT_PICTURE | NOTIFICATION_CONTENT_PICTURE | Picture-attached notification. |
| NOTIFICATION_CONTENT_CONVERSATION | NOTIFICATION_CONTENT_CONVERSATION | Conversation notification. |
| NOTIFICATION_CONTENT_MULTILINE | NOTIFICATION_CONTENT_MULTILINE | Multi-line text notification.|
## SlotLevel
**System capability**: SystemCapability.Notification.Notification
| Name | Value | Description |
| --------------------------------- | ----------- | ------------------ |
| LEVEL_NONE | 0 | Notification is disabled. |
| LEVEL_MIN | 1 | Notification is enabled, but the notification icon is not displayed in the status bar, with no banner or alert tone.|
| LEVEL_LOW | 2 | Notification is enabled, and the notification icon is displayed in the status bar, with no banner or alert tone.|
| LEVEL_DEFAULT | 3 | Notification is enabled, and the notification icon is displayed in the status bar, with an alert tone but no banner.|
| LEVEL_HIGH | 4 | Notification is enabled, and the notification icon is displayed in the status bar, with an alert tone and banner.|
## BundleOption
**System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description |
| ------ | ------ |---- | --- | ------ |
| bundle | string | Yes | Yes | Bundle information of the application.|
| uid | number | Yes | Yes | User ID.|
## SlotType
**System capability**: SystemCapability.Notification.Notification
| Name | Value | Description |
| -------------------- | -------- | ---------- |
| UNKNOWN_TYPE | 0 | Unknown type.|
| SOCIAL_COMMUNICATION | 1 | Notification slot for social communication.|
| SERVICE_INFORMATION | 2 | Notification slot for service information.|
| CONTENT_INFORMATION | 3 | Notification slot for content consultation.|
| OTHER_TYPES | 0xFFFF | Notification slot for other purposes.|
## NotificationActionButton
Describes the button displayed in the notification.
**System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description |
| --------- | ----------------------------------------------- | --- | ---- | ------------------------- |
| title | string | Yes | Yes | Button title. |
| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** of the button.|
| extras | { [key: string]: any } | Yes | Yes | Extra information of the button. |
| userInput | [NotificationUserInput](#notificationuserinput) | Yes | Yes | User input object. |
## NotificationBasicContent
Describes the normal text notification.
**System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description |
| -------------- | ------ | ---- | ---- | ---------------------------------- |
| title | string | Yes | Yes | Notification title. |
| text | string | Yes | Yes | Notification content. |
| additionalText | string | Yes | Yes | Additional information of the notification.|
## NotificationLongTextContent
Describes the long text notification.
**System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description |
| -------------- | ------ | ---- | --- | -------------------------------- |
| title | string | Yes | Yes | Notification title. |
| text | string | Yes | Yes | Notification content. |
| additionalText | string | Yes | Yes | Additional information of the notification.|
| longText | string | Yes | Yes | Long text of the notification. |
| briefText | string | Yes | Yes | Brief text of the notification.|
| expandedTitle | string | Yes | Yes | Title of the notification in the expanded state. |
## NotificationMultiLineContent
Describes the multi-line text notification.
**System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description |
| -------------- | --------------- | --- | --- | -------------------------------- |
| title | string | Yes | Yes | Notification title. |
| text | string | Yes | Yes | Notification content. |
| additionalText | string | Yes | Yes | Additional information of the notification.|
| briefText | string | Yes | Yes | Brief text of the notification.|
| longTitle | string | Yes | Yes | Title of the notification in the expanded state. |
| lines | Array\<string\> | Yes | Yes | Multi-line text of the notification. |
## NotificationPictureContent
Describe the picture-attached notification.
**System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description |
| -------------- | -------------- | ---- | --- | -------------------------------- |
| title | string | Yes | Yes | Notification title. |
| text | string | Yes | Yes | Notification content. |
| additionalText | string | Yes | Yes | Additional information of the notification.|
| briefText | string | Yes | Yes | Brief text of the notification.|
| expandedTitle | string | Yes | Yes | Title of the notification in the expanded state. |
| picture | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Picture attached to the notification. |
## NotificationContent
Describes the notification content.
**System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description |
| ----------- | ------------------------------------------------------------ | ---- | --- | ------------------ |
| contentType | [ContentType](#contenttype) | Yes | Yes | Notification content type. |
| normal | [NotificationBasicContent](#notificationbasiccontent) | Yes | Yes | Normal text. |
| longText | [NotificationLongTextContent](#notificationlongtextcontent) | Yes | Yes | Long text.|
| multiLine | [NotificationMultiLineContent](#notificationmultilinecontent) | Yes | Yes | Multi-line text. |
| picture | [NotificationPictureContent](#notificationpicturecontent) | Yes | Yes | Picture-attached. |
## NotificationFlagStatus
Describes the notification flag status.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Value | Description |
| -------------- | --- | --------------------------------- |
| TYPE_NONE | 0 | The default flag is used. |
| TYPE_OPEN | 1 | The notification flag is enabled. |
| TYPE_CLOSE | 2 | The notification flag is disabled. |
## NotificationFlags
Enumerates notification flags.
**System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description |
| ---------------- | ---------------------- | ---- | ---- | --------------------------------- |
| soundEnabled | [NotificationFlagStatus](#notificationflagstatus) | Yes | No | Whether to enable the sound alert for the notification. |
| vibrationEnabled | [NotificationFlagStatus](#notificationflagstatus) | Yes | No | Whether to enable vibration for the notification. |
## NotificationRequest
Describes the notification request.
**System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description |
| --------------------- | --------------------------------------------- | ---- | --- | -------------------------- |
| content | [NotificationContent](#notificationcontent) | Yes | Yes | Notification content. |
| id | number | Yes | Yes | Notification ID. |
| slotType | [SlotType](#slottype) | Yes | Yes | Notification slot type. |
| isOngoing | boolean | Yes | Yes | Whether the notification is an ongoing notification. |
| isUnremovable | boolean | Yes | Yes | Whether the notification can be removed. |
| deliveryTime | number | Yes | Yes | Time when the notification is sent. |
| tapDismissed | boolean | Yes | Yes | Whether the notification is automatically cleared. |
| autoDeletedTime | number | Yes | Yes | Time when the notification is automatically cleared. |
| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** instance to which the notification will be redirected after being clicked.|
| extraInfo | {[key: string]: any} | Yes | Yes | Extended parameters. |
| color | number | Yes | Yes | Background color of the notification. Not supported currently.|
| colorEnabled | boolean | Yes | Yes | Whether the notification background color can be enabled. Not supported currently.|
| isAlertOnce | boolean | Yes | Yes | Whether the notification triggers an alert only once.|
| isStopwatch | boolean | Yes | Yes | Whether to display the stopwatch. |
| isCountDown | boolean | Yes | Yes | Whether to display the countdown time. |
| isFloatingIcon | boolean | Yes | Yes | Whether the notification is displayed as a floating icon in the status bar. |
| label | string | Yes | Yes | Notification label. |
| badgeIconStyle | number | Yes | Yes | Notification badge type. |
| showDeliveryTime | boolean | Yes | Yes | Whether to display the time when the notification is delivered. |
| actionButtons | Array\<[NotificationActionButton](#notificationactionbutton)\> | Yes | Yes | Buttons in the notification. Up to two buttons are allowed. |
| smallIcon | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Small notification icon. This field is optional, and the icon size cannot exceed 30 KB.|
| largeIcon | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Large notification icon. This field is optional, and the icon size cannot exceed 30 KB.|
| creatorBundleName | string | Yes | No | Name of the bundle that creates the notification. |
| creatorUid | number | Yes | No | UID used for creating the notification. |
| creatorPid | number | Yes | No | PID used for creating the notification. |
| creatorUserId| number | Yes | No | ID of the user who creates the notification. |
| hashCode | string | Yes | No | Unique ID of the notification. |
| classification | string | Yes | Yes | Notification category.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| groupName| string | Yes | Yes | Notification group name. |
| template | [NotificationTemplate](#notificationtemplate) | Yes | Yes | Notification template. |
| isRemoveAllowed | boolean | Yes | No | Whether the notification can be removed.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| source | number | Yes | No | Notification source.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| distributedOption | [DistributedOptions](#distributedoptions) | Yes | Yes | Distributed notification options. |
| deviceId | string | Yes | No | Device ID of the notification source.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| notificationFlags | [NotificationFlags](#notificationflags) | Yes | No | Notification flags. |
| removalWantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** instance to which the notification will be redirected when it is removed. |
| badgeNumber | number | Yes | Yes | Number of notifications displayed on the application icon. |
## DistributedOptions
Describes distributed options.
**System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description |
| ---------------------- | -------------- | ---- | ---- | ---------------------------------- |
| isDistributed | boolean | Yes | Yes | Whether the notification is a distributed notification. |
| supportDisplayDevices | Array\<string> | Yes | Yes | List of the devices to which the notification can be synchronized. |
| supportOperateDevices | Array\<string> | Yes | Yes | List of the devices on which the notification can be opened. |
| remindType | number | Yes | No | Notification reminder type.<br>**System API**: This is a system API and cannot be called by third-party applications. |
## NotificationSlot
Describes the notification slot.
**System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description |
| -------------------- | --------------------- | ---- | --- | ------------------------------------------ |
| type | [SlotType](#slottype) | Yes | Yes | Notification slot type. |
| level | number | Yes | Yes | Notification level. If this parameter is not set, the default value is used based on the notification slot type.|
| desc | string | Yes | Yes | Notification slot description. |
| badgeFlag | boolean | Yes | Yes | Whether to display the badge. |
| bypassDnd | boolean | Yes | Yes | Whether to bypass DND mode in the system. |
| lockscreenVisibility | number | Yes | Yes | Mode for displaying the notification on the lock screen. |
| vibrationEnabled | boolean | Yes | Yes | Whether vibration is enabled for the notification. |
| sound | string | Yes | Yes | Notification alert tone. |
| lightEnabled | boolean | Yes | Yes | Whether the indicator blinks for the notification. |
| lightColor | number | Yes | Yes | Indicator color of the notification. |
| vibrationValues | Array\<number\> | Yes | Yes | Vibration mode of the notification. |
| enabled<sup>9+</sup> | boolean | Yes | No | Whether the notification slot is enabled. |
## NotificationTemplate
Describes the notification template.
**System capability**: SystemCapability.Notification.Notification
| Name| Type | Readable| Writable| Description |
| ---- | ---------------------- | ---- | ---- | ---------- |
| name | string | Yes | Yes | Template name.|
| data | {[key:string]: Object} | Yes | Yes | Template data.|
## NotificationUserInput
Provides the notification user input.
**System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description |
| -------- | ------ | --- | ---- | ----------------------------- |
| inputKey | string | Yes | Yes | Key to identify the user input.|
## DeviceRemindType
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Value | Description |
| -------------------- | --- | --------------------------------- |
| IDLE_DONOT_REMIND | 0 | The device is not in use. No notification is required. |
| IDLE_REMIND | 1 | The device is not in use. |
| ACTIVE_DONOT_REMIND | 2 | The device is in use. No notification is required. |
| ACTIVE_REMIND | 3 | The device is in use. |
## SourceType
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Value | Description |
| -------------------- | --- | -------------------- |
| TYPE_NORMAL | 0 | Normal notification. |
| TYPE_CONTINUOUS | 1 | Continuous notification. |
| TYPE_TIMER | 2 | Timed notification. |
# @ohos.notificationSubscribe
The **NotificationSubscribe** module provides APIs for notification subscription, notification unsubscription, subscription removal, and more. In general cases, only system applications can call these APIs.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import NotificationSubscribe from '@ohos.notificationSubscribe';
```
## NotificationSubscribe.subscribe
subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\<void\>): void
Subscribes to a notification with the subscription information specified. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------- | ---- | ---------------- |
| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. |
| info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | Yes | Notification subscription information.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
// subscribe callback
function subscribeCallback(err) {
if (err) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribe success");
}
}
function onConsumeCallback(data) {
console.info("Consume callback: " + JSON.stringify(data));
}
var subscriber = {
onConsume: onConsumeCallback
}
var info = {
bundleNames: ["bundleName1","bundleName2"]
}
NotificationSubscribe.subscribe(subscriber, info, subscribeCallback);
```
## NotificationSubscribe.subscribe
subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>): void
Subscribes to notifications of all applications under this user. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ---------------------- | ---- | ---------------- |
| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
function subscribeCallback(err) {
if (err) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribe success");
}
}
function onConsumeCallback(data) {
console.info("Consume callback: " + JSON.stringify(data));
}
var subscriber = {
onConsume: onConsumeCallback
}
NotificationSubscribe.subscribe(subscriber, subscribeCallback);
```
## NotificationSubscribe.subscribe
subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo): Promise\<void\>
Subscribes to a notification with the subscription information specified. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------- | ---- | ------------ |
| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber.|
| info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | No | Notification subscription information. |
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
function onConsumeCallback(data) {
console.info("Consume callback: " + JSON.stringify(data));
}
var subscriber = {
onConsume: onConsumeCallback
};
NotificationSubscribe.subscribe(subscriber).then(() => {
console.info("subscribe success");
});
```
## NotificationSubscribe.unsubscribe
unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>): void
Unsubscribes from a notification. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ---------------------- | ---- | -------------------- |
| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
function unsubscribeCallback(err) {
if (err) {
console.info("unsubscribe failed " + JSON.stringify(err));
} else {
console.info("unsubscribe success");
}
}
function onDisconnectCallback(data) {
console.info("Cancel callback: " + JSON.stringify(data));
}
var subscriber = {
onDisconnect: onDisconnectCallback
}
NotificationSubscribe.unsubscribe(subscriber, unsubscribeCallback);
```
## NotificationSubscribe.unsubscribe
unsubscribe(subscriber: NotificationSubscriber): Promise\<void\>
Unsubscribes from a notification. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ---------------------- | ---- | ------------ |
| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
function onDisconnectCallback(data) {
console.info("Cancel callback: " + JSON.stringify(data));
}
var subscriber = {
onDisconnect: onDisconnectCallback
};
NotificationSubscribe.unsubscribe(subscriber).then(() => {
console.info("unsubscribe success");
});
```
## NotificationSubscribe.remove
remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason, callback: AsyncCallback\<void\>): void
Removes a notification for a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| --------------- | ----------------------------------| ---- | -------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. |
| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600007 | The notification is not exist. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
function removeCallback(err) {
if (err) {
console.info("remove failed " + JSON.stringify(err));
} else {
console.info("remove success");
}
}
var bundle = {
bundle: "bundleName1",
}
var notificationKey = {
id: 0,
label: "label",
}
var reason = NotificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
NotificationSubscribe.remove(bundle, notificationKey, reason, removeCallback);
```
## NotificationSubscribe.remove
remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason): Promise\<void\>
Removes a notification for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| --------------- | --------------- | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.|
| notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. |
| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. |
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600007 | The notification is not exist. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
var bundle = {
bundle: "bundleName1",
}
var notificationKey = {
id: 0,
label: "label",
}
var reason = NotificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
NotificationSubscribe.remove(bundle, notificationKey, reason).then(() => {
console.info("remove success");
});
```
## NotificationSubscribe.remove
remove(hashCode: string, reason: RemoveReason, callback: AsyncCallback\<void\>): void
Removes a specified notification. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | -------------------- |
| hashCode | string | Yes | Unique notification ID. It is the **hashCode** in the [NotificationRequest](#notificationrequest) object of [SubscribeCallbackData](#subscribecallbackdata) of the [onConsume](#onconsume) callback.|
| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600007 | The notification is not exist. |
**Example**
```js
var hashCode = 'hashCode'
function removeCallback(err) {
if (err) {
console.info("remove failed " + JSON.stringify(err));
} else {
console.info("remove success");
}
}
var reason = NotificationSubscribe.RemoveReason.CANCEL_REASON_REMOVE;
NotificationSubscribe.remove(hashCode, reason, removeCallback);
```
## NotificationSubscribe.remove
remove(hashCode: string, reason: RemoveReason): Promise\<void\>
Removes a specified notification. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------- | ---- | ---------- |
| hashCode | string | Yes | Unique notification ID.|
| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. |
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600007 | The notification is not exist. |
**Example**
```js
var hashCode = 'hashCode'
var reason = NotificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
NotificationSubscribe.remove(hashCode, reason).then(() => {
console.info("remove success");
});
```
## NotificationSubscribe.removeAll
removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>): void
Removes all notifications for a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ---------------------------- |
| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
function removeAllCallback(err) {
if (err) {
console.info("removeAll failed " + JSON.stringify(err));
} else {
console.info("removeAll success");
}
}
var bundle = {
bundle: "bundleName1",
}
NotificationSubscribe.removeAll(bundle, removeAllCallback);
```
## NotificationSubscribe.removeAll
removeAll(callback: AsyncCallback\<void\>): void
Removes all notifications. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
**Example**
```js
function removeAllCallback(err) {
if (err) {
console.info("removeAll failed " + JSON.stringify(err));
} else {
console.info("removeAll success");
}
}
NotificationSubscribe.removeAll(removeAllCallback);
```
## NotificationSubscribe.removeAll
removeAll(bundle?: BundleOption): Promise\<void\>
Removes all notifications for a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- |
| bundle | [BundleOption](#bundleoption) | No | Bundle information of the application.|
**Error codes**
| ID| Error Message |
| -------- | ---------------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 17700001 | The specified bundle name was not found. |
**Example**
```js
// If no application is specified, notifications of all applications are deleted.
NotificationSubscribe.removeAll().then(() => {
console.info("removeAll success");
});
```
## NotificationSubscribe.removeAll
removeAll(userId: number, callback: AsyncCallback\<void>): void
Removes all notifications for a specified user. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- |
| userId | number | Yes | User ID.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600008 | The user is not exist. |
**Example**
```js
function removeAllCallback(err) {
if (err) {
console.info("removeAll failed " + JSON.stringify(err));
} else {
console.info("removeAll success");
}
}
var userId = 1
NotificationSubscribe.removeAll(userId, removeAllCallback);
```
## Notification.removeAll
removeAll(userId: number): Promise\<void>
Removes all notifications for a specified user. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.Notification
**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ------------ | ---- | ---------- |
| userId | number | Yes | User ID.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------------------- |
| 1600001 | Internal error. |
| 1600002 | Marshalling or unmarshalling error. |
| 1600003 | Failed to connect service. |
| 1600008 | The user is not exist. |
**Example**
```js
function removeAllCallback(err) {
if (err) {
console.info("removeAll failed " + JSON.stringify(err));
} else {
console.info("removeAll success");
}
}
var userId = 1
NotificationSubscribe.removeAll(userId, removeAllCallback);
```
## NotificationSubscriber
Provides callbacks for receiving or removing notifications and serves as the input parameter of [subscribe](#notificationsubscribe).
**System API**: This is a system API and cannot be called by third-party applications.
### onConsume
onConsume?: (data: [SubscribeCallbackData](#subscribecallbackdata)) => void
Callback for receiving notifications.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| ------------ | ------------------------ | ---- | -------------------------- |
| data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Information about the notification received.|
**Example**
```javascript
function subscribeCallback(err) {
if (err) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onConsumeCallback(data) {
console.info('===> onConsume in test');
let req = data.request;
console.info('===> onConsume callback req.id:' + req.id);
};
var subscriber = {
onConsume: onConsumeCallback
};
NotificationSubscribe.subscribe(subscriber, subscribeCallback);
```
### onCancel
onCancel?:(data: [SubscribeCallbackData](#subscribecallbackdata)) => void
Callback for canceling notifications.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| ------------ | ------------------------ | ---- | -------------------------- |
| data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Information about the notification to cancel.|
**Example**
```javascript
function subscribeCallback(err) {
if (err) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onCancelCallback(data) {
console.info('===> onCancel in test');
let req = data.request;
console.info('===> onCancel callback req.id:' + req.id);
}
var subscriber = {
onCancel: onCancelCallback
};
NotificationSubscribe.subscribe(subscriber, subscribeCallback);
```
### onUpdate
onUpdate?:(data: [NotificationSortingMap](#notificationsortingmap)) => void
Callback for notification sorting updates.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| ------------ | ------------------------ | ---- | -------------------------- |
| data | [NotificationSortingMap](#notificationsortingmap) | Yes| Latest notification sorting list.|
**Example**
```javascript
function subscribeCallback(err) {
if (err) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onUpdateCallback(map) {
console.info('===> onUpdateCallback map:' + JSON.stringify(map));
}
var subscriber = {
onUpdate: onUpdateCallback
};
NotificationSubscribe.subscribe(subscriber, subscribeCallback);
```
### onConnect
onConnect?:() => void
Callback for subscription.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Example**
```javascript
function subscribeCallback(err) {
if (err) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onConnectCallback() {
console.info('===> onConnect in test');
}
var subscriber = {
onConnect: onConnectCallback
};
NotificationSubscribe.subscribe(subscriber, subscribeCallback);
```
### onDisconnect
onDisconnect?:() => void
Callback for unsubscription.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Example**
```javascript
function subscribeCallback(err) {
if (err) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function unsubscribeCallback(err) {
if (err.code) {
console.info("unsubscribe failed " + JSON.stringify(err));
} else {
console.info("unsubscribeCallback");
}
};
function onConnectCallback() {
console.info('===> onConnect in test');
}
function onDisconnectCallback() {
console.info('===> onDisconnect in test');
}
var subscriber = {
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback
};
// The onConnect callback is invoked when subscription to the notification is complete.
NotificationSubscribe.subscribe(subscriber, subscribeCallback);
// The onDisconnect callback is invoked when unsubscription to the notification is complete.
NotificationSubscribe.unsubscribe(subscriber, unsubscribeCallback);
```
### onDestroy
onDestroy?:() => void
Callback for service disconnection.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Example**
```javascript
function subscribeCallback(err) {
if (err) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onDestroyCallback() {
console.info('===> onDestroy in test');
}
var subscriber = {
onDestroy: onDestroyCallback
};
NotificationSubscribe.subscribe(subscriber, subscribeCallback);
```
### onDoNotDisturbDateChange
onDoNotDisturbDateChange?:(mode: notification.[DoNotDisturbDate](js-apis-notificationManager.md#donotdisturbdate)) => void
Callback for DND time setting updates.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| ------------ | ------------------------ | ---- | -------------------------- |
| mode | notification.[DoNotDisturbDate](js-apis-notificationManager.md#DoNotDisturbDate) | Yes| DND time setting updates.|
**Example**
```javascript
function subscribeCallback(err) {
if (err) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onDoNotDisturbDateChangeCallback(mode) {
console.info('===> onDoNotDisturbDateChange:' + mode);
}
var subscriber = {
onDoNotDisturbDateChange: onDoNotDisturbDateChangeCallback
};
NotificationSubscribe.subscribe(subscriber, subscribeCallback);
```
### onEnabledNotificationChanged
onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](#enablednotificationcallbackdata)) => void
Listens for the notification enabled status changes. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| ------------ | ------------------------ | ---- | -------------------------- |
| callback | AsyncCallback\<[EnabledNotificationCallbackData](#enablednotificationcallbackdata)\> | Yes| Callback used to return the result.|
**Example**
```javascript
function subscribeCallback(err) {
if (err) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onEnabledNotificationChangedCallback(callbackData) {
console.info("bundle: ", callbackData.bundle);
console.info("uid: ", callbackData.uid);
console.info("enable: ", callbackData.enable);
};
var subscriber = {
onEnabledNotificationChanged: onEnabledNotificationChangedCallback
};
NotificationSubscribe.subscribe(subscriber, subscribeCallback);
```
## BundleOption
**System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description |
| ------ | ------ |---- | --- | ------ |
| bundle | string | Yes | Yes | Bundle information of the application.|
| uid | number | Yes | Yes | User ID.|
## NotificationKey
**System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description |
| ----- | ------ | ---- | --- | -------- |
| id | number | Yes | Yes | Notification ID. |
| label | string | Yes | Yes | Notification label.|
## SubscribeCallbackData
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Readable | Writable | Description |
| --------------- | ------------------------------------------------- | -------- | -------- | -------- |
| request | [NotificationRequest](js-apis-notificationManager.md#notificationrequest) | Yes| No| Notification content.|
| sortingMap | [NotificationSortingMap](#notificationsortingmap) | Yes| No| Notification sorting information.|
| reason | number | Yes | No | Reason for deletion.|
| sound | string | Yes | No | Sound used for notification.|
| vibrationValues | Array\<number\> | Yes | No | Vibration used for notification.|
## EnabledNotificationCallbackData
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Readable | Writable | Description |
| ------ | ------- | ---------------- | ---------------- | ---------------- |
| bundle | string | Yes| No| Bundle name of the application. |
| uid | number | Yes| No| UID of the application. |
| enable | boolean | Yes| No| Notification enabled status of the application.|
## NotificationSorting
Provides sorting information of activity notifications.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Readable| Writable| Description |
| -------- | ------------------------------------- | ---- | --- | ------------ |
| slot | [NotificationSlot](js-apis-notificationManager.md#notificationslot) | Yes | No | Notification slot.|
| hashCode | string | Yes | No | Unique ID of the notification.|
| ranking | number | Yes | No | Notification sequence number.|
## NotificationSortingMap
Provides sorting information of active notifications in all subscribed notifications.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Readable| Writable| Description |
| -------------- | ------------------------------------------------------------ | ---- | --- | ---------------- |
| sortings | {[key: string]: [NotificationSorting](#notificationsorting)} | Yes | No | Array of notification sorting information.|
| sortedHashCode | Array\<string\> | Yes | No | Array of unique notification IDs.|
## NotificationSubscribeInfo
Provides the information about the publisher for notification subscription.
**System capability**: SystemCapability.Notification.Notification
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Readable| Writable| Description |
| ----------- | --------------- | --- | ---- | ------------------------------- |
| bundleNames | Array\<string\> | Yes | Yes | Bundle names of the applications whose notifications are to be subscribed to.|
| userId | number | Yes | Yes | User whose notifications are to be subscribed to. |
## NotificationUserInput
Provides the notification user input.
**System capability**: SystemCapability.Notification.Notification
| Name | Type | Readable| Writable| Description |
| -------- | ------ | --- | ---- | ----------------------------- |
| inputKey | string | Yes | Yes | Key to identify the user input.|
## RemoveReason
**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 after 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.
先完成此消息的编辑!
想要评论请 注册