The NotificationManager class in android lists two methods setInterruptionFilter (int interruptionFilter)
and setNotificationPolicy (NotificationManager.Policy policy)
.
From the docs:
public final void setInterruptionFilter (int interruptionFilter)
Sets the current notification interruption filter.
The interruption filter defines which notifications are allowed to interrupt the user (e.g. via sound & vibration) and is applied globally.
public void setNotificationPolicy (NotificationManager.Policy policy)
Sets the current notification policy.
Both were added in API level 23. From my understanding, both seem to accomplish the same task of setting the Do Not Disturb policy for the android device. What exactly is the difference between the two methods?
with setNotificationPolicy you can set the Do Not Disturb "Allow Interruptions" policies like
NotificationManager.Policy.PRIORITY_CATEGORY_ALARM
( allow alarm )with setInterruptionFilter you set the actual Don Not Disturb on or off where :
NotificationManager.INTERRUPTION_FILTER_PRIORITY
= set DND on with the setNotificationPolicy settingsNotificationManager.INTERRUPTION_FILTER_NONE
= set DND on for every interuptionNotificationManager.INTERRUPTION_FILTER_ALL
= set DND offTIP. You can get the policy first before changing it with
NotificationManager.getNotificationPolicy()
to set it back after your done.