Before publishing a notification, check whether the notification feature is enabled for the respective application. By default, the feature is disabled for newly installed apps.
Before publishing a notification, make sure the notification feature is enabled for your application. This feature is disabled by default and can be enabled in the notification settings.
The following sample is provided to help you better understand how to develop notification functions:
- notification
This sample shows how to use **Notification** APIs in Extended TypeScript (eTS) to subscribe to, unsubscribe from, publish, and cancel notifications as well as enable the notification feature and check whether the feature is enabled.
> 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.
| type | Readable and writable| SlotType | Yes| Notification slot type.|
| level | Readable and writable| number | No| Notification level. If this parameter is not set, the default value is used based on the notification slot type.|
| desc | Readable and writable| string | No| Description of the notification slot.|
| badgeFlag | Readable and writable| boolean | No| Whether to display the badge.|
| bypassDnd | Readable and writable| boolean | No| Whether to bypass the system do-not-disturb (DND) setting.|
| lockscreenVisibility | Readable and writable| boolean | No| How the notification is displayed on the locked screen.|
| vibrationEnabled | Readable and writable| boolean | No| Whether vibration is enabled for the notification.|
| slotType | Read-only| slotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| callback | Read-only| AsyncCallback\<NotificationSlot\> | Yes| Callback used to return the result.|
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| slotType | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| callback | Yes | No | AsyncCallback\<[NotificationSlot](#notificationslot)\> | Yes | Callback used to return the result. |
| slotType | Read-only| slotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| slotType | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| SlotType | Read-only| SlotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| callback | Read-only| AsyncCallback\<void\> | Yes| Callback used to return the result.|
- Return value
**Parameters**
void
| Name | Readable| Writable| Type | Mandatory| Description |
| slotType | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result. |
| SlotType | Read-only| SlotType | Yes| Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
- Return value
| Name | Readable| Writable| Type | Mandatory| Description |
| slotType | Yes | No | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.|
| 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.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
| info | Read-only| WantAgentInfo | Yes| Information about the **WantAgent** object to obtain.|
| 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.<br>**true**: The device supports distributed notifications.<br>**false**: The device does not support distributed notifications.|
| LEVEL_NONE | 0 | The notification feature is disabled. |
| LEVEL_MIN | 1 | The notification feature is enabled, but the notification icon is not displayed in the status bar, with no banner or alert tone.|
| LEVEL_LOW | 2 | The notification feature is enabled, and the notification icon is displayed in the status bar, with no banner or alert tone.|
| LEVEL_DEFAULT | 3 | The notification feature is enabled, and the notification icon is displayed in the status bar, with an alert tone but no banner.|
| LEVEL_HIGH | 4 | The notification feature is enabled, and the notification icon is displayed in the status bar, with an alert tone and banner.|
| badgeIconStyle | Yes | Yes | number | No | Notification badge type. |
| showDeliveryTime | Yes | Yes | boolean | No | Whether to display the time when the notification is delivered. |
| actionButtons | Yes | Yes | Array\<[NotificationActionButton](#notificationactionbutton)\> | No | Buttons in the notification. Up to two buttons are allowed. |
| smallIcon | Yes | Yes | PixelMap | No | Small notification icon. |
| largeIcon | Yes | Yes | PixelMap | No | Large notification icon. |
| creatorBundleName | Yes | No | string | No | Name of the bundle that creates the notification. |
| creatorUid | Yes | No | number | No | UID used for creating the notification. |
| creatorPid | Yes | No | number | No | PID used for creating the notification. |
| creatorUserId<sup>8+</sup>| Yes | No | number | No | ID of the user who creates a notification. |
| hashCode | Yes | No | string | No | Unique ID of the notification. |