首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么getCurrentInterruptionFilter BroadcastReceiver可以在快速设置中工作,而不能在设置中工作?

为什么getCurrentInterruptionFilter BroadcastReceiver可以在快速设置中工作,而不能在设置中工作?
EN

Stack Overflow用户
提问于 2018-12-27 17:27:31
回答 1查看 102关注 0票数 1

我有以下的广播接收器来掌握我的中断过滤器中的变化。

代码语言:javascript
复制
public class DndBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED);
        if (NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED.equals(intent.getAction())) {
            NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            assert mNotificationManager != null;
            if (mNotificationManager.getCurrentInterruptionFilter() == NotificationManager.INTERRUPTION_FILTER_NONE) {
                System.out.println("None");
            } else if (mNotificationManager.getCurrentInterruptionFilter() == NotificationManager.INTERRUPTION_FILTER_ALARMS) {
                System.out.println("Alarms");
            } else if (mNotificationManager.getCurrentInterruptionFilter() == NotificationManager.INTERRUPTION_FILTER_ALL) {
                System.out.println("All");
            } else if (mNotificationManager.getCurrentInterruptionFilter() == NotificationManager.INTERRUPTION_FILTER_PRIORITY) {
                System.out.println("Priority");
            } else if (mNotificationManager.getCurrentInterruptionFilter() == NotificationManager.INTERRUPTION_FILTER_UNKNOWN) {
                System.out.println("Unknown");
            }
        }
    }
}

当我切换快速设置免打扰按钮时,这真的很有效,但当我使用实际设置面板中的按钮打开或关闭免打扰时,没有检测到任何更改。为什么会这样,有什么显而易见的原因吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-27 19:05:52

好吧,这是因为我的广播接收器只有在我的应用程序在前台时才能工作。所以快速设置有效,但设置无效,因为我在设置屏幕上。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53942678

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档