NotificationRequest

The NotificationRequest module provides APIs for defining the notification request.

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.

NotificationRequest

System capability: SystemCapability.Notification.Notification

Name Type Read Only Optional Description
content NotificationContent No No Notification content.
id number No Yes Notification ID. The default value is 0. If a notification with the same ID exists, the notification is updated. If no notification with the same ID exists, a new notification is created.
updateOnly18+ boolean No Yes Whether to update notifications only. The default value is false.
- true: If a notification with the same ID exists, the notification is updated. If no notification with the same ID exists, the update fails and no new notification is created.
- false: If a notification with the same ID exists, the notification is updated. If no notification with the same ID exists, a new notification is created.
appMessageId12+ string No Yes Unique ID carried in a notification sent by an application, which is used for notification deduplication. If an application publishes notifications with the same appMessageId locally or on the cloud, the device displays only one message. Repeated notifications received later will be silenced and deduplicated, and will not be displayed or notified. The deduplication flag is valid only within 24 hours after the notification is published. After 24 hours or the device is restarted, the deduplication flag becomes invalid.
notificationSlotType11+ notificationManager.SlotType No Yes Notification slot type. The default value is OTHER_TYPES. The notification reminder mode varies depending on the notification slot type.
notificationFlags8+ NotificationFlags No Yes Notification flags to be set or obtained. This parameter is left empty by default. This parameter is writable since API version 23. You can set this parameter to reduce the notification modes. When the notification channel type is LIVE_VIEW, this parameter does not take effect.
priorityNotificationType23+ notificationManager.PriorityNotificationType No Yes Notification priority type. The default value is OTHER. If this parameter is set, the notification is pinned on the top and displayed in a highlighted manner in the notification center. The actual display effect depends on the device capability and notification center UI style.
Model restriction: This API can be used only in the stage model.
isAlertOnce boolean No Yes Whether to send a notification only once when the notification is published or updated. The default value is false.
- true: A notification is sent only when the notification is published for the first time. For subsequent update, the notification mode is changed to LEVEL_LOW.
- false: A notification is sent based on the configured notification mode.
sound12+ string No Yes Path of the custom application notification ringtone resource. By default, this parameter is left empty. The following two types of audio resources are supported:
- Resource file: Audio file preconfigured in the application. It must be stored in the resources/rawfile directory. To use the resource file, directly pass the file name.
- Sandbox file: Audio file downloaded from the network or generated by the user. It must be stored in the files directory or its subdirectory in the EL1 area of the sandbox file directory. The input format is uri::{fileUri}, where fileUri is the path obtained through getUriFromPath. For example, if an application transfers the downloaded audio resource demo.mp3 to the sandbox file directory /data/storage/el1/base/files/, the path obtained through getUriFromPath is file://{bundleName}/data/storage/el1/base/files/demo.mp3. You can use this path to release a notification to play the audio resource downloaded by the application.
Supported formats: M4A, AAC, MP3, OGG, WAV, FLAC, and AMR.
badgeNumber9+ number No Yes Number of notifications displayed on the application icon. The value is accumulated. The default value is 0.
If the value of badgeNumber is less than or equal to 0, the badge number is not displayed;
if the value is greater than 99, 99+ is displayed on the badge.
For example, if an application publishes three notifications, and badgeNumber is set to 2, 0, and 3 in sequence, the application displays 2, 2, and 5 accordingly.
wantAgent WantAgent No Yes Behavior intent of an application, which is triggered when a notification is clicked. This parameter is left empty by default.
actionButtons Array<NotificationActionButton> No Yes Notification button. This parameter is left empty by default. A notification can contain a maximum of two buttons. Since API version 16, a notification can contain a maximum of three buttons for wearables.
removalWantAgent9+ WantAgent No Yes Behavior intent of an application, which is triggered when a notification is removed. This parameter is left empty by default.
Currently, redirection to UIAbility is not supported. Only common events can be published (that is, the actionType field of WantAgentInfo is set to 4).
tapDismissed boolean No Yes Whether the notification is automatically cleared when the notification carries wantAgent or actionButtons. This parameter is valid only when the notification carries wantAgent or actionButtons. The default value is true.
- true: The current notification is automatically cleared after the notification or button is tapped.
- false: The current notification is retained after the notification or button is tapped.
autoDeletedTime number No Yes Scheduled time for clearing a notification. If this parameter is set, the notification will be automatically cleared after the specified time. The default value is 0.
Data format: timestamp,
in milliseconds.
For example, if a notification is to be cleared after being displayed for 3 seconds (3000 ms), you can set new Date().getTime() + 3000 to meet this requirement.
deliveryTime number No Yes Time when the notification is sent. This API is automatically generated by the system.
Data format: timestamp,
in milliseconds.
label string No Yes Notification label. This parameter is left empty by default.
The label field can be used independently, or used together with ID as a notification identifier. ID is preferentially used.
If the label is not empty when a notification is published, you need to specify the label when updating or deleting the notification.
smallIcon image.PixelMap No Yes Small notification icon. This parameter is left empty by default. The total number of the icon pixel bytes cannot exceed 192 KB (which is obtained through getPixelBytesNumber). The recommended icon size is 128 × 128 pixels. The display effect depends on the device capability and notification center UI style.
largeIcon image.PixelMap No Yes Large notification icon. This parameter is left empty by default. The total number of the icon pixel bytes cannot exceed 192 KB (which is obtained through getPixelBytesNumber). The recommended icon size is 128 × 128 pixels. The display effect depends on the device capability and notification center UI style.
overlayIcon23+ image.PixelMap No Yes Notification overlay icon. This parameter is left empty by default. The total number of the icon pixel bytes cannot exceed 192 KB (which is obtained through getPixelBytesNumber).
This API takes effect only when notificationSlotType is set to SOCIAL_COMMUNICATION. The recommended icon size is 128 × 128 pixels. The display effect depends on the device capability and notification center UI style.
groupName8+ string No Yes Group to which a notification belongs. If the group names of different notifications are the same, these notifications are displayed in a group. This parameter is left blank by default.
template8+ NotificationTemplate No Yes Notification template. This parameter is left empty by default.
extraInfo {[key: string]: any} No Yes Extended parameters, used to provide custom services for applications. This parameter is left blank by default.
The key value is assigned by the system. Manual modification does not take effect. The system automatically changes the value to the actual value during data transmission.
- ohos.notificationManager.wantUri: uri field in the Want object, which is passed to the application when the user taps a notification. This field can be obtained via the getActiveNotifications API call.
slotType(deprecated) notification.SlotType No Yes Notification slot type. The default value is OTHER_TYPES.
This attribute is supported since API version 7 and deprecated since API version 11. You are advised to use notificationSlotType instead.
hashCode string Yes Yes Unique ID of the notification.
creatorBundleName string Yes Yes Name of the application that creates the notification.
creatorUid number Yes Yes UID of the application that creates the notification.
creatorPid number Yes Yes PID used for creating the notification.
creatorUserId8+ number Yes Yes ID of the user who creates the notification.
isOngoing boolean No Yes Not supported currently.
isUnremovable boolean No Yes Not supported currently.
color number No Yes Background color of the notification. Not supported currently.
colorEnabled boolean No Yes Whether the notification background color can be enabled. Not supported currently.
isStopwatch boolean No Yes Whether to display the stopwatch. Not supported currently.
isCountDown boolean No Yes Whether to display the countdown time. Not supported currently.
isFloatingIcon boolean No Yes Whether the notification is displayed as a floating icon in the status bar. Not supported currently.
distributedOption8+ DistributedOptions No Yes Distributed notification options. Not supported currently.
badgeIconStyle number No Yes Notification badge type. Not supported currently.
showDeliveryTime boolean No Yes Whether to display the time when the notification is delivered. Not supported currently.

DistributedOptions8+

Describes options for cross-device notifications. Not supported currently.

System capability: SystemCapability.Notification.Notification

Name Type Read Only Optional Description
isDistributed boolean No Yes Whether cross-device notifications are supported. The default value is true.
- true: cross-device notifications are supported.
- false: cross-device notifications are not supported.
supportDisplayDevices Array<string> No Yes List of the devices to which the notification can be synchronized.
supportOperateDevices Array<string> No Yes List of the devices on which the notification can be opened.

NotificationParameters24+

Describes part of the wantAgent information about in NotificationRequest.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Notification.Notification

Name Type Read Only Optional Description
wantAction string No Yes action field passed in want when wantAgent is created. For details, see action.
wantUri string No Yes uri field passed in want when wantAgent is created. For details, see uri.
wantParameters Record<string, Object> No Yes parameters field passed in want when wantAgent is created. For details, see parameters.