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,7 +26,7 @@ Publishes a notification. This API uses an asynchronous callback to return the r
...
@@ -26,7 +26,7 @@ Publishes a notification. This API uses an asynchronous callback to return the r
| 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
| 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.|
| 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.<br>**true**: The device supports distributed notifications.<br>**false**: The device does not support distributed notifications.|
| 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.|
| 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.|
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.
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.
| 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.|
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.
| 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.|
| 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. |
| 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 | [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. |
| 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. |
| 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. |
| 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. |
| 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. |
| 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.|
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.
| 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. |
| 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\<Array\<[NotificationSlot](#notificationslot)\>\> | Yes | Callback used to return all notification slots of the current application.|
| 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. |
| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| 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.|
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.
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.
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.
| 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.|
| 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. |
| 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. |
| 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. |
| 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. |
| 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. |
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.
| 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.|