public abstract class NotificationSubscriber extends Object
NotificationSubscriber is an abstract class. If you want to monitor notifications
in your application, you must first inherit this class and implement related methods. For example,
if you want to be notified when a notification is received, override the onConsumed(ohos.event.notification.NotificationRequest);
if you want to be notified when a notification is canceled, override the onCanceled(ohos.event.notification.NotificationRequest)
method. Note that your application must have system-level permission to subscribe to notifications.
SystemCapability.Notification#ANS| 构造器 | 说明 |
|---|---|
NotificationSubscriber() |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
abstract void |
onCanceled(NotificationRequest request) |
Called back when a notification is canceled.
|
abstract void |
onCanceled(NotificationRequest request,
NotificationSortingMap sortingMap,
int deleteReason) |
Called back when a notification is canceled.
|
abstract void |
onConnected() |
Called back when the subscriber is connected to the Advanced Notification Service (ANS).
|
abstract void |
onConsumed(NotificationRequest request) |
Called back when the subscriber receives a new notification.
|
abstract void |
onConsumed(NotificationRequest request,
NotificationSortingMap sortingMap) |
Called back when the subscriber receives a new notification.
|
abstract void |
onDied() |
Called back when connection to the ANS has died.
|
abstract void |
onDisConnect() |
Called back when the subscriber is disconnected from the ANS.
|
abstract void |
onDisturbModeChanged(int disturbMode) |
Called when the Do Not Disturb mode type changes.
|
abstract void |
onUpdate(NotificationSortingMap sortingMap) |
Called back when the ranking information about the current notification changes.
|
public abstract void onConsumed(NotificationRequest request)
You need to inherit the NotificationSubscriber class and override this method to subscribe to
and receive notifications.
request - Indicates the received NotificationRequest object.public abstract void onConsumed(NotificationRequest request, NotificationSortingMap sortingMap)
You need to inherit the NotificationSubscriber class and override this method to subscribe to
and receive notifications.
request - Indicates the received NotificationRequest object.sortingMap - Indicates the sorting map used by the current subscriber to
obtain notification ranking information.public abstract void onCanceled(NotificationRequest request, NotificationSortingMap sortingMap, int deleteReason)
You need to inherit the NotificationSubscriber class and override this method if you want to be
notified when a notification is canceled.
request - Indicates the canceled NotificationRequest object.sortingMap - Indicates the sorting map used by the current subscriber to
obtain notification ranking information.deleteReason - Indicates the reason for the deletion. For details, see NotificationConstant.public abstract void onCanceled(NotificationRequest request)
You need to inherit the NotificationSubscriber class and override this method if you want to be
notified when a notification is canceled.
request - Indicates the canceled NotificationRequest object.public abstract void onUpdate(NotificationSortingMap sortingMap)
sortingMap - Indicates the sorting map used to obtain notification ranking information.public abstract void onConnected()
public abstract void onDisConnect()
public abstract void onDied()
public abstract void onDisturbModeChanged(int disturbMode)
disturbMode - Indicates the current Do Not Disturb mode type.