summaryrefslogtreecommitdiffstats
path: root/core/java/android/app
diff options
context:
space:
mode:
authorDan Sandler <dsandler@android.com>2015-04-15 11:02:54 -0400
committerDaniel Sandler <dsandler@android.com>2015-04-21 17:14:17 +0000
commit994349c61e8697e626a7cd2b241a16b2b7669305 (patch)
tree52acb2617d6f89719513cf59cd84446508d8d671 /core/java/android/app
parent8d505ff025f16715d47f97d0f74a0cbba6c6391d (diff)
downloadframeworks_base-994349c61e8697e626a7cd2b241a16b2b7669305.zip
frameworks_base-994349c61e8697e626a7cd2b241a16b2b7669305.tar.gz
frameworks_base-994349c61e8697e626a7cd2b241a16b2b7669305.tar.bz2
Rediscover your own notifications.
This new API, NotificationManager.getActiveNotifications(), allows an app to recover the set of notifications it has posted that are still active (un-cleared, un-canceled, visible by the user). Along with the Notification object you'll get the original tag and id you used to post it, wrapped up in the somewhat awkwardly-named StatusBarNotification data structure (previously only used internally by NoMan/SysUI and NotificationListenerServices). Bug: 17320461 Change-Id: I8cd610956fafed4e31526b663cebdc31231ad930
Diffstat (limited to 'core/java/android/app')
-rw-r--r--core/java/android/app/INotificationManager.aidl2
-rw-r--r--core/java/android/app/NotificationManager.java29
2 files changed, 31 insertions, 0 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl
index c177a52..e275df0 100644
--- a/core/java/android/app/INotificationManager.aidl
+++ b/core/java/android/app/INotificationManager.aidl
@@ -92,4 +92,6 @@ interface INotificationManager
byte[] getBackupPayload(int user);
void applyRestore(in byte[] payload, int user);
+
+ ParceledListSlice getAppActiveNotifications(String callingPkg, int userId);
}
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index 7133dce..0a59026 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -23,6 +23,7 @@ import android.app.Notification.Builder;
import android.app.NotificationManager.Policy.Token;
import android.content.ComponentName;
import android.content.Context;
+import android.content.pm.ParceledListSlice;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@@ -35,10 +36,12 @@ import android.os.StrictMode;
import android.os.UserHandle;
import android.provider.Settings.Global;
import android.service.notification.IConditionListener;
+import android.service.notification.StatusBarNotification;
import android.service.notification.ZenModeConfig;
import android.util.Log;
import java.util.Objects;
+import java.util.List;
/**
* Class to notify the user of events that happen. This is how you tell
@@ -642,4 +645,30 @@ public class NotificationManager
}
}
+ /**
+ * Recover a list of active notifications: ones that have been posted by the calling app that
+ * have not yet been dismissed by the user or {@link #cancel(String, int)}ed by the app.
+ *
+ * Each notification is embedded in a {@link StatusBarNotification} object, including the
+ * original <code>tag</code> and <code>id</code> supplied to
+ * {@link #notify(String, int, Notification) notify()}
+ * (via {@link StatusBarNotification#getTag() getTag()} and
+ * {@link StatusBarNotification#getId() getId()}) as well as a copy of the original
+ * {@link Notification} object (via {@link StatusBarNotification#getNotification()}).
+ *
+ * @return An array of {@link StatusBarNotification}.
+ */
+ public StatusBarNotification[] getActiveNotifications() {
+ final INotificationManager service = getService();
+ final String pkg = mContext.getPackageName();
+ try {
+ final ParceledListSlice<StatusBarNotification> parceledList
+ = service.getAppActiveNotifications(pkg, UserHandle.myUserId());
+ final List<StatusBarNotification> list = parceledList.getList();
+ return list.toArray(new StatusBarNotification[list.size()]);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Unable to talk to notification manager. Woe!", e);
+ }
+ return new StatusBarNotification[0];
+ }
}