harmony 鸿蒙NotificationRequest

  • 2025-06-12
  • 浏览 (4)

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 the same notification ID exists, the notification content is updated.
slotType(deprecated) notification.SlotType No Yes Notification slot type.
This API is deprecated since API version 11. You are advised to use notificationSlotType instead.
notificationSlotType11+ notificationManager.SlotType No Yes Notification slot type. The default value is OTHER_TYPES.
isOngoing boolean No Yes Not supported currently.
isUnremovable boolean No Yes Not supported currently.
updateOnly18+ boolean No Yes Whether to update notifications only.
- true: If a notification with the same ID exists, the notification is updated; otherwise, the notification fails to update and no notification is created.
- false (default): If a notification with the same ID exists, the notification is updated; otherwise, a notification is created.
deliveryTime number No Yes Time when the notification is sent. This API is automatically generated by the system.
Data format: timestamp,
in milliseconds.
tapDismissed boolean No Yes Whether the notification is automatically cleared. This parameter is valid only when the notification carries wantAgent or actionButtons.
- true (default): 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 Time when the notification is automatically cleared.
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.
wantAgent WantAgent No Yes WantAgent instance to which the notification will be redirected after being clicked.
extraInfo {[key: string]: any} No Yes Extended parameters.
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.
isAlertOnce boolean No Yes Whether to send a notification only once when the notification is published or updated.
- 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_MIN.
- false (default): A notification is sent based on the configured notification mode.
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.
label string No Yes Notification label.
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.
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.
actionButtons Array<NotificationActionButton> No Yes Notification button. A notification can contain a maximum of two buttons by default. Since API version 16, this capability is supported on the wearables. A notification can contain a maximum of three buttons for the wearables.
smallIcon image.PixelMap No Yes Small notification icon. Optional field. The total number of the icon pixel bytes cannot exceed 192 KB (which is obtained through getPixelBytesNumber. The recommended icon size is 128 px × 128 px. The display effect depends on the device capability and notification center UI style.
largeIcon image.PixelMap No Yes Large notification icon. Optional field. The total number of the icon pixel bytes cannot exceed 192 KB (which is obtained through getPixelBytesNumber. The recommended icon size is 128 px × 128 px. The display effect depends on the device capability and notification center UI style.
creatorBundleName string Yes Yes Name of the bundle that creates the notification.
creatorUid number Yes Yes UID used for creating the notification.
creatorPid number Yes Yes PID used for creating the notification.
creatorUserId8+ number Yes Yes ID of the user who creates the notification.
hashCode string Yes Yes Unique ID of the notification.
groupName8+ string No Yes Notification group name. This parameter is left blank by default.
template8+ NotificationTemplate No Yes Notification template.
distributedOption8+ DistributedOptions No Yes Distributed notification options. Not supported currently.
notificationFlags8+ NotificationFlags Yes Yes Notification flags.
removalWantAgent9+ WantAgent No Yes WantAgent instance to which the notification will be redirected when it is removed.
Currently, redirection to UIAbility is not supported. Only common events can be published (that is, actionType is set to 4).
badgeNumber9+ number No Yes Accumulative number of notifications displayed on the application icon.
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.
appMessageId12+ string No Yes Unique ID carried in a notification sent by an app, which is used for notification deduplication. If an app 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.
sound12+ string No Yes Name of the custom ringtone file for application notifications. This file must be stored in the resources/rawfile directory and supports formats such as M4A, AAC, MP3, OGG, WAV, FLAC, and AMR. This field takes effect only after the system application with the ohos.permission.NOTIFICATION_AGENT_CONTROLLER permission calls the notificationManager.setAdditionalConfig API to set additional configuration.

DistributedOptions8+

Describes distributed notification options. Not supported currently.

System capability: SystemCapability.Notification.Notification

Name Type Read Only Optional Description
isDistributed boolean No Yes Whether the notification is a distributed notification.
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.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Notification Kit (User Notification Service)

harmony 鸿蒙Notification

harmony 鸿蒙Notification Error Codes

harmony 鸿蒙NotificationActionButton

harmony 鸿蒙NotificationCommonDef

harmony 鸿蒙NotificationContent (System API)

harmony 鸿蒙NotificationContent

harmony 鸿蒙NotificationFlags (System API)

harmony 鸿蒙NotificationFlags

harmony 鸿蒙NotificationRequest (System API)

0  赞