NotificationListenerService
abstract class NotificationListenerService : Service
kotlin.Any | ||||
↳ | android.content.Context | |||
↳ | android.content.ContextWrapper | |||
↳ | android.app.Service | |||
↳ | android.service.notification.NotificationListenerService |
A service that receives calls from the system when new notifications are posted or removed, or their ranking changed.
To extend this class, you must declare the service in your manifest file with the android.Manifest.permission#BIND_NOTIFICATION_LISTENER_SERVICE
permission and include an intent filter with the SERVICE_INTERFACE
action. For example:
<service android:name=".NotificationListener" android:label="@string/service_name" android:exported="false" android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"> <intent-filter> <action android:name="android.service.notification.NotificationListenerService" /> </intent-filter> <meta-data android:name="android.service.notification.default_filter_types" android:value="conversations|alerting"> </meta-data> <meta-data android:name="android.service.notification.disabled_filter_types" android:value="ongoing|silent"> </meta-data> </service>
The service should wait for the onListenerConnected()
event before performing any operations. The requestRebind(android.content.ComponentName)
method is the only one that is safe to call before onListenerConnected()
or after onListenerDisconnected()
.
Notification listeners cannot get notification access or be bound by the system on low-RAM devices running Android Q (and below). The system also ignores notification listeners running in a work profile. A android.app.admin.DevicePolicyManager
might block notifications originating from a work profile.
From Build.VERSION_CODES#N
onward all callbacks are called on the main thread. Prior to N, there is no guarantee on what thread the callback will happen.
Summary
Nested classes | |
---|---|
open |
Stores ranking related information on a currently active notification. |
open |
Provides access to ranking information on currently active notifications. |
Constants | |
---|---|
static String |
An optional activity intent action that shows additional settings for what notifications should be processed by this notification listener service. |
static Int |
A flag value indicating that this notification listener can see altering type notifications. |
static Int |
A flag value indicating that this notification listener can see conversation type notifications. |
static Int |
A flag value indicating that this notification listener can see important ( > |
static Int |
A flag value indicating that this notification listener can see silent type notifications. |
static Int |
|
static Int |
|
static Int |
|
static Int |
|
static Int |
|
static Int |
|
static Int |
|
static Int |
|
static String |
The name of the |
static String |
The name of the |
static String |
The name of the |
static Int |
Channel or group modification reason provided to |
static Int |
Channel or group modification reason provided to |
static Int |
Channel or group modification reason provided to |
static Int |
Notification was canceled by the app canceling this specific notification. |
static Int |
Notification was canceled by the app cancelling all its notifications. |
static Int |
Notification was canceled due to an assistant adjustment update. |
static Int |
Notification was canceled by the status bar reporting a user dismissal. |
static Int |
Notification was canceled by the status bar reporting a user dismiss all. |
static Int |
Notification was canceled by the user banning the channel. |
static Int |
Notification was canceled due to the backing channel being deleted |
static Int |
Notification was canceled due to the app's storage being cleared |
static Int |
Notification was canceled by the status bar reporting a notification click. |
static Int |
Notification was canceled by the status bar reporting an inflation error. |
static Int |
Notification was canceled because it was an invisible member of a group. |
static Int |
Notification was canceled because it was a member of a canceled group. |
static Int |
Notification was canceled by a listener reporting a user dismissal. |
static Int |
Notification was canceled by a listener reporting a user dismiss all. |
static Int |
Notification was canceled when entering lockdown mode, which turns off Smart Lock, fingerprint unlocking, and notifications on the lock screen. |
static Int |
Notification was canceled by the user banning the package. |
static Int |
Notification was canceled by the package manager modifying the package. |
static Int |
Notification was canceled by the device administrator suspending the package. |
static Int |
Notification was canceled by the owning managed profile being turned off. |
static Int |
Notification was snoozed. |
static Int |
Notification was canceled due to timeout |
static Int |
Autobundled summary notification was canceled because its group was unbundled |
static Int |
Notification was canceled by the owning user context being stopped. |
static String |
The |
static Int |
Whether notification suppressed by DND should not interruption visually when the screen is off. |
static Int |
Whether notification suppressed by DND should not interruption visually when the screen is on. |
Inherited constants | |
---|---|
Public constructors | |
---|---|
Public methods | |
---|---|
Unit |
Inform the notification manager about dismissal of all notifications. |
Unit |
cancelNotification(pkg: String!, tag: String!, id: Int) Inform the notification manager about dismissal of a single notification. |
Unit |
cancelNotification(key: String!) Inform the notification manager about dismissal of a single notification. |
Unit |
cancelNotifications(keys: Array<String!>!) Inform the notification manager about dismissal of specific notifications. |
Unit |
Clears listener hints set via |
open Array<StatusBarNotification!>! |
Request the list of outstanding notifications (that is, those that are visible to the current user). |
open Array<StatusBarNotification!>! |
getActiveNotifications(keys: Array<String!>!) Request one or more notifications by key. |
Int |
Gets the current notification interruption filter active on the host. |
Int |
Gets the set of hints representing current state. |
open NotificationListenerService.RankingMap! |
Returns current ranking information. |
MutableList<NotificationChannelGroup!>! |
getNotificationChannelGroups(pkg: String, user: UserHandle) Returns all notification channel groups belonging to the given package for a given user. |
MutableList<NotificationChannel!>! |
getNotificationChannels(pkg: String, user: UserHandle) Returns all notification channels belonging to the given package for a given user. |
Array<StatusBarNotification!>! |
Like |
Unit |
migrateNotificationFilter(defaultTypes: Int, disallowedPkgs: MutableList<String!>?) Lets an app migrate notification filters from its app into the OS. |
open IBinder? |
This is not the lifecycle event you are looking for. |
open Unit | |
open Unit |
onInterruptionFilterChanged(interruptionFilter: Int) Implement this method to be notified when the |
open Unit |
Implement this method to learn about when the listener is enabled and connected to the notification manager. |
open Unit |
Implement this method to learn about when the listener is disconnected from the notification manager. |
open Unit |
onListenerHintsChanged(hints: Int) Implement this method to be notified when the |
open Unit |
onNotificationChannelGroupModified(pkg: String!, user: UserHandle!, group: NotificationChannelGroup!, modificationType: Int) Implement this method to learn about notification channel group modifications. |
open Unit |
onNotificationChannelModified(pkg: String!, user: UserHandle!, channel: NotificationChannel!, modificationType: Int) Implement this method to learn about notification channel modifications. |
open Unit |
Implement this method to learn about new notifications as they are posted by apps. |
open Unit |
onNotificationPosted(sbn: StatusBarNotification!, rankingMap: NotificationListenerService.RankingMap!) Implement this method to learn about new notifications as they are posted by apps. |
open Unit |
Implement this method to be notified when the notification ranking changes. |
open Unit |
Implement this method to learn when notifications are removed. |
open Unit |
onNotificationRemoved(sbn: StatusBarNotification!, rankingMap: NotificationListenerService.RankingMap!) Implement this method to learn when notifications are removed. |
open Unit |
onNotificationRemoved(sbn: StatusBarNotification!, rankingMap: NotificationListenerService.RankingMap!, reason: Int) Implement this method to learn when notifications are removed and why. |
open Unit |
onSilentStatusBarIconsVisibilityChanged(hideSilentStatusIcons: Boolean) Implement this method to be notified when the behavior of silent notifications in the status bar changes. |
Unit |
requestInterruptionFilter(interruptionFilter: Int) Sets the desired |
Unit |
requestListenerHints(hints: Int) Sets the desired |
open static Unit |
requestRebind(componentName: ComponentName!) Request that the listener be rebound, after a previous call to #requestUnbind. |
Unit |
Request that the service be unbound. |
open static Unit |
requestUnbind(componentName: ComponentName) Request that the service be unbound. |
Unit |
setNotificationsShown(keys: Array<String!>!) Inform the notification manager that these notifications have been viewed by the user. |
Unit |
snoozeNotification(key: String!, durationMs: Long) Inform the notification manager about snoozing a specific notification. |
Unit |
updateNotificationChannel(pkg: String, user: UserHandle, channel: NotificationChannel) Updates a notification channel for a given package for a given user. |
Protected methods | |
---|---|
open Unit |
attachBaseContext(base: Context!) |
Inherited functions | |
---|---|
Constants
ACTION_SETTINGS_HOME
static val ACTION_SETTINGS_HOME: String
An optional activity intent action that shows additional settings for what notifications should be processed by this notification listener service. If defined, the OS may link to this activity from the system notification listener service filter settings page.
Value: "android.service.notification.action.SETTINGS_HOME"
FLAG_FILTER_TYPE_ALERTING
static val FLAG_FILTER_TYPE_ALERTING: Int
A flag value indicating that this notification listener can see altering type notifications.
Value: 2
FLAG_FILTER_TYPE_CONVERSATIONS
static val FLAG_FILTER_TYPE_CONVERSATIONS: Int
A flag value indicating that this notification listener can see conversation type notifications.
Value: 1
FLAG_FILTER_TYPE_ONGOING
static val FLAG_FILTER_TYPE_ONGOING: Int
A flag value indicating that this notification listener can see important ( > NotificationManager#IMPORTANCE_MIN
) ongoing type notifications.
Value: 8
FLAG_FILTER_TYPE_SILENT
static val FLAG_FILTER_TYPE_SILENT: Int
A flag value indicating that this notification listener can see silent type notifications.
Value: 4
HINT_HOST_DISABLE_CALL_EFFECTS
static val HINT_HOST_DISABLE_CALL_EFFECTS: Int
Listener hints
constant - the primary device UI should disable phone call sounds, but not notification sound. This does not change the interruption filter, only the effects. *
Value: 4
HINT_HOST_DISABLE_EFFECTS
static val HINT_HOST_DISABLE_EFFECTS: Int
Listener hints
constant - the primary device UI should disable notification sound, vibrating and other visual or aural effects. This does not change the interruption filter, only the effects. *
Value: 1
HINT_HOST_DISABLE_NOTIFICATION_EFFECTS
static val HINT_HOST_DISABLE_NOTIFICATION_EFFECTS: Int
Listener hints
constant - the primary device UI should disable notification sound, but not phone calls. This does not change the interruption filter, only the effects. *
Value: 2
INTERRUPTION_FILTER_ALARMS
static val INTERRUPTION_FILTER_ALARMS: Int
Interruption filter
constant - Alarms only interruption filter.
Value: 4
INTERRUPTION_FILTER_ALL
static val INTERRUPTION_FILTER_ALL: Int
Interruption filter
constant - Normal interruption filter.
Value: 1
INTERRUPTION_FILTER_NONE
static val INTERRUPTION_FILTER_NONE: Int
Interruption filter
constant - No interruptions filter.
Value: 3
INTERRUPTION_FILTER_PRIORITY
static val INTERRUPTION_FILTER_PRIORITY: Int
Interruption filter
constant - Priority interruption filter.
Value: 2
INTERRUPTION_FILTER_UNKNOWN
static val INTERRUPTION_FILTER_UNKNOWN: Int
Interruption filter
constant - returned when the value is unavailable for any reason. For example, before the notification listener is connected. {@see #onListenerConnected()}
Value: 0
META_DATA_DEFAULT_AUTOBIND
static val META_DATA_DEFAULT_AUTOBIND: String
The name of the meta-data
tag containing a boolean value that is used to decide if this listener should be automatically bound by default. If the value is 'false', the listener can be bound on demand using requestRebind
An absent value means that the default is 'true'
Value: "android.service.notification.default_autobind_listenerservice"
META_DATA_DEFAULT_FILTER_TYPES
static val META_DATA_DEFAULT_FILTER_TYPES: String
The name of the meta-data
tag containing a pipe separated list of default integer notification types or "ongoing", "conversations", "alerting", or "silent" that should be provided to this listener. See FLAG_FILTER_TYPE_ONGOING
, FLAG_FILTER_TYPE_CONVERSATIONS
, ),
Value: "android.service.notification.default_filter_types"
META_DATA_DISABLED_FILTER_TYPES
static val META_DATA_DISABLED_FILTER_TYPES: String
The name of the meta-data
tag containing a comma separated list of default integer notification types that this listener never wants to receive. See FLAG_FILTER_TYPE_ONGOING
, FLAG_FILTER_TYPE_CONVERSATIONS
, ),
Value: "android.service.notification.disabled_filter_types"
NOTIFICATION_CHANNEL_OR_GROUP_ADDED
static val NOTIFICATION_CHANNEL_OR_GROUP_ADDED: Int
Channel or group modification reason provided to onNotificationChannelModified(java.lang.String,android.os.UserHandle,android.app.NotificationChannel,int)
or onNotificationChannelGroupModified(java.lang.String,android.os.UserHandle,android.app.NotificationChannelGroup,int)
- the provided object was created.
Value: 1
NOTIFICATION_CHANNEL_OR_GROUP_DELETED
static val NOTIFICATION_CHANNEL_OR_GROUP_DELETED: Int
Channel or group modification reason provided to onNotificationChannelModified(java.lang.String,android.os.UserHandle,android.app.NotificationChannel,int)
or onNotificationChannelGroupModified(java.lang.String,android.os.UserHandle,android.app.NotificationChannelGroup,int)
- the provided object was deleted.
Value: 3
NOTIFICATION_CHANNEL_OR_GROUP_UPDATED
static val NOTIFICATION_CHANNEL_OR_GROUP_UPDATED: Int
Channel or group modification reason provided to onNotificationChannelModified(java.lang.String,android.os.UserHandle,android.app.NotificationChannel,int)
or onNotificationChannelGroupModified(java.lang.String,android.os.UserHandle,android.app.NotificationChannelGroup,int)
- the provided object was updated.
Value: 2
REASON_APP_CANCEL
static val REASON_APP_CANCEL: Int
Notification was canceled by the app canceling this specific notification.
Value: 8
REASON_APP_CANCEL_ALL
static val REASON_APP_CANCEL_ALL: Int
Notification was canceled by the app cancelling all its notifications.
Value: 9
REASON_ASSISTANT_CANCEL
static val REASON_ASSISTANT_CANCEL: Int
Notification was canceled due to an assistant adjustment update.
Value: 22
REASON_CANCEL
static val REASON_CANCEL: Int
Notification was canceled by the status bar reporting a user dismissal.
Value: 2
REASON_CANCEL_ALL
static val REASON_CANCEL_ALL: Int
Notification was canceled by the status bar reporting a user dismiss all.
Value: 3
REASON_CHANNEL_BANNED
static val REASON_CHANNEL_BANNED: Int
Notification was canceled by the user banning the channel.
Value: 17
REASON_CHANNEL_REMOVED
static val REASON_CHANNEL_REMOVED: Int
Notification was canceled due to the backing channel being deleted
Value: 20
REASON_CLEAR_DATA
static val REASON_CLEAR_DATA: Int
Notification was canceled due to the app's storage being cleared
Value: 21
REASON_CLICK
static val REASON_CLICK: Int
Notification was canceled by the status bar reporting a notification click.
Value: 1
REASON_ERROR
static val REASON_ERROR: Int
Notification was canceled by the status bar reporting an inflation error.
Value: 4
REASON_GROUP_OPTIMIZATION
static val REASON_GROUP_OPTIMIZATION: Int
Notification was canceled because it was an invisible member of a group.
Value: 13
REASON_GROUP_SUMMARY_CANCELED
static val REASON_GROUP_SUMMARY_CANCELED: Int
Notification was canceled because it was a member of a canceled group.
Value: 12
REASON_LISTENER_CANCEL
static val REASON_LISTENER_CANCEL: Int
Notification was canceled by a listener reporting a user dismissal.
Value: 10
REASON_LISTENER_CANCEL_ALL
static val REASON_LISTENER_CANCEL_ALL: Int
Notification was canceled by a listener reporting a user dismiss all.
Value: 11
REASON_LOCKDOWN
static val REASON_LOCKDOWN: Int
Notification was canceled when entering lockdown mode, which turns off Smart Lock, fingerprint unlocking, and notifications on the lock screen. All the listeners shall ensure the canceled notifications are indeed removed on their end to prevent data leaking. When the user exits the lockdown mode, the removed notifications (due to lockdown) will be restored via NotificationListeners#notifyPostedLocked()
Value: 23
REASON_PACKAGE_BANNED
static val REASON_PACKAGE_BANNED: Int
Notification was canceled by the user banning the package.
Value: 7
REASON_PACKAGE_CHANGED
static val REASON_PACKAGE_CHANGED: Int
Notification was canceled by the package manager modifying the package.
Value: 5
REASON_PACKAGE_SUSPENDED
static val REASON_PACKAGE_SUSPENDED: Int
Notification was canceled by the device administrator suspending the package.
Value: 14
REASON_PROFILE_TURNED_OFF
static val REASON_PROFILE_TURNED_OFF: Int
Notification was canceled by the owning managed profile being turned off.
Value: 15
REASON_SNOOZED
static val REASON_SNOOZED: Int
Notification was snoozed.
Value: 18
REASON_TIMEOUT
static val REASON_TIMEOUT: Int
Notification was canceled due to timeout
Value: 19
REASON_UNAUTOBUNDLED
static val REASON_UNAUTOBUNDLED: Int
Autobundled summary notification was canceled because its group was unbundled
Value: 16
REASON_USER_STOPPED
static val REASON_USER_STOPPED: Int
Notification was canceled by the owning user context being stopped.
Value: 6
SERVICE_INTERFACE
static val SERVICE_INTERFACE: String
The Intent
that must be declared as handled by the service.
Value: "android.service.notification.NotificationListenerService"
SUPPRESSED_EFFECT_SCREEN_OFF
static valSUPPRESSED_EFFECT_SCREEN_OFF: Int
Deprecated: Use the more specific visual effects in NotificationManager.Policy
.
Whether notification suppressed by DND should not interruption visually when the screen is off.
Value: 1
SUPPRESSED_EFFECT_SCREEN_ON
static valSUPPRESSED_EFFECT_SCREEN_ON: Int
Deprecated: Use the more specific visual effects in NotificationManager.Policy
.
Whether notification suppressed by DND should not interruption visually when the screen is on.
Value: 2
Public constructors
NotificationListenerService
NotificationListenerService()
Public methods
cancelAllNotifications
fun cancelAllNotifications(): Unit
Inform the notification manager about dismissal of all notifications.
Use this if your listener has a user interface that allows the user to dismiss all notifications, similar to the behavior of Android's status bar and notification panel. It should be called after the user invokes the "dismiss all" function of your UI; upon being informed, the notification manager will actually remove all active notifications and you will get multiple onNotificationRemoved(android.service.notification.StatusBarNotification)
callbacks.
The service should wait for the onListenerConnected()
event before performing this operation. {@see #cancelNotification(String, String, int)}
cancelNotification
funcancelNotification(
pkg: String!,
tag: String!,
id: Int
): Unit
Deprecated: Use cancelNotification(java.lang.String)
instead. Beginning with android.os.Build.VERSION_CODES#LOLLIPOP
this method will no longer cancel the notification. It will continue to cancel the notification for applications whose targetSdkVersion
is earlier than android.os.Build.VERSION_CODES#LOLLIPOP
.
Inform the notification manager about dismissal of a single notification.
Use this if your listener has a user interface that allows the user to dismiss individual notifications, similar to the behavior of Android's status bar and notification panel. It should be called after the user dismisses a single notification using your UI; upon being informed, the notification manager will actually remove the notification and you will get an onNotificationRemoved(android.service.notification.StatusBarNotification)
callback.
Note: If your listener allows the user to fire a notification's android.app.Notification#contentIntent
by tapping/clicking/etc., you should call this method at that time if the Notification in question has the android.app.Notification#FLAG_AUTO_CANCEL
flag set.
The service should wait for the onListenerConnected()
event before performing this operation.
Parameters | |
---|---|
pkg |
String!: Package of the notifying app. |
tag |
String!: Tag of the notification as specified by the notifying app in android.app.NotificationManager#notify(String, int, android.app.Notification) . |
id |
Int: ID of the notification as specified by the notifying app in android.app.NotificationManager#notify(String, int, android.app.Notification) .
|
cancelNotification
fun cancelNotification(key: String!): Unit
Inform the notification manager about dismissal of a single notification.
Use this if your listener has a user interface that allows the user to dismiss individual notifications, similar to the behavior of Android's status bar and notification panel. It should be called after the user dismisses a single notification using your UI; upon being informed, the notification manager will actually remove the notification and you will get an onNotificationRemoved(android.service.notification.StatusBarNotification)
callback.
Note: If your listener allows the user to fire a notification's android.app.Notification#contentIntent
by tapping/clicking/etc., you should call this method at that time if the Notification in question has the android.app.Notification#FLAG_AUTO_CANCEL
flag set.
The service should wait for the onListenerConnected()
event before performing this operation.
Parameters | |
---|---|
key |
String!: Notification to dismiss from StatusBarNotification#getKey() . |
cancelNotifications
fun cancelNotifications(keys: Array<String!>!): Unit
Inform the notification manager about dismissal of specific notifications.
Use this if your listener has a user interface that allows the user to dismiss multiple notifications at once.
The service should wait for the onListenerConnected()
event before performing this operation.
Parameters | |
---|---|
keys |
Array<String!>!: Notifications to dismiss, or null to dismiss all. {@see #cancelNotification(String, String, int)} |
clearRequestedListenerHints
fun clearRequestedListenerHints(): Unit
Clears listener hints set via getCurrentListenerHints()
.
The service should wait for the onListenerConnected()
event before performing this operation.
getActiveNotifications
open fun getActiveNotifications(): Array<StatusBarNotification!>!
Request the list of outstanding notifications (that is, those that are visible to the current user). Useful when you don't know what's already been posted.
The service should wait for the onListenerConnected()
event before performing this operation.
Return | |
---|---|
Array<StatusBarNotification!>! |
An array of active notifications, sorted in natural order. |
getActiveNotifications
open fun getActiveNotifications(keys: Array<String!>!): Array<StatusBarNotification!>!
Request one or more notifications by key. Useful if you have been keeping track of notifications but didn't want to retain the bits, and now need to go back and extract more data out of those notifications.
The service should wait for the onListenerConnected()
event before performing this operation.
Parameters | |
---|---|
keys |
Array<String!>!: the keys of the notifications to request |
Return | |
---|---|
Array<StatusBarNotification!>! |
An array of notifications corresponding to the requested keys, in the same order as the key list. |
getCurrentInterruptionFilter
fun getCurrentInterruptionFilter(): Int
Gets the current notification interruption filter active on the host.
The interruption filter defines which notifications are allowed to interrupt the user (e.g. via sound & vibration) and is applied globally. Listeners can find out whether a specific notification matched the interruption filter via Ranking#matchesInterruptionFilter()
.
The current filter may differ from the previously requested filter if the notification host does not support or refuses to apply the requested filter, or if another component changed the filter in the meantime.
Listen for updates using onInterruptionFilterChanged(int)
.
The service should wait for the onListenerConnected()
event before performing this operation.
Return | |
---|---|
Int |
One of the INTERRUPTION_FILTER_ constants, or INTERRUPTION_FILTER_UNKNOWN when unavailable. |
getCurrentListenerHints
fun getCurrentListenerHints(): Int
Gets the set of hints representing current state.
The current state may differ from the requested state if the hint represents state shared across all listeners or a feature the notification host does not support or refuses to grant.
The service should wait for the onListenerConnected()
event before performing this operation.
Return | |
---|---|
Int |
Zero or more of the HINT_ constants. |
getCurrentRanking
open fun getCurrentRanking(): NotificationListenerService.RankingMap!
Returns current ranking information.
The returned object represents the current ranking snapshot and only applies for currently active notifications.
Generally you should use the RankingMap that is passed with events such as onNotificationPosted(android.service.notification.StatusBarNotification,android.service.notification.NotificationListenerService.RankingMap)
, onNotificationRemoved(android.service.notification.StatusBarNotification,android.service.notification.NotificationListenerService.RankingMap)
, and so on. This method should only be used when needing access outside of such events, for example to retrieve the RankingMap right after initialization.
The service should wait for the onListenerConnected()
event before performing this operation.
Return | |
---|---|
NotificationListenerService.RankingMap! |
A RankingMap object providing access to ranking information |
getNotificationChannelGroups
fun getNotificationChannelGroups(
pkg: String,
user: UserHandle
): MutableList<NotificationChannelGroup!>!
Returns all notification channel groups belonging to the given package for a given user.
This method will throw a security exception if you don't have access to notifications for the given user.
The caller must have device
or be the notification assistant in order to use this method.
Parameters | |
---|---|
pkg |
String: The package to retrieve channel groups for. This value cannot be null . |
user |
UserHandle: This value cannot be null . |
getNotificationChannels
fun getNotificationChannels(
pkg: String,
user: UserHandle
): MutableList<NotificationChannel!>!
Returns all notification channels belonging to the given package for a given user.
This method will throw a security exception if you don't have access to notifications for the given user.
The caller must have device
or be the notification assistant in order to use this method.
Parameters | |
---|---|
pkg |
String: The package to retrieve channels for. This value cannot be null . |
user |
UserHandle: This value cannot be null . |
getSnoozedNotifications
fun getSnoozedNotifications(): Array<StatusBarNotification!>!
Like getActiveNotifications()
, but returns the list of currently snoozed notifications, for all users this listener has access to.
The service should wait for the onListenerConnected()
event before performing this operation.
Return | |
---|---|
Array<StatusBarNotification!>! |
An array of snoozed notifications, sorted in natural order. |
migrateNotificationFilter
fun migrateNotificationFilter(
defaultTypes: Int,
disallowedPkgs: MutableList<String!>?
): Unit
Lets an app migrate notification filters from its app into the OS.
This call will be ignored if the app has already migrated these settings or the user has set filters in the UI. This method is intended for user specific settings; if an app has already specified defaults types in its manifest with META_DATA_DEFAULT_FILTER_TYPES
, the defaultTypes option will be ignored.
Parameters | |
---|---|
defaultTypes |
Int: A value representing the types of notifications that this listener should receive by default Value is either 0 or a combination of android.service.notification.NotificationListenerService#FLAG_FILTER_TYPE_CONVERSATIONS , android.service.notification.NotificationListenerService#FLAG_FILTER_TYPE_ALERTING , android.service.notification.NotificationListenerService#FLAG_FILTER_TYPE_SILENT , and android.service.notification.NotificationListenerService#FLAG_FILTER_TYPE_ONGOING |
disallowedPkgs |
MutableList<String!>?: A list of package names whose notifications should not be seen by this listener, by default, because the listener does not process or display them, or because a user had previously disallowed these packages in the listener app's UI This value may be null . |
onBind
open fun onBind(intent: Intent!): IBinder?
This is not the lifecycle event you are looking for.
The service should wait for the onListenerConnected()
event before performing any operations.
Parameters | |
---|---|
intent |
Intent!: The Intent that was used to bind to this service, as given to android.content.Context#bindService. Note that any extras that were included with the Intent at that point will not be seen here. |
Return | |
---|---|
IBinder? |
Return an IBinder through which clients can call on to the service. |
onInterruptionFilterChanged
open fun onInterruptionFilterChanged(interruptionFilter: Int): Unit
Implement this method to be notified when the interruption filter
changed.
This method must be called on the thread that originally created this UI element. This is typically the main thread of your app.
Parameters | |
---|---|
interruptionFilter |
Int: The current interruption filter . |
onListenerConnected
open fun onListenerConnected(): Unit
Implement this method to learn about when the listener is enabled and connected to the notification manager. You are safe to call getActiveNotifications()
at this time.
This method must be called on the thread that originally created this UI element. This is typically the main thread of your app.
onListenerDisconnected
open fun onListenerDisconnected(): Unit
Implement this method to learn about when the listener is disconnected from the notification manager.You will not receive any events after this call, and may only call requestRebind(android.content.ComponentName)
at this time.
This method must be called on the thread that originally created this UI element. This is typically the main thread of your app.
onListenerHintsChanged
open fun onListenerHintsChanged(hints: Int): Unit
Implement this method to be notified when the Listener hints
change.
This method must be called on the thread that originally created this UI element. This is typically the main thread of your app.
Parameters | |
---|---|
hints |
Int: The current listener hints . |
onNotificationChannelGroupModified
open fun onNotificationChannelGroupModified(
pkg: String!,
user: UserHandle!,
group: NotificationChannelGroup!,
modificationType: Int
): Unit
Implement this method to learn about notification channel group modifications.
The caller must have device
in order to receive this callback.
This method must be called on the thread that originally created this UI element. This is typically the main thread of your app.
Parameters | |
---|---|
pkg |
String!: The package the group belongs to. |
user |
UserHandle!: The user on which the change was made. |
group |
NotificationChannelGroup!: The group that has changed. |
modificationType |
Int: One of NOTIFICATION_CHANNEL_OR_GROUP_ADDED , NOTIFICATION_CHANNEL_OR_GROUP_UPDATED , NOTIFICATION_CHANNEL_OR_GROUP_DELETED . Value is android.service.notification.NotificationListenerService#NOTIFICATION_CHANNEL_OR_GROUP_ADDED , android.service.notification.NotificationListenerService#NOTIFICATION_CHANNEL_OR_GROUP_UPDATED , or android.service.notification.NotificationListenerService#NOTIFICATION_CHANNEL_OR_GROUP_DELETED |
onNotificationChannelModified
open fun onNotificationChannelModified(
pkg: String!,
user: UserHandle!,
channel: NotificationChannel!,
modificationType: Int
): Unit
Implement this method to learn about notification channel modifications.
The caller must have device
in order to receive this callback.
This method must be called on the thread that originally created this UI element. This is typically the main thread of your app.
Parameters | |
---|---|
pkg |
String!: The package the channel belongs to. |
user |
UserHandle!: The user on which the change was made. |
channel |
NotificationChannel!: The channel that has changed. |
modificationType |
Int: One of NOTIFICATION_CHANNEL_OR_GROUP_ADDED , NOTIFICATION_CHANNEL_OR_GROUP_UPDATED , NOTIFICATION_CHANNEL_OR_GROUP_DELETED . Value is android.service.notification.NotificationListenerService#NOTIFICATION_CHANNEL_OR_GROUP_ADDED , android.service.notification.NotificationListenerService#NOTIFICATION_CHANNEL_OR_GROUP_UPDATED , or android.service.notification.NotificationListenerService#NOTIFICATION_CHANNEL_OR_GROUP_DELETED |
onNotificationPosted
open fun onNotificationPosted(sbn: StatusBarNotification!): Unit
Implement this method to learn about new notifications as they are posted by apps.
This method must be called on the thread that originally created this UI element. This is typically the main thread of your app.
Parameters | |
---|---|
sbn |
StatusBarNotification!: A data structure encapsulating the original android.app.Notification object as well as its identifying information (tag and id) and source (package name). |
onNotificationPosted
open fun onNotificationPosted(
sbn: StatusBarNotification!,
rankingMap: NotificationListenerService.RankingMap!
): Unit
Implement this method to learn about new notifications as they are posted by apps.
This method must be called on the thread that originally created this UI element. This is typically the main thread of your app.
Parameters | |
---|---|
sbn |
StatusBarNotification!: A data structure encapsulating the original android.app.Notification object as well as its identifying information (tag and id) and source (package name). |
rankingMap |
NotificationListenerService.RankingMap!: The current ranking map that can be used to retrieve ranking information for active notifications, including the newly posted one. |
onNotificationRankingUpdate
open fun onNotificationRankingUpdate(rankingMap: NotificationListenerService.RankingMap!): Unit
Implement this method to be notified when the notification ranking changes.
This method must be called on the thread that originally created this UI element. This is typically the main thread of your app.
Parameters | |
---|---|
rankingMap |
NotificationListenerService.RankingMap!: The current ranking map that can be used to retrieve ranking information for active notifications. |
onNotificationRemoved
open fun onNotificationRemoved(sbn: StatusBarNotification!): Unit
Implement this method to learn when notifications are removed.
NOTE: The StatusBarNotification
object you receive will be "light"; that is, the result from StatusBarNotification#getNotification
may be missing some heavyweight fields such as android.app.Notification#contentView
and android.app.Notification#largeIcon
. However, all other fields on StatusBarNotification
, sufficient to match this call with a prior call to onNotificationPosted(android.service.notification.StatusBarNotification)
, will be intact.
This method must be called on the thread that originally created this UI element. This is typically the main thread of your app.
Parameters | |
---|---|
sbn |
StatusBarNotification!: A data structure encapsulating at least the original information (tag and id) and source (package name) used to post the android.app.Notification that was just removed. |
onNotificationRemoved
open fun onNotificationRemoved(
sbn: StatusBarNotification!,
rankingMap: NotificationListenerService.RankingMap!
): Unit
Implement this method to learn when notifications are removed.
NOTE: The StatusBarNotification
object you receive will be "light"; that is, the result from StatusBarNotification#getNotification
may be missing some heavyweight fields such as android.app.Notification#contentView
and android.app.Notification#largeIcon
. However, all other fields on StatusBarNotification
, sufficient to match this call with a prior call to onNotificationPosted(android.service.notification.StatusBarNotification)
, will be intact.
This method must be called on the thread that originally created this UI element. This is typically the main thread of your app.
Parameters | |
---|---|
sbn |
StatusBarNotification!: A data structure encapsulating at least the original information (tag and id) and source (package name) used to post the android.app.Notification that was just removed. |
rankingMap |
NotificationListenerService.RankingMap!: The current ranking map that can be used to retrieve ranking information for active notifications. |
onNotificationRemoved
open fun onNotificationRemoved(
sbn: StatusBarNotification!,
rankingMap: NotificationListenerService.RankingMap!,
reason: Int
): Unit
Implement this method to learn when notifications are removed and why.
NOTE: The StatusBarNotification
object you receive will be "light"; that is, the result from StatusBarNotification#getNotification
may be missing some heavyweight fields such as android.app.Notification#contentView
and android.app.Notification#largeIcon
. However, all other fields on StatusBarNotification
, sufficient to match this call with a prior call to onNotificationPosted(android.service.notification.StatusBarNotification)
, will be intact.
This method must be called on the thread that originally created this UI element. This is typically the main thread of your app.
onSilentStatusBarIconsVisibilityChanged
open fun onSilentStatusBarIconsVisibilityChanged(hideSilentStatusIcons: Boolean): Unit
Implement this method to be notified when the behavior of silent notifications in the status bar changes. See NotificationManager#shouldHideSilentStatusBarIcons()
.
This method must be called on the thread that originally created this UI element. This is typically the main thread of your app.
Parameters | |
---|---|
hideSilentStatusIcons |
Boolean: whether or not status bar icons should be hidden for silent notifications |
requestInterruptionFilter
fun requestInterruptionFilter(interruptionFilter: Int): Unit
Sets the desired interruption filter
.
This is merely a request, the host may or may not choose to apply the requested interruption filter depending on other listener requests or other global state.
Listen for updates using onInterruptionFilterChanged(int)
.
Apps targeting Build.VERSION_CODES#VANILLA_ICE_CREAM
and above (with some exceptions, such as companion device managers) cannot modify the global interruption filter. Calling this method will instead activate or deactivate an android.app.AutomaticZenRule
associated to the app.
The service should wait for the onListenerConnected()
event before performing this operation.
Parameters | |
---|---|
interruptionFilter |
Int: One of the INTERRUPTION_FILTER_ constants. |
requestListenerHints
fun requestListenerHints(hints: Int): Unit
Sets the desired listener hints
.
This is merely a request, the host may or may not choose to take action depending on other listener requests or other global state.
Listen for updates using onListenerHintsChanged(int)
.
The service should wait for the onListenerConnected()
event before performing this operation.
Parameters | |
---|---|
hints |
Int: One or more of the HINT_ constants. |
requestRebind
open static fun requestRebind(componentName: ComponentName!): Unit
Request that the listener be rebound, after a previous call to #requestUnbind.
This method will fail for listeners that have not been granted the permission by the user.
requestUnbind
fun requestUnbind(): Unit
Request that the service be unbound.
Once this is called, you will no longer receive updates and no method calls are guaranteed to be successful, until you next receive the onListenerConnected()
event. The service will likely be killed by the system after this call.
The service should wait for the onListenerConnected()
event before performing this operation. I know it's tempting, but you must wait.
requestUnbind
open static fun requestUnbind(componentName: ComponentName): Unit
Request that the service be unbound.
This method will fail for components that are not part of the calling app.
Parameters | |
---|---|
componentName |
ComponentName: This value cannot be null . |
setNotificationsShown
fun setNotificationsShown(keys: Array<String!>!): Unit
Inform the notification manager that these notifications have been viewed by the user. This should only be called when there is sufficient confidence that the user is looking at the notifications, such as when the notifications appear on the screen due to an explicit user interaction.
The service should wait for the onListenerConnected()
event before performing this operation.
Parameters | |
---|---|
keys |
Array<String!>!: Notifications to mark as seen. |
snoozeNotification
fun snoozeNotification(
key: String!,
durationMs: Long
): Unit
Inform the notification manager about snoozing a specific notification.
Use this if your listener has a user interface that allows the user to snooze a notification for a time. It should be called after the user snoozes a single notification using your UI; upon being informed, the notification manager will actually remove the notification and you will get an onNotificationRemoved(android.service.notification.StatusBarNotification)
callback. When the snoozing period expires, you will get a onNotificationPosted(android.service.notification.StatusBarNotification,android.service.notification.NotificationListenerService.RankingMap)
callback for the notification.
Parameters | |
---|---|
key |
String!: The key of the notification to snooze |
durationMs |
Long: A duration to snooze the notification for, in milliseconds. |
updateNotificationChannel
fun updateNotificationChannel(
pkg: String,
user: UserHandle,
channel: NotificationChannel
): Unit
Updates a notification channel for a given package for a given user. This should only be used to reflect changes a user has made to the channel via the listener's user interface.
This method will throw a security exception if you don't have access to notifications for the given user.
The caller must have device
in order to use this method.
Parameters | |
---|---|
pkg |
String: The package the channel belongs to. This value cannot be null . |
user |
UserHandle: The user the channel belongs to. This value cannot be null . |
channel |
NotificationChannel: the channel to update. This value cannot be null . |
Protected methods
attachBaseContext
protected open fun attachBaseContext(base: Context!): Unit
Parameters | |
---|---|
base |
Context!: The new base context for this wrapper. |