Managing Notification Slots
The system supports a range of notification slots. Different notification slots are assigned different reminder modes. You can choose notification slots for your application and manage them as required, such as creating, querying, and deleting notification slots.
Notification Slots
The following table lists the notification slots and their reminder modes. Y indicates that the feature is supported, and N indicates that the feature is not supported.
SlotType | Value | Category | Notification Panel | Banner | Lock Screen | Alert Tone/Vibration | Status Bar Icon | Automatic Screen-on |
---|---|---|---|---|---|---|---|---|
SOCIAL_COMMUNICATION | 1 | Social communication | Y | Y | Y | Y | Y | Y |
SERVICE_INFORMATION | 2 | Service notification | Y | N | Y | Y | Y | Y |
CONTENT_INFORMATION | 3 | Content and news | Y | N | N | N | Y | N |
OTHER_TYPES | 0xFFFF | Other | Y | N | N | N | N | N |
Available APIs
API | Description |
---|---|
addSlot(type: SlotType, callback: AsyncCallback<void>): void addSlot(type: SlotType): Promise<void> |
Adds a notification slot. |
getSlot(slotType: SlotType, callback: AsyncCallback<NotificationSlot>): void getSlot(slotType: SlotType): Promise<NotificationSlot> |
Obtains a notification slot. |
getSlots(callback: AsyncCallback<Array<NotificationSlot>>): void getSlots(): Promise<Array<NotificationSlot>> |
Obtains all notification slots for this application. |
removeSlot(slotType: SlotType, callback: AsyncCallback<void>): void removeSlot(slotType: SlotType): Promise<void> |
Removes a notification slot for this application. |
removeAllSlots(callback: AsyncCallback<void>): void removeAllSlots(): Promise<void> |
Removes all notification slots for this application. |
In addition to using addslot(), you can also create a notification slot by passing SlotType in the NotificationRequest. If the specified notification slot does not exist, it is automatically created.
How to Develop
-
Import the notificationManager module.
import notificationManager from '@ohos.notificationManager'; import Base from '@ohos.base';
-
Add a notification slot.
import Base from '@ohos.base'; // addSlot callback let addSlotCallBack = (err: Base.BusinessError): void => { if (err) { console.error(`addSlot failed, code is ${err.code}, message is ${err.message}`); } else { console.info("addSlot success"); } } notificationManager.addSlot(notificationManager.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack);
-
Obtain a notification slot.
// getSlot callback let getSlotCallback = (err: Base.BusinessError, data: notificationManager.NotificationSlot): void => { if (err) { console.error(`getSlot failed, code is ${err.code}, message is ${err.message}`); } else { console.info(`getSlot success, data is ${JSON.stringify(data)}`); } } let slotType: notificationManager.SlotType = notificationManager.SlotType.SOCIAL_COMMUNICATION; notificationManager.getSlot(slotType, getSlotCallback);
-
Remove a notification slot.
// removeSlot callback let removeSlotCallback = (err: Base.BusinessError): void => { if (err) { console.error(`removeSlot failed, code is ${err.code}, message is ${err.message}`); } else { console.info("removeSlot success"); } } let slotType = notificationManager.SlotType.SOCIAL_COMMUNICATION; notificationManager.removeSlot(slotType, removeSlotCallback);