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

Name Type Read-Only Optional Description
contentType(deprecated) notification.ContentType No Yes Notification content type.
This attribute is supported since API version 7 and deprecated since API version 11. You are advised to use notificationContentType instead.
notificationContentType11+ notificationManager.ContentType No Yes Notification content type.
normal NotificationBasicContent No Yes Normal text.
longText NotificationLongTextContent No Yes Long text.
multiLine NotificationMultiLineContent No Yes Multi-line text.
picture NotificationPictureContent No Yes Picture-attached.
systemLiveView11+ NotificationSystemLiveViewContent No Yes System 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

Name Type Read-Only Optional Description
title string No No Notification title. It cannot be empty or exceed 1,024 bytes. Excess content will be truncated.
text string No No Notification content. It cannot be empty or exceed 3,072 bytes. Excess content will be truncated.
additionalText string No Yes Additional information of the notification. It cannot exceed 3,072 bytes. Excess content will be truncated. This parameter is left empty by default.
lockscreenPicture12+ image.PixelMap No Yes Picture displayed on the lock screen. This parameter is left empty by default. 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

Name Type Read-Only Optional Description
longText string No No Long text of the notification. It cannot be empty or exceed 3,072 bytes. Excess content will be truncated.
briefText string No No Brief text of the notification. It cannot be empty or exceed 1,024 bytes. Excess content will be truncated.
expandedTitle string No No Title of the notification in the expanded state. It cannot be empty or exceed 1,024 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

Name Type Read-Only Optional Description
briefText string No No Brief text of the notification. It cannot be empty or exceed 1,024 bytes. Excess content will be truncated.
longTitle string No No Title of the notification in the expanded state. It cannot be empty or exceed 1,024 bytes. Excess content will be truncated.
lines Array<string> No No Multi-line text of a notification. A maximum of three lines are supported, and each line cannot exceed 1,024 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

Name Type Read-Only Optional Description
briefText string No No Brief text of the notification. It cannot be empty or exceed 1,024 bytes. Excess content will be truncated.
expandedTitle string No No Title of the notification in the expanded state. It cannot be empty or exceed 1,024 bytes. Excess content will be truncated.
picture image.PixelMap No No Picture content of the notification. The total pixel data size of the image 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

Name Type Read-Only Optional Description
typeCode11+ number No No Type code, which identifies the type of the service that invokes the API.
capsule11+ NotificationCapsule No Yes Capsule of the notification. This parameter is left empty by default.
button11+ NotificationButton No Yes Button in the notification. This parameter is left empty by default.
time11+ NotificationTime No Yes Time of the notification. This parameter is left empty by default.
progress11+ NotificationProgress No Yes Progress of the notification. This parameter is left empty by default.

NotificationCapsule11+

Describe the notification capsule.

System capability: SystemCapability.Notification.Notification

Name Type Read-Only Optional Description
title string No Yes Title of the capsule, with a maximum of 200 bytes. Excess part will be truncated.
icon image.PixelMap No Yes Icon of the capsule. 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.
backgroundColor string No Yes Background color of the capsule.

NotificationButton11+

Describes the notification button.

System capability: SystemCapability.Notification.Notification

Name Type Read-Only Optional Description
names Array<string> No Yes Button names. A maximum of three names are supported.
icons Array<image.PixelMap> No Yes Button icons. A maximum of three icons are 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.
iconsResource12+ Array<Resource> No Yes Button icon resources. A maximum of three icon resources are supported.

NotificationTime11+

Describes the notification timing information.

System capability: SystemCapability.Notification.Notification

Name Type Read-Only Optional Description
initialTime number No Yes Start time, in milliseconds.
isCountDown boolean No Yes Whether to count down. The default value is false.
- true: Yes.
- false: No.
isPaused boolean No Yes Whether to pause the progress. The default value is false.
- true: Yes.
- false: No.
isInTitle boolean No Yes Whether 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

Name Type Read-Only Optional Description
maxValue number No Yes Maximum progress value.
currentValue number No Yes Current progress value.
isPercentage boolean No Yes Whether to show the progress in percentage. The default value is false.
- true: Yes.
- false: No.