final NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
if (Build.VERSION.SDK_INT >= 21)
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
On Android 18+ there is a NotificationListenerService. This service gets notified when new notifications are shown. Then, I understand there are three ways to act:
super.xxxwhen receiving a notification, the notification is also showed. So this method seems to not work.
NotificationListenerService#getCurrentInterruptionFilter(). This method could return
NotificationListenerService#INTERRUPTION_FILTER_NONE(or any other of the constants), (haven't tested, should be verified).
NotificationListenerService#getCurrentInterruptionFilter()is final, so it cannot be overridden.
NotificationListenerService. That's the only option that can work in a satisfying way
About NotificationManager, see additional information in this post in StackOverflow (specially interesting the highlighted comment) and in this post.