I just noticed some functions of
NotificationManager that handle a class that’s called
Looking at the docs of AutomaticZenRule, it still doesn’t tell much about what it is, and what can it be used for:
Rule instance information for zen mode.
What I tried
Searching the Internet, I can see just in a Commonsware blog post, that they wonder what it is:
It is unclear what AutomaticZenRule is …
There is practically nothing more that I’ve found about it. Not “zen mode” and not “AutomaticZenRule”.
What is “zen mode” ?
What is “AutomaticZenRule” , and what can I do with it? How is it related to notifications?
Is there anything special on Android N, that this API was added on this version?
Is there a sample for using it?
From digging in into the other documents available, i was able to understand ZenMode to some extent(although it can be my own version and not the correct one).
What my understanding is as follows –
Zen Mode is the
Do not Disturb mode which now in latest updates can be enabled automatically which depends on factors such as late time of the day, etc.
AutomaticZenrule can be used by applications who want their notifications to not be masked or suppressed when in do not disturb mode.
For this your application should make request to policy access by sending the user to the activity that matches the system intent action
If user has granted access to notification policy for your app, then you will be able to set a priority notification even in do not disturb mode.
AutomaticZenrule thus plays a vital role to state the system that the application’s notifications not be suppressed.
Although, i dont have a running sample code for it, i guess it should be on similar lines like the enabling device admin code or requesting a permission use case.
Thanks to you i got to read something new 🙂
Zen Mode is just another name for Do Not Disturb (DND) mode. Android can activate DND mode based on rules. These rules can be provided either by the system, or by a third-party app.
In the following screenshot you can see two system-provided rules, together with a “Driving” rule provided by the third-party app “Pixel Ambient Services”:
AutomaticZenRule is there to integrate your own rules into the Android system. To integrate your own rules, you have to follow these rough steps:
- Make sure that you have sufficient permissions to access the DND policy (
Add an activity for your rule:
<activity android:name="MyRuleConfigurationActivity"> <meta-data android:name="android.service.zen.automatic.ruleType" android:value="My Rule" /> <intent-filter> <action android:name="android.app.action.AUTOMATIC_ZEN_RULE"/> </intent-filter> </activity>
Android will show your activity whenever the user wants to create or edit a rule of the specified rule type. In the latter case, Android will supply the ID of the existing rule in
NotificationManager#EXTRA_AUTOMATIC_RULE_ID. To propagate changes in your activity back to android, you need to construct an
AutomaticZenRuleinstance and call
After that, you can tell Android that the conditions for your rule are currently satisfied / not satisfied by calling