Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android how to turn on do not disturb (dnd) programmatically

Tags:

android

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); 
like image 771
Andrew Avatar asked Aug 06 '15 18:08

Andrew


1 Answers

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.

like image 167
Jordan Parsons Avatar answered Sep 22 '22 23:09

Jordan Parsons