The Notification module provides notification management capabilities, covering notifications, notification slots, notification subscription, notification enabled status, and notification badge status.
Since API version 9, this module is no longer maintained. It is recommended that you use @ohos.notificationManager instead.
The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with the superscript to indicate their earliest API version.
Notification subscription and unsubscription are open only to system applications.
publish(request: NotificationRequest, callback: AsyncCallback<void>): void
Publishes a notification. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| request | NotificationRequest | Yes | Content and related configuration of the notification to publish. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Example
import NotificationManager from '@ohos.notificationManager';
import Base from '@ohos.base';
// publish callback
let publishCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`publish failed, code is ${err}`);
} else {
console.info("publish success");
}
}
// NotificationRequest object
let notificationRequest: NotificationManager.NotificationRequest = {
id: 1,
content: {
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
title: "test_title",
text: "test_text",
additionalText: "test_additionalText"
}
}
};
Notification.publish(notificationRequest, publishCallback); publish(request: NotificationRequest): Promise<void>
Publishes a notification. This API uses a promise to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| request | NotificationRequest | Yes | Content and related configuration of the notification to publish. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import NotificationManager from '@ohos.notificationManager';
import Base from '@ohos.base';
// NotificationRequest object
let notificationRequest: NotificationManager.NotificationRequest = {
id: 1,
content: {
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
title: "test_title",
text: "test_text",
additionalText: "test_additionalText"
}
}
};
Notification.publish(notificationRequest).then(() => {
console.info("publish success");
}).catch((err: Base.BusinessError) => {
console.error(`publish failed, code is ${err}`);
}); cancel(id: number, label: string, callback: AsyncCallback<void>): void
Cancels a notification with the specified ID and label. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| id | number | Yes | Notification ID. |
| label | string | Yes | Notification label. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Example
import Base from '@ohos.base';
// cancel callback
let cancelCallback = (err: Base.BusinessError) => {
if (err) {
console.error("cancel failed " + JSON.stringify(err));
} else {
console.info("cancel success");
}
}
Notification.cancel(0, "label", cancelCallback); cancel(id: number, label?: string): Promise<void>
Cancels a notification with the specified ID and optional label. This API uses a promise to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| id | number | Yes | Notification ID. |
| label | string | No | Notification label. This parameter is left empty by default. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import Base from '@ohos.base';
Notification.cancel(0).then(() => {
console.info("cancel success");
}).catch((err: Base.BusinessError) => {
console.error(`cancel failed, code is ${err}`);
}); cancel(id: number, callback: AsyncCallback<void>): void
Cancels a notification with the specified ID. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| id | number | Yes | Notification ID. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Example
import Base from '@ohos.base';
// cancel callback
let cancelCallback = (err: Base.BusinessError) => {
if (err) {
console.error("cancel failed " + JSON.stringify(err));
} else {
console.info("cancel success");
}
}
Notification.cancel(0, cancelCallback); cancelAll(callback: AsyncCallback<void>): void
Cancels all notifications. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Example
import Base from '@ohos.base';
// cancel callback
let cancelAllCallback = (err: Base.BusinessError) => {
if (err) {
console.error("cancelAll failed " + JSON.stringify(err));
} else {
console.info("cancelAll success");
}
}
Notification.cancelAll(cancelAllCallback); cancelAll(): Promise<void>
Cancels all notifications. This API uses a promise to return the result.
System capability: SystemCapability.Notification.Notification
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import Base from '@ohos.base';
Notification.cancelAll().then(() => {
console.info("cancelAll success");
}).catch((err: Base.BusinessError) => {
console.error(`cancelAll failed, code is ${err}`);
}); addSlot(type: SlotType, callback: AsyncCallback<void>): void
Adds a notification slot of a specified type. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | SlotType | Yes | Type of the notification slot to add. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Example
import Base from '@ohos.base';
// addSlot callback
let addSlotCallback = (err: Base.BusinessError) => {
if (err) {
console.error("addSlot failed " + JSON.stringify(err));
} else {
console.info("addSlot success");
}
}
Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallback); addSlot(type: SlotType): Promise<void>
Adds a notification slot of a specified type. This API uses a promise to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | SlotType | Yes | Type of the notification slot to add. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import Base from '@ohos.base';
Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => {
console.info("addSlot success");
}).catch((err: Base.BusinessError) => {
console.error(`addSlot failed, code is ${err}`);
}); getSlot(slotType: SlotType, callback: AsyncCallback<NotificationSlot>): void
Obtains a notification slot of a specified type. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotType | SlotType | Yes | Notification slot type, currently divided into social communication, service reminder, content consultation, and other types. |
| callback | AsyncCallback<NotificationSlot> | Yes | Callback used to return the result. |
Example
import Base from '@ohos.base';
// getSlot callback
let getSlotCallback = (err: Base.BusinessError) => {
if (err) {
console.error("getSlot failed " + JSON.stringify(err));
} else {
console.info("getSlot success");
}
}
let slotType: Notification.SlotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.getSlot(slotType, getSlotCallback); getSlot(slotType: SlotType): Promise<NotificationSlot>
Obtains a notification slot of a specified type. This API uses a promise to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotType | SlotType | Yes | Notification slot type, currently divided into social communication, service reminder, content consultation, and other types. |
Return value
| Type | Description |
|---|---|
| Promise<NotificationSlot> | Promise used to return the result. |
Example
import Base from '@ohos.base';
let slotType: Notification.SlotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.getSlot(slotType).then((data) => {
console.info("getSlot success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getSlot failed, code is ${err}`);
}); getSlots(callback: AsyncCallback<Array<NotificationSlot>>): void
Obtains all notification slots. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<Array<NotificationSlot>> | Yes | Callback used to return the result. |
Example
import Base from '@ohos.base';
// getSlots callback
function getSlotsCallback(err: Base.BusinessError) {
if (err) {
console.error("getSlots failed " + JSON.stringify(err));
} else {
console.info("getSlots success");
}
}
Notification.getSlots(getSlotsCallback); getSlots(): Promise<Array<NotificationSlot>>
Obtains all notification slots of this application. This API uses a promise to return the result.
System capability: SystemCapability.Notification.Notification
Return value
| Type | Description |
|---|---|
| Promise<Array<NotificationSlot>> | Promise used to return the result. |
Example
import Base from '@ohos.base';
Notification.getSlots().then((data) => {
console.info("getSlots success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getSlots failed, code is ${err}`);
}); removeSlot(slotType: SlotType, callback: AsyncCallback<void>): void
Removes a notification slot of a specified type. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotType | SlotType | Yes | Notification slot type, currently divided into social communication, service reminder, content consultation, and other types. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Example
import Base from '@ohos.base';
// removeSlot callback
let removeSlotCallback = (err: Base.BusinessError) => {
if (err) {
console.error("removeSlot failed " + JSON.stringify(err));
} else {
console.info("removeSlot success");
}
}
let slotType: Notification.SlotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.removeSlot(slotType, removeSlotCallback); removeSlot(slotType: SlotType): Promise<void>
Removes a notification slot of a specified type. This API uses a promise to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| slotType | SlotType | Yes | Notification slot type, currently divided into social communication, service reminder, content consultation, and other types. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import Base from '@ohos.base';
let slotType: Notification.SlotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.removeSlot(slotType).then(() => {
console.info("removeSlot success");
}).catch((err: Base.BusinessError) => {
console.error(`removeSlot failed, code is ${err}`);
}); removeAllSlots(callback: AsyncCallback<void>): void
Removes all notification slots. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Example
import Base from '@ohos.base';
let removeAllCallback = (err: Base.BusinessError) => {
if (err) {
console.error("removeAllSlots failed " + JSON.stringify(err));
} else {
console.info("removeAllSlots success");
}
}
Notification.removeAllSlots(removeAllCallback); removeAllSlots(): Promise<void>
Removes all notification slots. This API uses a promise to return the result.
System capability: SystemCapability.Notification.Notification
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import Base from '@ohos.base';
Notification.removeAllSlots().then(() => {
console.info("removeAllSlots success");
}).catch((err: Base.BusinessError) => {
console.error(`removeAllSlots failed, code is ${err}`);
}); getActiveNotificationCount(callback: AsyncCallback<number>): void
Obtains the number of active notifications of this application. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<number> | Yes | Callback used to return the result. |
Example
import Base from '@ohos.base';
let getActiveNotificationCountCallback = (err: Base.BusinessError, data: number) => {
if (err) {
console.error("getActiveNotificationCount failed " + JSON.stringify(err));
} else {
console.info("getActiveNotificationCount success");
}
}
Notification.getActiveNotificationCount(getActiveNotificationCountCallback); getActiveNotificationCount(): Promise<number>
Obtains the number of active notifications of this application. This API uses a promise to return the result.
System capability: SystemCapability.Notification.Notification
Return value
| Type | Description |
|---|---|
| Promise<number> | Promise used to return the result. |
Example
import Base from '@ohos.base';
Notification.getActiveNotificationCount().then((data: number) => {
console.info("getActiveNotificationCount success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getActiveNotificationCount failed, code is ${err}`);
}); getActiveNotifications(callback: AsyncCallback<Array<NotificationRequest>>): void
Obtains active notifications of this application. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<Array<NotificationRequest>> | Yes | Callback used to return the result. |
Example
import Base from '@ohos.base';
import NotificationManager from '@ohos.notificationManager';
let getActiveNotificationsCallback = (err: Base.BusinessError, data: NotificationManager.NotificationRequest[]) => {
if (err) {
console.error("getActiveNotifications failed " + JSON.stringify(err));
} else {
console.info("getActiveNotifications success");
}
}
Notification.getActiveNotifications(getActiveNotificationsCallback); getActiveNotifications(): Promise<Array<NotificationRequest>>
Obtains active notifications of this application. This API uses a promise to return the result.
System capability: SystemCapability.Notification.Notification
Return value
| Type | Description |
|---|---|
| Promise<Array<NotificationRequest>> | Promise used to return the result. |
Example
import Base from '@ohos.base';
import NotificationManager from '@ohos.notificationManager';
Notification.getActiveNotifications().then((data: NotificationManager.NotificationRequest[]) => {
console.info("getActiveNotifications success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getActiveNotifications failed, code is ${err}`);
}); cancelGroup(groupName: string, callback: AsyncCallback<void>): void
Cancels notifications under a notification group of this application. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| groupName | string | Yes | Name of the notification group, which is specified through NotificationRequest when the notification is published. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Example
import Base from '@ohos.base';
let cancelGroupCallback = (err: Base.BusinessError) => {
if (err) {
console.error("cancelGroup failed " + JSON.stringify(err));
} else {
console.info("cancelGroup success");
}
}
let groupName: string = "GroupName";
Notification.cancelGroup(groupName, cancelGroupCallback); cancelGroup(groupName: string): Promise<void>
Cancels notifications under a notification group of this application. This API uses a promise to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| groupName | string | Yes | Name of the notification group. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import Base from '@ohos.base';
let groupName: string = "GroupName";
Notification.cancelGroup(groupName).then(() => {
console.info("cancelGroup success");
}).catch((err: Base.BusinessError) => {
console.error(`cancelGroup failed, code is ${err}`);
}); isSupportTemplate(templateName: string, callback: AsyncCallback<boolean>): void
Checks whether a specified template is supported before using NotificationTemplate to publish a notification. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| templateName | string | Yes | Template name. Currently, only downloadTemplate is supported. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. |
Example
import Base from '@ohos.base';
let templateName: string = 'downloadTemplate';
function isSupportTemplateCallback(err: Base.BusinessError, data: boolean) {
if (err) {
console.error("isSupportTemplate failed " + JSON.stringify(err));
} else {
console.info("isSupportTemplate success");
}
}
Notification.isSupportTemplate(templateName, isSupportTemplateCallback); isSupportTemplate(templateName: string): Promise<boolean>
Checks whether a specified template is supported before using NotificationTemplate to publish a notification. This API uses a promise to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| templateName | string | Yes | Template name. Currently, only downloadTemplate is supported. |
Return value
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result. |
Example
import Base from '@ohos.base';
let templateName: string = 'downloadTemplate';
Notification.isSupportTemplate(templateName).then((data: boolean) => {
console.info("isSupportTemplate success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`isSupportTemplate failed, code is ${err}`);
}); requestEnableNotification(callback: AsyncCallback<void>): void
Requests notification to be enabled for this application. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Example
import Base from '@ohos.base';
let requestEnableNotificationCallback = (err: Base.BusinessError) => {
if (err) {
console.error("requestEnableNotification failed " + JSON.stringify(err));
} else {
console.info("requestEnableNotification success");
}
};
Notification.requestEnableNotification(requestEnableNotificationCallback); requestEnableNotification(): Promise<void>
Requests notification to be enabled for this application. This API uses a promise to return the result.
System capability: SystemCapability.Notification.Notification
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import Base from '@ohos.base';
Notification.requestEnableNotification().then(() => {
console.info("requestEnableNotification success");
}).catch((err: Base.BusinessError) => {
console.error(`requestEnableNotification failed, code is ${err}`);
}); isDistributedEnabled(callback: AsyncCallback<boolean>): void
Checks whether the device supports distributed notification. This API uses a callback to return the result.
System capability: SystemCapability.Notification.Notification
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. |
Example
import Base from '@ohos.base';
let isDistributedEnabledCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.error("isDistributedEnabled failed " + JSON.stringify(err));
} else {
console.info("isDistributedEnabled success " + JSON.stringify(data));
}
};
Notification.isDistributedEnabled(isDistributedEnabledCallback); isDistributedEnabled(): Promise<boolean>
Checks whether the device supports distributed notification. This API uses a promise to return the result.
System capability: SystemCapability.Notification.Notification
Return value
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result. |
Example
import Base from '@ohos.base';
Notification.isDistributedEnabled().then((data: boolean) => {
console.info("isDistributedEnabled success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`isDistributedEnabled failed, code is ${err}`);
}); System capability: SystemCapability.Notification.Notification
| Name | Value | Description |
|---|---|---|
| NOTIFICATION_CONTENT_BASIC_TEXT | NOTIFICATION_CONTENT_BASIC_TEXT | Normal text notification. |
| NOTIFICATION_CONTENT_LONG_TEXT | NOTIFICATION_CONTENT_LONG_TEXT | Long text notification. |
| NOTIFICATION_CONTENT_PICTURE | NOTIFICATION_CONTENT_PICTURE | Picture-attached notification. |
| NOTIFICATION_CONTENT_CONVERSATION | NOTIFICATION_CONTENT_CONVERSATION | Conversation notification. |
| NOTIFICATION_CONTENT_MULTILINE | NOTIFICATION_CONTENT_MULTILINE | Multi-line text notification. |
System capability: SystemCapability.Notification.Notification
| Name | Value | Description |
|---|---|---|
| LEVEL_NONE | 0 | The notification function is disabled. |
| LEVEL_MIN | 1 | The notification function is enabled, but the notification icon is not displayed in the status bar, with no banner or alert tone. |
| LEVEL_LOW | 2 | The notification function is enabled, and the notification icon is displayed in the status bar, with no banner or alert tone. |
| LEVEL_DEFAULT | 3 | The notification function is enabled, and the notification icon is displayed in the status bar, with an alert tone but no banner. |
| LEVEL_HIGH | 4 | The notification function is enabled, and the notification icon is displayed in the status bar, with an alert tone and banner. |
System capability: SystemCapability.Notification.Notification
This API is supported since API version 7 and deprecated since API version 9. You are advised to use notificationManager.BundleOption instead.
| Name | Type | Mandatory | Description |
|---|---|---|---|
| bundle | string | Yes | Bundle information of the application. |
| uid | number | No | User ID. The default value is 0. |
System capability: SystemCapability.Notification.Notification
This API is supported since API version 7 and deprecated since API version 9.
| Name | Type | Readable | Writable | Description |
|---|---|---|---|---|
| id | number | Yes | Yes | Notification ID. |
| label | string | Yes | Yes | Notification label. |
System capability: SystemCapability.Notification.Notification
| Name | Value | Description |
|---|---|---|
| UNKNOWN_TYPE | 0 | Unknown type. |
| SOCIAL_COMMUNICATION | 1 | Notification slot for social communication. |
| SERVICE_INFORMATION | 2 | Notification slot for service information. |
| CONTENT_INFORMATION | 3 | Notification slot for content consultation. |
| OTHER_TYPES | 0xFFFF | Notification slot for other purposes. |
Describes the button displayed in the notification.
System capability: SystemCapability.Notification.Notification
| Name | Type | Readable | Writable | Description |
|---|---|---|---|---|
| title | string | Yes | Yes | Button title. |
| wantAgent | WantAgent | Yes | Yes | WantAgent of the button. |
| extras | { [key: string]: any } | Yes | Yes | Extra information of the button. |
| userInput8+ | NotificationUserInput | Yes | Yes | User input object. |
Describes the normal text notification.
System capability: SystemCapability.Notification.Notification
| Name | Type | Readable | Writable | Description |
|---|---|---|---|---|
| title | string | Yes | Yes | Notification title. |
| text | string | Yes | Yes | Notification content. |
| additionalText | string | Yes | Yes | Additional information of the notification. |
Describes the long text notification.
System capability: SystemCapability.Notification.Notification
| Name | Type | Readable | Writable | Description |
|---|---|---|---|---|
| title | string | Yes | Yes | Notification title. |
| text | string | Yes | Yes | Notification content. |
| additionalText | string | Yes | Yes | Additional information of the notification. |
| longText | string | Yes | Yes | Long text of the notification. |
| briefText | string | Yes | Yes | Brief text of the notification. |
| expandedTitle | string | Yes | Yes | Title of the notification in the expanded state. |
Describes the multi-line text notification.
System capability: SystemCapability.Notification.Notification
| Name | Type | Readable | Writable | Description |
|---|---|---|---|---|
| title | string | Yes | Yes | Notification title. |
| text | string | Yes | Yes | Notification content. |
| additionalText | string | Yes | Yes | Additional information of the notification. |
| briefText | string | Yes | Yes | Brief text of the notification. |
| longTitle | string | Yes | Yes | Title of the notification in the expanded state. |
| lines | Array<string> | Yes | Yes | Multi-line text of the notification. |
Describes the picture-attached notification.
System capability: SystemCapability.Notification.Notification
| Name | Type | Readable | Writable | Description |
|---|---|---|---|---|
| title | string | Yes | Yes | Notification title. |
| text | string | Yes | Yes | Notification content. |
| additionalText | string | Yes | Yes | Additional information of the notification. |
| briefText | string | Yes | Yes | Brief text of the notification. |
| expandedTitle | string | Yes | Yes | Title of the notification in the expanded state. |
| picture | image.PixelMap | Yes | Yes | Picture attached to the notification. |
Describes the notification content.
System capability: SystemCapability.Notification.Notification
| Name | Type | Readable | Writable | Description |
|---|---|---|---|---|
| contentType | notification.ContentType | Yes | Yes | Enumerates the notification content types. |
| normal | NotificationBasicContent | Yes | Yes | Basic type notification content. |
| longText | NotificationLongTextContent | Yes | Yes | Long text. |
| multiLine | NotificationMultiLineContent | Yes | Yes | Multi-line text. |
| picture | NotificationPictureContent | Yes | Yes | Picture-attached. |
Describes the notification request.
System capability: SystemCapability.Notification.Notification
| Name | Type | Readable | Writable | Description |
|---|---|---|---|---|
| content | NotificationContent | Yes | Yes | Notification content. |
| id | number | Yes | Yes | Notification ID. |
| slotType | notification.SlotType | Yes | Yes | Slot type. |
| isOngoing | boolean | Yes | Yes | Whether the notification is an ongoing notification. |
| isUnremovable | boolean | Yes | Yes | Whether the notification can be removed. |
| deliveryTime | number | Yes | Yes | Time when the notification is sent. |
| tapDismissed | boolean | Yes | Yes | Whether the notification is automatically cleared. |
| autoDeletedTime | number | Yes | Yes | Time when the notification is automatically cleared. |
| wantAgent | WantAgent | Yes | Yes | WantAgent instance to which the notification will be redirected after being clicked. |
| extraInfo | {[key: string]: any} | Yes | Yes | Extended parameters. |
| color | number | Yes | Yes | Background color of the notification. Not supported currently. |
| colorEnabled | boolean | Yes | Yes | Whether the notification background color is enabled. Not supported currently. |
| isAlertOnce | boolean | Yes | Yes | Whether the notification triggers an alert only once. |
| isStopwatch | boolean | Yes | Yes | Whether to display the stopwatch. |
| isCountDown | boolean | Yes | Yes | Whether to display the countdown time. |
| isFloatingIcon | boolean | Yes | Yes | Whether the notification is displayed as a floating icon in the status bar. |
| label | string | Yes | Yes | Notification label. |
| badgeIconStyle | number | Yes | Yes | Notification badge type. |
| showDeliveryTime | boolean | Yes | Yes | Whether to display the time when the notification is delivered. |
| actionButtons | Array<NotificationActionButton> | Yes | Yes | Notification button, with a maximum of two buttons. |
| smallIcon | image.PixelMap | Yes | Yes | Small notification icon. This field is optional, and the icon size cannot exceed 30 KB. |
| largeIcon | image.PixelMap | Yes | Yes | Large notification icon. This field is optional, and the icon size cannot exceed 30 KB. |
| creatorBundleName | string | Yes | No | Name of the bundle that creates the notification. |
| creatorUid | number | Yes | No | UID used for creating the notification. |
| creatorPid | number | Yes | No | PID used for creating the notification. |
| creatorUserId8+ | number | Yes | No | ID of the user who creates the notification. |
| hashCode | string | Yes | No | Unique ID of the notification. |
| groupName8+ | string | Yes | Yes | Group notification name. |
| template8+ | NotificationTemplate | Yes | Yes | Notification template. |
| distributedOption8+ | DistributedOptions | Yes | Yes | Options of the distributed notification. |
| notificationFlags8+ | NotificationFlags | Yes | No | Notification flags. |
| removalWantAgent9+ | WantAgent | Yes | Yes | WantAgent instance to which the notification will be redirected when it is removed. |
| badgeNumber9+ | number | Yes | Yes | Number of notifications displayed on the application icon. |
Describes distributed notifications options.
System capability: SystemCapability.Notification.Notification
| Name | Type | Readable | Writable | Description |
|---|---|---|---|---|
| isDistributed | boolean | Yes | Yes | Whether it is a distributed notification. |
| supportDisplayDevices | Array<string> | Yes | Yes | List of the devices to which the notification can be synchronized. |
| supportOperateDevices | Array<string> | Yes | Yes | List of the devices on which the notification can be opened. |
Describes the notification slot.
System capability: SystemCapability.Notification.Notification
| Name | Type | Readable | Writable | Description |
|---|---|---|---|---|
| type | notification.SlotType | Yes | Yes | Slot type. |
| level | notification.SlotLevel | Yes | Yes | Notification level. If not set, the default value is determined by the type of the notification slot. |
| desc | string | Yes | Yes | Notification slot description. |
| badgeFlag | boolean | Yes | Yes | Whether to display the badge. |
| bypassDnd | boolean | Yes | Yes | Whether to bypass Do Not Disturb mode in the system. |
| lockscreenVisibility | number | Yes | Yes | Mode for displaying the notification on the lock screen. |
| vibrationEnabled | boolean | Yes | Yes | Whether vibration is enabled for the notification. |
| sound | string | Yes | Yes | Notification alert tone. |
| lightEnabled | boolean | Yes | Yes | Whether the indicator blinks for the notification. |
| lightColor | number | Yes | Yes | Indicator color of the notification. |
| vibrationValues | Array<number> | Yes | Yes | Vibration mode of the notification. |
| enabled9+ | boolean | Yes | No | Whether the notification slot is enabled. |