Methods Summary |
---|
private void | applyUpdate(NotificationRankingUpdate update)
mRankingMap = new RankingMap(update);
|
public final void | cancelAllNotifications()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 {@link #onNotificationRemoved(StatusBarNotification)} callbacks.
{@see #cancelNotification(String, String, int)}
cancelNotifications(null /*all*/);
|
public final void | cancelNotification(java.lang.String pkg, java.lang.String tag, int id)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 {@link #onNotificationRemoved(StatusBarNotification)} callback.
Note: If your listener allows the user to fire a notification's
{@link android.app.Notification#contentIntent} by tapping/clicking/etc., you should call
this method at that time if the Notification in question has the
{@link android.app.Notification#FLAG_AUTO_CANCEL} flag set.
if (!isBound()) return;
try {
getNotificationInterface().cancelNotificationFromListener(
mWrapper, pkg, tag, id);
} catch (android.os.RemoteException ex) {
Log.v(TAG, "Unable to contact notification manager", ex);
}
|
public final void | cancelNotification(java.lang.String key)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 {@link #onNotificationRemoved(StatusBarNotification)} callback.
Note: If your listener allows the user to fire a notification's
{@link android.app.Notification#contentIntent} by tapping/clicking/etc., you should call
this method at that time if the Notification in question has the
{@link android.app.Notification#FLAG_AUTO_CANCEL} flag set.
if (!isBound()) return;
try {
getNotificationInterface().cancelNotificationsFromListener(mWrapper,
new String[] {key});
} catch (android.os.RemoteException ex) {
Log.v(TAG, "Unable to contact notification manager", ex);
}
|
public final void | cancelNotifications(java.lang.String[] keys)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.
if (!isBound()) return;
try {
getNotificationInterface().cancelNotificationsFromListener(mWrapper, keys);
} catch (android.os.RemoteException ex) {
Log.v(TAG, "Unable to contact notification manager", ex);
}
|
public StatusBarNotification[] | getActiveNotifications()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.
return getActiveNotifications(null, TRIM_FULL);
|
public StatusBarNotification[] | getActiveNotifications(int trim)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.
return getActiveNotifications(null, trim);
|
public StatusBarNotification[] | getActiveNotifications(java.lang.String[] keys)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.
return getActiveNotifications(keys, TRIM_FULL);
|
public StatusBarNotification[] | getActiveNotifications(java.lang.String[] keys, int trim)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.
if (!isBound())
return null;
try {
ParceledListSlice<StatusBarNotification> parceledList = getNotificationInterface()
.getActiveNotificationsFromListener(mWrapper, keys, trim);
List<StatusBarNotification> list = parceledList.getList();
int N = list.size();
for (int i = 0; i < N; i++) {
Notification notification = list.get(i).getNotification();
Builder.rebuild(getContext(), notification);
}
return list.toArray(new StatusBarNotification[N]);
} catch (android.os.RemoteException ex) {
Log.v(TAG, "Unable to contact notification manager", ex);
}
return null;
|
private android.content.Context | getContext()
if (mSystemContext != null) {
return mSystemContext;
}
return this;
|
public final int | getCurrentInterruptionFilter()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
{@link 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 {@link #onInterruptionFilterChanged(int)}.
if (!isBound()) return 0;
try {
return getNotificationInterface().getInterruptionFilterFromListener(mWrapper);
} catch (android.os.RemoteException ex) {
Log.v(TAG, "Unable to contact notification manager", ex);
return 0;
}
|
public final int | getCurrentListenerHints()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.
if (!isBound()) return 0;
try {
return getNotificationInterface().getHintsFromListener(mWrapper);
} catch (android.os.RemoteException ex) {
Log.v(TAG, "Unable to contact notification manager", ex);
return 0;
}
|
public android.service.notification.NotificationListenerService$RankingMap | getCurrentRanking()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 {@link #onNotificationPosted(StatusBarNotification, RankingMap)},
{@link #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.
return mRankingMap;
|
private final android.app.INotificationManager | getNotificationInterface()
if (mNoMan == null) {
mNoMan = INotificationManager.Stub.asInterface(
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
}
return mNoMan;
|
private boolean | isBound()
if (mWrapper == null) {
Log.w(TAG, "Notification listener service not yet bound.");
return false;
}
return true;
|
public android.os.IBinder | onBind(android.content.Intent intent)
if (mWrapper == null) {
mWrapper = new INotificationListenerWrapper();
}
return mWrapper;
|
public void | onInterruptionFilterChanged(int interruptionFilter)Implement this method to be notified when the
{@link #getCurrentInterruptionFilter() interruption filter} changed.
// optional
|
public void | onListenerConnected()Implement this method to learn about when the listener is enabled and connected to
the notification manager. You are safe to call {@link #getActiveNotifications()}
at this time.
// optional
|
public void | onListenerHintsChanged(int hints)Implement this method to be notified when the
{@link #getCurrentListenerHints() Listener hints} change.
// optional
|
public void | onNotificationPosted(StatusBarNotification sbn)Implement this method to learn about new notifications as they are posted by apps.
// optional
|
public void | onNotificationPosted(StatusBarNotification sbn, android.service.notification.NotificationListenerService$RankingMap rankingMap)Implement this method to learn about new notifications as they are posted by apps.
onNotificationPosted(sbn);
|
public void | onNotificationRankingUpdate(android.service.notification.NotificationListenerService$RankingMap rankingMap)Implement this method to be notified when the notification ranking changes.
// optional
|
public void | onNotificationRemoved(StatusBarNotification sbn)Implement this method to learn when notifications are removed.
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 {@link StatusBarNotification} object you receive will be "light"; that is, the
result from {@link StatusBarNotification#getNotification} may be missing some heavyweight
fields such as {@link android.app.Notification#contentView} and
{@link android.app.Notification#largeIcon}. However, all other fields on
{@link StatusBarNotification}, sufficient to match this call with a prior call to
{@link #onNotificationPosted(StatusBarNotification)}, will be intact.
// optional
|
public void | onNotificationRemoved(StatusBarNotification sbn, android.service.notification.NotificationListenerService$RankingMap rankingMap)Implement this method to learn when notifications are removed.
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 {@link StatusBarNotification} object you receive will be "light"; that is, the
result from {@link StatusBarNotification#getNotification} may be missing some heavyweight
fields such as {@link android.app.Notification#contentView} and
{@link android.app.Notification#largeIcon}. However, all other fields on
{@link StatusBarNotification}, sufficient to match this call with a prior call to
{@link #onNotificationPosted(StatusBarNotification)}, will be intact.
onNotificationRemoved(sbn);
|
public void | registerAsSystemService(android.content.Context context, android.content.ComponentName componentName, int currentUser)Directly register this service with the Notification Manager.
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.
mSystemContext = context;
if (mWrapper == null) {
mWrapper = new INotificationListenerWrapper();
}
INotificationManager noMan = getNotificationInterface();
noMan.registerListener(mWrapper, componentName, currentUser);
mCurrentUser = currentUser;
|
public final void | requestInterruptionFilter(int interruptionFilter)Sets the desired {@link #getCurrentInterruptionFilter() 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 {@link #onInterruptionFilterChanged(int)}.
if (!isBound()) return;
try {
getNotificationInterface()
.requestInterruptionFilterFromListener(mWrapper, interruptionFilter);
} catch (android.os.RemoteException ex) {
Log.v(TAG, "Unable to contact notification manager", ex);
}
|
public final void | requestListenerHints(int hints)Sets the desired {@link #getCurrentListenerHints() 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 {@link #onListenerHintsChanged(int)}.
if (!isBound()) return;
try {
getNotificationInterface().requestHintsFromListener(mWrapper, hints);
} catch (android.os.RemoteException ex) {
Log.v(TAG, "Unable to contact notification manager", ex);
}
|
public final void | setOnNotificationPostedTrim(int trim)Sets the notification trim that will be received via {@link #onNotificationPosted}.
Setting a trim other than {@link #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 {@link #getActiveNotifications(int)}.
Set to {@link #TRIM_FULL} initially.
if (!isBound()) return;
try {
getNotificationInterface().setOnNotificationPostedTrimFromListener(mWrapper, trim);
} catch (RemoteException ex) {
Log.v(TAG, "Unable to contact notification manager", ex);
}
|
public void | unregisterAsSystemService()Directly unregister this service from the Notification Manager.
This method will fail for listeners that were not registered
with (@link registerAsService).
if (mWrapper != null) {
INotificationManager noMan = getNotificationInterface();
noMan.unregisterListener(mWrapper, mCurrentUser);
}
|