private static List<Notification> asNotificationList( StatusBarNotification[] statusBarNotifications) { List<Notification> notificationList = new ArrayList<>(statusBarNotifications.length); for (StatusBarNotification statusBarNotification : statusBarNotifications) { notificationList.add(statusBarNotification.getNotification()); } return notificationList; } }
@Implementation(minSdk = M) public StatusBarNotification[] getActiveNotifications() { StatusBarNotification[] statusBarNotifications = new StatusBarNotification[notifications.size()]; int i = 0; for (Map.Entry<Key, Notification> entry : notifications.entrySet()) { statusBarNotifications[i++] = new StatusBarNotification( RuntimeEnvironment.application.getPackageName(), null /* opPkg */, entry.getKey().id, entry.getKey().tag, android.os.Process.myUid() /* uid */, android.os.Process.myPid() /* initialPid */, 0 /* score */, entry.getValue(), android.os.Process.myUserHandle(), 0 /* postTime */); } return statusBarNotifications; }
@Override public void onNotificationRemoved(StatusBarNotification sbn) { super.onNotificationRemoved(sbn); }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public class MyNotificationListenerService extends NotificationListenerService {...} ... private void clearNotificationExample(StatusBarNotification sbn) { myNotificationListenerService.cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId()); }
@Override public void onNotificationPosted(StatusBarNotification sbn) { Log.i(TAG, "onNotificationPosted"); Log.i(TAG, "ID :" + sbn.getId() + "\t" + sbn.getNotification().tickerText + "\t" + sbn.getPackageName()); }
@Override public void onNotificationPosted(StatusBarNotification sbn) { Bundle extras = sbn.getNotification().extras; packageName = sbn.getPackageName(); Object oTitle = extras.get(Notification.EXTRA_TITLE); Object oText = extras.get(Notification.EXTRA_TEXT); if (oTitle == null || oText == null) return; title = oTitle.toString(); text = oText.toString(); Log.d(TAG, "Notification - : " + " \npackageName: " + packageName + " \nTitle : " + title + " \nText : " + text); switch (packageName) { case pkgWX: new WXClient(getApplicationContext()).onNotification(title, text); break; case pkgThis: App.timeCheckNotificationListenerServiceIsWorking = new Date().getTime(); Log.i(TAG, "onNotificationPosted: time: " + App.timeCheckNotificationListenerServiceIsWorking); break; } }
/** * http://stackoverflow.com/questions/9292032/extract-notification-text-from-parcelable-contentview-or-contentintent * */ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public static boolean notificationMatchesFilter(StatusBarNotification sbn, NotificationListenerService.RankingMap rankingMap) { NotificationListenerService.Ranking ranking = new NotificationListenerService.Ranking(); return rankingMap.getRanking(sbn.getKey(), ranking) && ranking.matchesInterruptionFilter(); }
@Override public IBinder onBind(Intent intent) { return super.onBind(intent); }
@Override public void onNotificationPosted(StatusBarNotification sbn) { super.onNotificationPosted(sbn); }
@Override public void onListenerDisconnected() { super.onListenerDisconnected(); connected = false; }
private void clearNotificationExample(StatusBarNotification sbn) { myNotificationListenerService.cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId()); }
@Override public void onNotificationPosted(StatusBarNotification sbn) { Notification n = sbn.getNotification(); for(Action action : n.actions){ String title = action.title.toString; ... } }
@Override public void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap, int reason) { super.onNotificationRemoved(sbn, rankingMap, reason); } }
@Override public void onListenerDisconnected() { super.onListenerDisconnected(); sIsConnected = false; }
private void removeRemoteViewsIfPresent(StatusBarNotification sbn) { Notification notif = sbn.getNotification(); if (notif != null) { notif.contentView = null; notif.bigContentView = null; } }
@Override public void onNotificationRemoved(StatusBarNotification sbn) { super.onNotificationRemoved(sbn); } }
private void removeRemoteViewsIfPresent(StatusBarNotification sbn) { Notification notif = sbn.getNotification(); if (notif != null) { notif.contentView = null; notif.bigContentView = null; } }
@Override public void onNotificationRemoved(StatusBarNotification notification) { super.onNotificationRemoved(notification); }
@Override public void onNotificationRemoved(StatusBarNotification sbn) { super.onNotificationRemoved(sbn); }
@Override public void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap) { super.onNotificationRemoved(sbn, rankingMap); }