NotificationManagerCompat

class NotificationManagerCompat
kotlin.Any
   ↳ androidx.core.app.NotificationManagerCompat

Compatibility library for NotificationManager with fallbacks for older platforms.

To use this class, call the static function #from to get a NotificationManagerCompat object, and then call one of its methods to post or cancel notifications.

Summary

Constants
static String

Intent action to register for on a service to receive side channel notifications.

static String

Notification extras key: if set to true, the posted notification should use the side channel for delivery instead of using notification manager.

static Int

Default notification importance: shows everywhere, allowed to makes noise, but does not visually intrude.

static Int

Higher notification importance: shows everywhere, allowed to makes noise and peek.

static Int

Low notification importance: shows everywhere, but is not intrusive.

static Int

Highest notification importance: shows everywhere, allowed to makes noise, peek, and use full screen intents.

static Int

Min notification importance: only shows in the shade, below the fold.

static Int

A notification with no importance: shows nowhere, is blocked.

static Int

Value signifying that the user has not expressed an importance.

Public methods
Unit

Cancel all previously shown notifications.

Boolean

Returns whether notifications from the calling package are not blocked.

Int

Returns the user specified importance for notifications from the calling package.

Unit
notify(id: Int, notification: Notification)

Post a notification to be shown in the status bar, stream, etc.

Unit
notify(tag: String?, id: Int, notification: Notification)

Post a notification to be shown in the status bar, stream, etc.

Unit
cancel(id: Int)

Cancel a previously shown notification.

Unit
cancel(tag: String?, id: Int)

Cancel a previously shown notification.

static NotificationManagerCompat
from(context: Context)

Get a NotificationManagerCompat instance for a provided context.

static MutableSet<String!>

Get the set of packages that have an enabled notification listener component within them.

Constants

ACTION_BIND_SIDE_CHANNEL

static val ACTION_BIND_SIDE_CHANNEL: String

Intent action to register for on a service to receive side channel notifications. The listening service must be in the same package as an enabled android.service.notification.NotificationListenerService.

Value: "android.support.BIND_NOTIFICATION_SIDE_CHANNEL"

EXTRA_USE_SIDE_CHANNEL

static val EXTRA_USE_SIDE_CHANNEL: String

Notification extras key: if set to true, the posted notification should use the side channel for delivery instead of using notification manager.

Value: "android.support.useSideChannel"

IMPORTANCE_DEFAULT

static val IMPORTANCE_DEFAULT: Int

Default notification importance: shows everywhere, allowed to makes noise, but does not visually intrude.

Value: 3

IMPORTANCE_HIGH

static val IMPORTANCE_HIGH: Int

Higher notification importance: shows everywhere, allowed to makes noise and peek.

Value: 4

IMPORTANCE_LOW

static val IMPORTANCE_LOW: Int

Low notification importance: shows everywhere, but is not intrusive.

Value: 2

IMPORTANCE_MAX

static val IMPORTANCE_MAX: Int

Highest notification importance: shows everywhere, allowed to makes noise, peek, and use full screen intents.

Value: 5

IMPORTANCE_MIN

static val IMPORTANCE_MIN: Int

Min notification importance: only shows in the shade, below the fold.

Value: 1

IMPORTANCE_NONE

static val IMPORTANCE_NONE: Int

A notification with no importance: shows nowhere, is blocked.

Value: 0

IMPORTANCE_UNSPECIFIED

static val IMPORTANCE_UNSPECIFIED: Int

Value signifying that the user has not expressed an importance. This value is for persisting preferences, and should never be associated with an actual notification.

Value: -1000

Public methods

cancelAll

fun cancelAll(): Unit

Cancel all previously shown notifications.

areNotificationsEnabled

fun areNotificationsEnabled(): Boolean

Returns whether notifications from the calling package are not blocked.

getImportance

fun getImportance(): Int

Returns the user specified importance for notifications from the calling package.

Return
Int: An importance level, such as #IMPORTANCE_DEFAULT.

notify

fun notify(id: Int, notification: Notification): Unit

Post a notification to be shown in the status bar, stream, etc.

Parameters
id Int: the ID of the notification
notification Int: the notification to post to the system

notify

fun notify(tag: String?, id: Int, notification: Notification): Unit

Post a notification to be shown in the status bar, stream, etc.

Parameters
tag String?: the string identifier for a notification. Can be null.
id String?: the ID of the notification. The pair (tag, id) must be unique within your app.
notification String?: the notification to post to the system

cancel

fun cancel(id: Int): Unit

Cancel a previously shown notification.

Parameters
id Int: the ID of the notification

cancel

fun cancel(tag: String?, id: Int): Unit

Cancel a previously shown notification.

Parameters
tag String?: the string identifier of the notification.
id String?: the ID of the notification

from

static fun from(context: Context): NotificationManagerCompat

Get a NotificationManagerCompat instance for a provided context.

getEnabledListenerPackages

static fun getEnabledListenerPackages(context: Context): MutableSet<String!>

Get the set of packages that have an enabled notification listener component within them.