How to schedule Do Not Disturb settings in android programmatically?

315 views Asked by At

I'm trying to activate Do Not Disturb (DND) settings from my app. I can set the DND settings using this piece of code (Provided ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED is true):

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

mNotificationManager.setNotificationPolicy(
                    new NotificationManager.Policy(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS | NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES,
                            NotificationManager.Policy.PRIORITY_SENDERS_CONTACTS,
                            NotificationManager.Policy.PRIORITY_SENDERS_CONTACTS));

mNotificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY);

I used the Policy to prioritize only calls and messages from people in my contacts only, which works fine, they were set on the device DND settings too.

Now, I want to schedule this DND settings for a particular time period, like shown in the picture below:

DND settings

Can I schedule it programmatically and how?

Thanks.

0

There are 0 answers