/** * 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(); }
private boolean shouldBeFilteredOut(StatusBarNotification sbn) { Notification notification = sbn.getNotification(); if (AndroidVersion.isAtLeastOreo()) { getCurrentRanking().getRanking(sbn.getKey(), mTempRanking); if (!mTempRanking.canShowBadge()) { return true; } if (mTempRanking.getChannel().getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID)) { // Special filtering for the default, legacy "Miscellaneous" channel. if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0) { return true; } } } if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0) { return true; } boolean isGroupHeader = (notification.flags & Notification.FLAG_GROUP_SUMMARY) != 0; CharSequence title = notification.extras.getCharSequence(Notification.EXTRA_TITLE); CharSequence text = notification.extras.getCharSequence(Notification.EXTRA_TEXT); boolean missingTitleAndText = TextUtils.isEmpty(title) && TextUtils.isEmpty(text); return (isGroupHeader || missingTitleAndText); }