1

I'm having troubles opening system DND preferences from my App so that user can create or edit Automatic Time rule.

Current situation

Our app already has a similar feature which disables App-notification LED, sound and vibration for some specific time period (for example between 10pm-8am) and is applied app-wide. As of Android Oreo, our feature doesn't work anymore because of Notification Channels. The only solution is, as far as I understand, to create in System preferences Automatic Time rule which is then applied system-wide.

What I want to do?

Just to redirect Oreo user from my app to System preferences ie. Do Not Disturb preferences in order to add or edit Time rule.

The problem

There is no specific Intent which opens Do Not Disturb preferences. The closest one I could find was Settings.ACTION_ZEN_MODE_PRIORITY_SETTINGS which leads me to this Preference screen. I also found action which I exactly need, but as you can see, it is hidden by annotation.

Does this mean there is no way to open this Preference screen and I should use another approach?

flyingAssistant
  • 872
  • 7
  • 19
  • [This](https://stackoverflow.com/questions/31862753/android-how-to-turn-on-do-not-disturb-dnd-programmatically) might help. – ADM Apr 30 '18 at 14:56
  • I tried, but this intent opens [DND access](https://imgur.com/a/cDsAbbi). Thanks anyways! – flyingAssistant Apr 30 '18 at 15:22

2 Answers2

0

I also had this question for a long time, now I finally found the solution that works for me:

Java

Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.Settings$ZenModeSettingsActivity"));
startActivity(intent);

Kotlin

val intent = Intent()
intent.component = ComponentName("com.android.settings", "com.android.settings.Settings\$ZenModeSettingsActivity")
startActivity(intent)
Cyb3rKo
  • 413
  • 7
  • 22
0

If you take a look at the AndroidManifest.xml for the Settings app you can see that there is an Activity Settings$ZenModeSettingsActivity (as mentioned by @cyb3rko in https://stackoverflow.com/a/63713587/467650) already from Android 5.0.

To send the user to the "Do not disturb" screen you can use the action android.settings.ZEN_MODE_SETTINGS like this:

try {
    startActivity(new Intent("android.settings.ZEN_MODE_SETTINGS"));
} catch (ActivityNotFoundException e) {
    // TODO: Handle activity not found
}

I would expect the intent filter to be even more stable than the class name.

Roy Solberg
  • 18,133
  • 12
  • 49
  • 76