“AutomaticZenRule”是什么?它有什么用途?

13

背景

我注意到NotificationManager的一些函数处理名为AutomaticZenRule的类:

https://developer.android.com/reference/android/app/NotificationManager.html#addAutomaticZenRule(android.app.AutomaticZenRule)

以及其他函数……

问题

查看AutomaticZenRule文档,它仍然没有详细说明它是什么,以及它可以用于什么:

zen 模式的规则实例信息。

尝试过的解决方案

在互联网上搜索后,我发现只有在Commonsware博客文章中提到了这个问题:

AutomaticZenRule是什么不清楚...

我没有找到更多关于它的资料。没有“zen模式”和没有“AutomaticZenRule”。

问题

  1. 什么是“zen模式”?

  2. 什么是“AutomaticZenRule”,我能用它做什么?它如何与通知相关联?

  3. 在Android N上有什么特殊之处,该API是在这个版本中添加的吗?

  4. 有使用它的示例吗?


1
将此作为注释添加,因为我没有足够的信息来实际回答一切。但是在 android.provider.Settings类 中有一个包含禅定模式(Zen Mode)的值,这暗示它可能与“请勿打扰”模式有关。虽然含糊不清,但至少有点线索。(如果链接因任何原因失效,重要部分是:“Activity Action: 显示禅定模式(又称“请勿打扰”)优先配置设置。”) - Zoe stands with Ukraine
2个回答

2
“Zen Mode”只是“请勿打扰(DND)”模式的另一个名称。Android可以根据规则激活DND模式。这些规则可以由系统或第三方应用程序提供。在下面的屏幕截图中,您可以看到两个系统提供的规则以及第三方应用程序“Pixel Ambient Services”提供的“驾驶”规则。

DND rules

AutomaticZenRule是将您自己的规则集成到Android系统中的工具。要集成自己的规则,您需要按照以下大致步骤进行操作:
  1. Make sure that you have sufficient permissions to access the DND policy (android.permission.ACCESS_NOTIFICATION_POLICY). See NotificationManager.isNotificationPolicyAccessGranted() for details.
  2. 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>
    
  3. 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 NotificationManager.addAutomaticZenRule / updateAutomaticZenRule.

  4. After that, you can tell Android that the conditions for your rule are currently satisfied / not satisfied by calling NotificationManager.setAutomaticZenRuleState.


是的。您有它的示例,可以通过代码启用和禁用它吗?它需要权限吗? - android developer

1
从研究其他可用文档中,我能够在某种程度上理解禅模式(虽然这可能是我的版本而不是正确的版本)。
我的理解如下 -
禅模式是“请勿打扰”模式,在最新更新中可以自动启用,取决于诸如一天中的晚时间等因素。应用程序可以使用AutomaticZenrule,当处于请勿打扰模式时,它们的通知不会被屏蔽或抑制。
为此,您的应用程序应该通过将用户发送到匹配系统意图操作ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS的活动来请求策略访问。
如果用户已授予您的应用程序通知策略访问权限,则即使在请勿打扰模式下,您也将能够设置优先通知。因此,AutomaticZenrule对于说明应用程序的通知不被抑制起着至关重要的作用。
尽管我没有运行示例代码,但我认为它应该与启用设备管理员代码或请求使用情况权限的用例类似。
感谢您让我了解到新东西 :)

“请勿打扰”模式会改变通知的创建/显示方式吗?使用“AutomaticZenrule”会以某种方式改变它吗?以何种方式? - android developer
{btsdaf} - Neji
{btsdaf} - android developer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接