Skip to content Skip to sidebar Skip to footer

What To Listen For To Detect Do-not-disturb Mode Changes In Android?

I would like my application to show a notification when the phone has been set to do-not-disturb modes (alarms-only, priority-only or total-silence). This works pretty well by list

Solution 1:

The broadcast receiver action is :

NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED

IntentFilterintent=newIntentFilter();
intent.addAction(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED);

The below code should be in receiver.

if(intetn.getAction().equals(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED) {
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    if(mNotificationManager.getCurrentInterruptionFilter() == NotificationManager.INTERRUPTION_FILTER_ALARMS) {
        //do your stuff
    } elseif (mNotificationManager.getCurrentInterruptionFilter() == NotificationManager.INTERRUPTION_FILTER_NONE) {
        //....
    } elseif (mNotificationManager.getCurrentInterruptionFilter() == NotificationManager.INTERRUPTION_FILTER_ALL) {
        //....
    } elseif (mNotificationManager.getCurrentInterruptionFilter() == NotificationManager.INTERRUPTION_FILTER_PRIORITY) {
        //....
    } elseif (mNotificationManager.getCurrentInterruptionFilter() == NotificationManager.INTERRUPTION_FILTER_UNKNOWN) {
        //....
    }
}

Post a Comment for "What To Listen For To Detect Do-not-disturb Mode Changes In Android?"