openharmony 鸿蒙 js-apis-inner-notification-notificationRequest

2025-06-12 浏览 (1)

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

NameTypeRead OnlyOptionalDescription
contentNotificationContentNoNoNotification content.
idnumberNoYesNotification ID. The default value is 0. If the same notification ID exists, the notification content is updated.
slotType(deprecated)notification.SlotTypeNoYesNotification slot type.
This API is deprecated since API version 11. You are advised to use notificationSlotType instead.
notificationSlotType11+notificationManager.SlotTypeNoYesNotification slot type. The default value is OTHER_TYPES.
isOngoingbooleanNoYesNot supported currently.
isUnremovablebooleanNoYesNot supported currently.
updateOnly18+booleanNoYesWhether 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.
deliveryTimenumberNoYesTime when the notification is sent. This API is automatically generated by the system.
Data format: timestamp,
in milliseconds.
tapDismissedbooleanNoYesWhether 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.
autoDeletedTimenumberNoYesTime 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.
wantAgentWantAgentNoYesWantAgent instance to which the notification will be redirected after being clicked.
extraInfo{[key: string]: any}NoYesExtended parameters.
colornumberNoYesBackground color of the notification. Not supported currently.
colorEnabledbooleanNoYesWhether the notification background color can be enabled. Not supported currently.
isAlertOncebooleanNoYesWhether 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.
isStopwatchbooleanNoYesWhether to display the stopwatch. Not supported currently.
isCountDownbooleanNoYesWhether to display the countdown time. Not supported currently.
isFloatingIconbooleanNoYesWhether the notification is displayed as a floating icon in the status bar. Not supported currently.
labelstringNoYesNotification 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.
badgeIconStylenumberNoYesNotification badge type. Not supported currently.
showDeliveryTimebooleanNoYesWhether to display the time when the notification is delivered. Not supported currently.
actionButtonsArray<NotificationActionButton>NoYesNotification 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.
smallIconimage.PixelMapNoYesSmall 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.
largeIconimage.PixelMapNoYesLarge 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.
creatorBundleNamestringYesYesName of the bundle that creates the notification.
creatorUidnumberYesYesUID used for creating the notification.
creatorPidnumberYesYesPID used for creating the notification.
creatorUserId8+numberYesYesID of the user who creates the notification.
hashCodestringYesYesUnique ID of the notification.
groupName8+stringNoYesNotification group name. This parameter is left blank by default.
template8+NotificationTemplateNoYesNotification template.
distributedOption8+DistributedOptionsNoYesDistributed notification options. Not supported currently.
notificationFlags8+NotificationFlagsYesYesNotification flags.
removalWantAgent9+WantAgentNoYesWantAgent 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+numberNoYesAccumulative 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+stringNoYesUnique 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+stringNoYesName 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

NameTypeRead OnlyOptionalDescription
isDistributedbooleanNoYesWhether the notification is a distributed notification.
supportDisplayDevicesArray<string>NoYesList of the devices to which the notification can be synchronized.
supportOperateDevicesArray<string>NoYesList 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)

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/nf0CQB