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

2025-06-12 浏览 (1)

NotificationContent

The NotificationContent module provides APIs for defining the notification content.

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.

NotificationContent

Describes the notification contents.

System capability: SystemCapability.Notification.Notification

NameTypeRead OnlyOptionalDescription
contentType(deprecated)notification.ContentTypeNoYesNotification content type.
This API is deprecated since API version 11. You are advised to use notificationContentType instead.
notificationContentType11+notificationManager.ContentTypeNoYesNotification content type.
normalNotificationBasicContentNoYesNormal text.
longTextNotificationLongTextContentNoYesLong text.
multiLineNotificationMultiLineContentNoYesMulti-line text.
pictureNotificationPictureContentNoYesPicture-attached.
systemLiveView11+NotificationSystemLiveViewContentNoYesSystem live view. A third-party application cannot directly create a notification of this type. After the system proxy creates a system live view, the third-party application releases a notification with the same ID to update the specified content.

NotificationBasicContent

Describes the normal text notification.

System capability: SystemCapability.Notification.Notification

NameTypeRead OnlyOptionalDescription
titlestringNoNoNotification title. It cannot be empty or exceed 1024 bytes. Excess content will be truncated.
textstringNoNoNotification content. It cannot be empty or exceed 3072 bytes. Excess content will be truncated.
additionalTextstringNoYesAdditional information of the notification. It cannot exceed 3072 bytes. Excess content will be truncated.
lockscreenPicture12+image.PixelMapNoYesPicture of a notification displayed on the lock screen. Currently, only the live view notification is supported. 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.

NotificationLongTextContent

Describes the long text notification. This API is inherited from NotificationBasicContent.

NOTE

The display effect depends on the device capability and notification center UI style.

System capability: SystemCapability.Notification.Notification

NameTypeRead OnlyOptionalDescription
longTextstringNoNoLong text of the notification. It cannot be an empty string and exceed 3072 bytes. Excess content will be truncated.
briefTextstringNoNoBrief text of the notification. It cannot be empty or exceed 1024 bytes. Excess content will be truncated.
expandedTitlestringNoNoTitle of the notification in the expanded state. It cannot be empty or exceed 1024 bytes. Excess content will be truncated.

NotificationMultiLineContent

Describes the multi-line text notification. This API is inherited from NotificationBasicContent.

NOTE

  • When the multi-line text notification and another notification form a group notification, the group notification is displayed as a normal text notification by default. After the group notification is expanded, the value of longTitle is used as the title, and the value of lines is used as the multi-line text content.
    When the multi-line text notification is displayed independently, the value of longTitle is used as the title, and the value of lines is used as the multi-line text content.

  • The display effect depends on the device capability and notification center UI style.

System capability: SystemCapability.Notification.Notification

NameTypeRead OnlyOptionalDescription
briefTextstringNoNoBrief text of the notification. It cannot be empty or exceed 1024 bytes. Excess content will be truncated.
longTitlestringNoNoTitle of the notification in the expanded state. It cannot be empty or exceed 1024 bytes. Excess content will be truncated.
linesArray<string>NoNoMulti-line text of a notification. A maximum of three lines are supported, and each line cannot exceed 1024 bytes. Excess content will be truncated.

NotificationPictureContent

Describes the picture-attached notification. This API is inherited from NotificationBasicContent.

NOTE

The display effect depends on the device capability and notification center UI style.

System capability: SystemCapability.Notification.Notification

NameTypeRead OnlyOptionalDescription
briefTextstringNoNoBrief text of the notification. It cannot be empty or exceed 1024 bytes. Excess content will be truncated.
expandedTitlestringNoNoTitle of the notification in the expanded state. It cannot be empty or exceed 1024 bytes. Excess content will be truncated.
pictureimage.PixelMapNoNoPicture content of the notification. The total number of bytes of image pixels cannot exceed 2 MB.

NotificationSystemLiveViewContent

Describes the system live view notification. A third-party application cannot directly create a notification of this type. After the system proxy creates a system live view, the third-party application releases a notification with the same ID to update the specified content. This API is inherited from NotificationBasicContent.

System capability: SystemCapability.Notification.Notification

NameTypeRead OnlyOptionalDescription
typeCode11+numberNoNoType code, which identifies the type of the service that invokes the API.
capsule11+NotificationCapsuleNoYesCapsule of the notification.
button11+NotificationButtonNoYesButton in the notification.
time11+NotificationTimeNoYesTime of the notification.
progress11+NotificationProgressNoYesProgress of the notification.

NotificationCapsule11+

Describe the notification capsule.

System capability: SystemCapability.Notification.Notification

NameTypeRead OnlyOptionalDescription
titlestringNoYesTitle of the capsule.
iconimage.PixelMapNoYesIcon of the capsule.
backgroundColorstringNoYesBackground color of the capsule.

NotificationButton11+

Describes the notification button.

System capability: SystemCapability.Notification.Notification

NameTypeRead OnlyOptionalDescription
namesArray<string>NoYesButton names. A maximum of three names are supported.
iconsArray<image.PixelMap>NoYesButton icons. A maximum of three icons are supported.
iconsResource12+Array<Resource>NoYesButton icon resources. A maximum of three icon resources are supported.

NotificationTime11+

Describes the notification timing information.

System capability: SystemCapability.Notification.Notification

NameTypeRead OnlyOptionalDescription
initialTimenumberNoYesStart time, in milliseconds.
isCountDownbooleanNoYesWhether to count down. The default value is false.
- true: Yes.
- false: No.
isPausedbooleanNoYesWhether to pause the progress. The default value is false.
- true: Yes.
- false: No.
isInTitlebooleanNoYesWhether the time is displayed in the title. The default value is false.
- true: Yes.
- false: No.

Example:

// The notification counts down from three seconds and the time is displayed in the title.
time: {
    initialTime: 3000,
    isCountDown: true,
    isPaused: false,
    isInTitle: true,
}

NotificationProgress11+

Describes the notification progress.

System capability: SystemCapability.Notification.Notification

NameTypeRead OnlyOptionalDescription
maxValuenumberNoYesMaximum progress value.
currentValuenumberNoYesCurrent progress value.
isPercentagebooleanNoYesWhether to show the progress in percentage. The default value is false.
- true: Yes.
- false: No.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Notification Kit (User Notification Service)

harmony 鸿蒙Notification

harmony 鸿蒙Notification Error Codes

harmony 鸿蒙NotificationActionButton

harmony 鸿蒙NotificationCommonDef

harmony 鸿蒙NotificationContent (System API)

harmony 鸿蒙NotificationFlags (System API)

harmony 鸿蒙NotificationFlags

harmony 鸿蒙NotificationRequest (System API)

harmony 鸿蒙NotificationRequest

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