public abstract class NotificationListenerService extends Service
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:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"> <intent-filter> <action android:name="android.service.notification.NotificationListenerService" /> </intent-filter> </service>
The service should wait for the onListenerConnected()
event
before performing any operations. The requestRebind(ComponentName)
method is the only one that is safe to call before onListenerConnected()
or after onListenerDisconnected()
.
Modifier and Type | Class and Description |
---|---|
protected class |
NotificationListenerService.NotificationListenerWrapper |
static class |
NotificationListenerService.Ranking
Stores ranking related information on a currently active notification.
|
static class |
NotificationListenerService.RankingMap
Provides access to ranking information on currently active
notifications.
|
Service.StartArgFlags, Service.StartResult, Service.StopForegroundFlags
Context.BindServiceFlags, Context.CreatePackageOptions, Context.ServiceName
Modifier and Type | Field and Description |
---|---|
static int |
HINT_HOST_DISABLE_CALL_EFFECTS
Listener hints constant - the primary device UI
should disable phone call sounds, buyt not notification sound. |
static int |
HINT_HOST_DISABLE_EFFECTS
Listener hints constant - the primary device UI
should disable notification sound, vibrating and other visual or aural effects. |
static int |
HINT_HOST_DISABLE_NOTIFICATION_EFFECTS
Listener hints constant - the primary device UI
should disable notification sound, but not phone calls. |
static int |
INTERRUPTION_FILTER_ALARMS
Interruption filter constant -
Alarms only interruption filter. |
static int |
INTERRUPTION_FILTER_ALL
Interruption filter constant -
Normal interruption filter. |
static int |
INTERRUPTION_FILTER_NONE
Interruption filter constant -
No interruptions filter. |
static int |
INTERRUPTION_FILTER_PRIORITY
Interruption filter constant -
Priority interruption filter. |
static int |
INTERRUPTION_FILTER_UNKNOWN
Interruption filter constant - returned when
the value is unavailable for any reason. |
protected int |
mCurrentUser
Only valid after a successful call to (@link registerAsService}.
|
protected Context |
mSystemContext
This context is required for system services since NotificationListenerService isn't
started as a real Service and hence no context is available..
|
protected NotificationListenerService.NotificationListenerWrapper |
mWrapper |
static String |
SERVICE_INTERFACE
The
Intent that must be declared as handled by the service. |
static int |
SUPPRESSED_EFFECT_SCREEN_OFF
Whether notification suppressed by DND should not interruption visually when the screen is
off.
|
static int |
SUPPRESSED_EFFECT_SCREEN_ON
Whether notification suppressed by DND should not interruption visually when the screen is
on.
|
static int |
TRIM_FULL
The full trim of the StatusBarNotification including all its features.
|
static int |
TRIM_LIGHT
A light trim of the StatusBarNotification excluding the following features:
tickerView
contentView
largeIcon
bigContentView
headsUpContentView
extras[EXTRA_LARGE_ICON]
extras[EXTRA_LARGE_ICON_BIG]
extras[EXTRA_PICTURE]
extras[EXTRA_BIG_TEXT]
|
START_CONTINUATION_MASK, START_FLAG_REDELIVERY, START_FLAG_RETRY, START_NOT_STICKY, START_REDELIVER_INTENT, START_STICKY, START_STICKY_COMPATIBILITY, START_TASK_REMOVED_COMPLETE, STOP_FOREGROUND_DETACH, STOP_FOREGROUND_REMOVE
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APP_OPS_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BACKUP_SERVICE, BATTERY_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_ALLOW_WHITELIST_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_EXTERNAL_SERVICE, BIND_FOREGROUND_SERVICE, BIND_FOREGROUND_SERVICE_WHILE_AWAKE, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_NOT_VISIBLE, BIND_SHOWING_UI, BIND_TREAT_LIKE_ACTIVITY, BIND_VISIBLE, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CAMERA_SERVICE, CAPTIONING_SERVICE, CARRIER_CONFIG_SERVICE, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTEXT_CREDENTIAL_PROTECTED_STORAGE, CONTEXT_DEVICE_PROTECTED_STORAGE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_REGISTER_PACKAGE, CONTEXT_RESTRICTED, CONTEXTHUB_SERVICE, COUNTRY_DETECTOR, DEVICE_IDLE_CONTROLLER, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, ETHERNET_SERVICE, FINGERPRINT_SERVICE, GATEKEEPER_SERVICE, HARDWARE_PROPERTIES_SERVICE, HDMI_CONTROL_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, JOB_SCHEDULER_SERVICE, KEYGUARD_SERVICE, LAUNCHER_APPS_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_PROJECTION_SERVICE, MEDIA_ROUTER_SERVICE, MEDIA_SESSION_SERVICE, MIDI_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_NO_LOCALIZED_COLLATORS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_POLICY_SERVICE, NETWORK_SCORE_SERVICE, NETWORK_STATS_SERVICE, NETWORKMANAGEMENT_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, PERSISTENT_DATA_BLOCK_SERVICE, POWER_SERVICE, PRINT_SERVICE, RADIO_SERVICE, RECOVERY_SERVICE, RESTRICTIONS_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SERIAL_SERVICE, SHORTCUT_SERVICE, SIP_SERVICE, SOUND_TRIGGER_SERVICE, STATUS_BAR_SERVICE, STORAGE_SERVICE, SYSTEM_HEALTH_SERVICE, TELECOM_SERVICE, TELEPHONY_SERVICE, TELEPHONY_SUBSCRIPTION_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, TRUST_SERVICE, TV_INPUT_SERVICE, UI_MODE_SERVICE, UPDATE_LOCK_SERVICE, USAGE_STATS_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, VOICE_INTERACTION_MANAGER_SERVICE, WALLPAPER_SERVICE, WIFI_NAN_SERVICE, WIFI_P2P_SERVICE, WIFI_RTT_SERVICE, WIFI_SCANNING_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
Constructor and Description |
---|
NotificationListenerService() |
Modifier and Type | Method and Description |
---|---|
protected void |
attachBaseContext(Context base)
Set the base context for this ContextWrapper.
|
void |
cancelAllNotifications()
Inform the notification manager about dismissal of all notifications.
|
void |
cancelNotification(String key)
Inform the notification manager about dismissal of a single notification.
|
void |
cancelNotification(String pkg,
String tag,
int id)
Deprecated.
Use
cancelNotification(String key)
instead. Beginning with 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 Build.VERSION_CODES.LOLLIPOP . |
void |
cancelNotifications(String[] keys)
Inform the notification manager about dismissal of specific notifications.
|
StatusBarNotification[] |
getActiveNotifications()
Request the list of outstanding notifications (that is, those that are visible to the
current user).
|
StatusBarNotification[] |
getActiveNotifications(int trim)
Request the list of outstanding notifications (that is, those that are visible to the
current user).
|
StatusBarNotification[] |
getActiveNotifications(String[] keys)
Request one or more notifications by key.
|
StatusBarNotification[] |
getActiveNotifications(String[] keys,
int trim)
Request one or more notifications by key.
|
protected Context |
getContext() |
int |
getCurrentInterruptionFilter()
Gets the current notification interruption filter active on the host.
|
int |
getCurrentListenerHints()
Gets the set of hints representing current state.
|
NotificationListenerService.RankingMap |
getCurrentRanking()
Returns current ranking information.
|
protected INotificationManager |
getNotificationInterface() |
protected boolean |
isBound() |
IBinder |
onBind(Intent intent)
This is not the lifecycle event you are looking for.
|
void |
onDestroy()
Called by the system to notify a Service that it is no longer used and is being removed.
|
void |
onInterruptionFilterChanged(int interruptionFilter)
Implement this method to be notified when the
interruption filter changed. |
void |
onListenerConnected()
Implement this method to learn about when the listener is enabled and connected to
the notification manager.
|
void |
onListenerDisconnected()
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(ComponentName) at this time. |
void |
onListenerHintsChanged(int hints)
Implement this method to be notified when the
Listener hints change. |
void |
onNotificationPosted(StatusBarNotification sbn)
Implement this method to learn about new notifications as they are posted by apps.
|
void |
onNotificationPosted(StatusBarNotification sbn,
NotificationListenerService.RankingMap rankingMap)
Implement this method to learn about new notifications as they are posted by apps.
|
void |
onNotificationRankingUpdate(NotificationListenerService.RankingMap rankingMap)
Implement this method to be notified when the notification ranking changes.
|
void |
onNotificationRemoved(StatusBarNotification sbn)
Implement this method to learn when notifications are removed.
|
void |
onNotificationRemoved(StatusBarNotification sbn,
NotificationListenerService.RankingMap rankingMap)
Implement this method to learn when notifications are removed.
|
void |
registerAsSystemService(Context context,
ComponentName componentName,
int currentUser)
Directly register this service with the Notification Manager.
|
void |
requestInterruptionFilter(int interruptionFilter)
Sets the desired
interruption filter . |
void |
requestListenerHints(int hints)
Sets the desired
listener hints . |
static void |
requestRebind(ComponentName componentName)
Request that the listener be rebound, after a previous call to (@link requestUnbind).
|
void |
requestUnbind()
Request that the service be unbound.
|
void |
setNotificationsShown(String[] keys)
Inform the notification manager that these notifications have been viewed by the
user.
|
void |
setOnNotificationPostedTrim(int trim)
Sets the notification trim that will be received via
onNotificationPosted(android.service.notification.StatusBarNotification) . |
void |
unregisterAsSystemService()
Directly unregister this service from the Notification Manager.
|
attach, dump, getApplication, onConfigurationChanged, onCreate, onLowMemory, onRebind, onStart, onStartCommand, onTaskRemoved, onTrimMemory, onUnbind, setForeground, startForeground, stopForeground, stopForeground, stopSelf, stopSelf, stopSelfResult
bindService, bindServiceAsUser, canStartActivityForResult, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermission, checkUriPermission, clearWallpaper, createApplicationContext, createConfigurationContext, createCredentialProtectedStorageContext, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, createPackageContextAsUser, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getBasePackageName, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDatabasePath, getDataDir, getDir, getDisplay, getDisplayAdjustments, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getFileStreamPath, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getOpPackageName, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSharedPreferences, getSharedPreferencesPath, getSystemService, getSystemServiceName, getTheme, getThemeResId, getUserId, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isCredentialProtectedStorage, isDeviceProtectedStorage, isRestricted, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, registerReceiverAsUser, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendBroadcastAsUser, sendBroadcastMultiplePermissions, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendOrderedBroadcastAsUser, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setTheme, setWallpaper, setWallpaper, startActivities, startActivities, startActivitiesAsUser, startActivity, startActivity, startActivityAsUser, startActivityAsUser, startActivityForResult, startInstrumentation, startIntentSender, startIntentSender, startService, startServiceAsUser, stopService, stopServiceAsUser, unbindService, unregisterReceiver
bindServiceAsUser, createCredentialEncryptedStorageContext, createDeviceEncryptedStorageContext, getColor, getColorStateList, getDrawable, getSharedPrefsFile, getString, getString, getSystemService, getText, isCredentialEncryptedStorage, isDeviceEncryptedStorage, migrateDatabaseFrom, migrateSharedPreferencesFrom, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks
public static final int INTERRUPTION_FILTER_ALL
Interruption filter
constant -
Normal interruption filter.public static final int INTERRUPTION_FILTER_PRIORITY
Interruption filter
constant -
Priority interruption filter.public static final int INTERRUPTION_FILTER_NONE
Interruption filter
constant -
No interruptions filter.public static final int INTERRUPTION_FILTER_ALARMS
Interruption filter
constant -
Alarms only interruption filter.public static final int INTERRUPTION_FILTER_UNKNOWN
Interruption filter
constant - returned when
the value is unavailable for any reason. For example, before the notification listener
is connected.
onListenerConnected()
public static final int HINT_HOST_DISABLE_EFFECTS
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.public static final int HINT_HOST_DISABLE_NOTIFICATION_EFFECTS
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.public static final int HINT_HOST_DISABLE_CALL_EFFECTS
Listener hints
constant - the primary device UI
should disable phone call sounds, buyt not notification sound.
This does not change the interruption filter, only the effects.public static final int SUPPRESSED_EFFECT_SCREEN_OFF
public static final int SUPPRESSED_EFFECT_SCREEN_ON
public static final int TRIM_FULL
public static final int TRIM_LIGHT
protected NotificationListenerService.NotificationListenerWrapper mWrapper
protected int mCurrentUser
protected Context mSystemContext
public static final String SERVICE_INTERFACE
Intent
that must be declared as handled by the service.protected void attachBaseContext(Context base)
ContextWrapper
attachBaseContext
in class ContextWrapper
base
- The new base context for this wrapper.public void onNotificationPosted(StatusBarNotification sbn)
sbn
- A data structure encapsulating the original Notification
object as well as its identifying information (tag and id) and source
(package name).public void onNotificationPosted(StatusBarNotification sbn, NotificationListenerService.RankingMap rankingMap)
sbn
- A data structure encapsulating the original Notification
object as well as its identifying information (tag and id) and source
(package name).rankingMap
- The current ranking map that can be used to retrieve ranking information
for active notifications, including the newly posted one.public void onNotificationRemoved(StatusBarNotification sbn)
This might occur because the user has dismissed the notification using system UI (or another notification listener) or because the app has withdrawn the notification.
NOTE: The StatusBarNotification
object you receive will be "light"; that is, the
result from StatusBarNotification.getNotification()
may be missing some heavyweight
fields such as Notification.contentView
and
Notification.largeIcon
. However, all other fields on
StatusBarNotification
, sufficient to match this call with a prior call to
onNotificationPosted(StatusBarNotification)
, will be intact.
sbn
- A data structure encapsulating at least the original information (tag and id)
and source (package name) used to post the Notification
that
was just removed.public void onNotificationRemoved(StatusBarNotification sbn, NotificationListenerService.RankingMap rankingMap)
This might occur because the user has dismissed the notification using system UI (or another notification listener) or because the app has withdrawn the notification.
NOTE: The StatusBarNotification
object you receive will be "light"; that is, the
result from StatusBarNotification.getNotification()
may be missing some heavyweight
fields such as Notification.contentView
and
Notification.largeIcon
. However, all other fields on
StatusBarNotification
, sufficient to match this call with a prior call to
onNotificationPosted(StatusBarNotification)
, will be intact.
sbn
- A data structure encapsulating at least the original information (tag and id)
and source (package name) used to post the Notification
that
was just removed.rankingMap
- The current ranking map that can be used to retrieve ranking information
for active notifications.public void onListenerConnected()
getActiveNotifications()
at this time.public void onListenerDisconnected()
requestRebind(ComponentName)
at this time.public void onNotificationRankingUpdate(NotificationListenerService.RankingMap rankingMap)
rankingMap
- The current ranking map that can be used to retrieve ranking information
for active notifications.public void onListenerHintsChanged(int hints)
Listener hints
change.hints
- The current listener hints
.public void onInterruptionFilterChanged(int interruptionFilter)
interruption filter
changed.interruptionFilter
- The current
interruption filter
.protected final INotificationManager getNotificationInterface()
public final void cancelNotification(String pkg, String tag, int id)
cancelNotification(String key)
instead. Beginning with 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 Build.VERSION_CODES.LOLLIPOP
.
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(StatusBarNotification)
callback.
Note: If your listener allows the user to fire a notification's
Notification.contentIntent
by tapping/clicking/etc., you should call
this method at that time if the Notification in question has the
Notification.FLAG_AUTO_CANCEL
flag set.
The service should wait for the onListenerConnected()
event
before performing this operation.
pkg
- Package of the notifying app.tag
- Tag of the notification as specified by the notifying app in
NotificationManager.notify(String, int, android.app.Notification)
.id
- ID of the notification as specified by the notifying app in
NotificationManager.notify(String, int, android.app.Notification)
.
public final void cancelNotification(String key)
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(StatusBarNotification)
callback.
Note: If your listener allows the user to fire a notification's
Notification.contentIntent
by tapping/clicking/etc., you should call
this method at that time if the Notification in question has the
Notification.FLAG_AUTO_CANCEL
flag set.
The service should wait for the onListenerConnected()
event
before performing this operation.
key
- Notification to dismiss from StatusBarNotification.getKey()
.public final void cancelAllNotifications()
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(StatusBarNotification)
callbacks.
The service should wait for the onListenerConnected()
event
before performing this operation.
cancelNotification(String, String, int)
public final void cancelNotifications(String[] keys)
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.
keys
- Notifications to dismiss, or null
to dismiss all.
cancelNotification(String, String, int)
public final void setNotificationsShown(String[] keys)
The service should wait for the onListenerConnected()
event
before performing this operation.
keys
- Notifications to mark as seen.public final void setOnNotificationPostedTrim(int trim)
onNotificationPosted(android.service.notification.StatusBarNotification)
.
Setting a trim other than TRIM_FULL
enables listeners that don't need access to the
full notification features right away to reduce their memory footprint. Full notifications
can be requested on-demand via getActiveNotifications(int)
.
Set to TRIM_FULL
initially.
The service should wait for the onListenerConnected()
event
before performing this operation.
trim
- trim of the notifications to be passed via onNotificationPosted(android.service.notification.StatusBarNotification)
.
See TRIM_*
constants.public StatusBarNotification[] getActiveNotifications()
The service should wait for the onListenerConnected()
event
before performing this operation.
public StatusBarNotification[] getActiveNotifications(int trim)
trim
- trim of the notifications to be returned. See TRIM_*
constants.public StatusBarNotification[] getActiveNotifications(String[] keys)
The service should wait for the onListenerConnected()
event
before performing this operation.
keys
- the keys of the notifications to requestpublic StatusBarNotification[] getActiveNotifications(String[] keys, int trim)
keys
- the keys of the notifications to requesttrim
- trim of the notifications to be returned. See TRIM_*
constants.public final int getCurrentListenerHints()
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.
public final int getCurrentInterruptionFilter()
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
NotificationListenerService.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.
public final void requestListenerHints(int hints)
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.
hints
- One or more of the HINT_ constants.public final void requestInterruptionFilter(int interruptionFilter)
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)
.
The service should wait for the onListenerConnected()
event
before performing this operation.
interruptionFilter
- One of the INTERRUPTION_FILTER_ constants.public NotificationListenerService.RankingMap getCurrentRanking()
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(StatusBarNotification, RankingMap)
,
onNotificationRemoved(StatusBarNotification, 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.
NotificationListenerService.RankingMap
object providing access to ranking informationpublic IBinder onBind(Intent intent)
The service should wait for the onListenerConnected()
event
before performing any operations.
onBind
in class Service
intent
- The Intent that was used to bind to this service,
as given to Context.bindService
. Note that any extras that were included with
the Intent at that point will not be seen here.protected boolean isBound()
public void onDestroy()
Service
public void registerAsSystemService(Context context, ComponentName componentName, int currentUser) throws RemoteException
Only system services may use this call. It will fail for non-system callers. Apps should ask the user to add their listener in Settings.
context
- Context required for accessing resources. Since this service isn't
launched as a real Service when using this method, a context has to be passed in.componentName
- the component that will consume the notification informationcurrentUser
- the user to use as the stream filterRemoteException
public void unregisterAsSystemService() throws RemoteException
This method will fail for listeners that were not registered with (@link registerAsService).
RemoteException
public static void requestRebind(ComponentName componentName)
This method will fail for listeners that have not been granted the permission by the user.
public final void requestUnbind()
This will no longer receive updates until
requestRebind(ComponentName)
is called.
The service will likely be kiled 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.
protected Context getContext()