How do I turn on/off 'do not disturb' (dnd) programmatically in Android? Is was hoping this would give me something but it doesn't:
Settings.System.putInt(getContentResolver(), Settings.System.DO_NOT_DISTURB, 1);
I found this solution:
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_NONE);
It requires:
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
Which as far as I can tell does not pop up a request dialog when doing requestPermissions(). It has to be granted through the settings menu Settings -> Sound & Notifcation -> Do Not Disturb Access.
This is on SDK 23 Marshmallow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With