简体   繁体   English

为什么getCurrentInterruptionFilter BroadcastReceiver可以通过“快速设置”而不是“设置”工作?

[英]Why does getCurrentInterruptionFilter BroadcastReceiver work from Quick Settings but not from Settings?

I have the following Broadcast Receiver to get hold of the changes in my Interruption Filter. 我具有以下广播接收器,以掌握中断过滤器中的更改。

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");
            }
        }
    }
}

This works really well when I toggle the Quick Settings DND button, but when I turn DND on or off using the button in the actual Settings panel, no change is detected. 当我切换“快速设置”免打扰按钮时,这确实非常好,但是当我使用实际“设置”面板中的按钮打开或关闭免打扰时,未检测到更改。 Is there any obvious reason why this might be? 有什么明显的原因可能会这样吗?

Ok, this is because my Broadcast Receiver only works when my app is in the foreground. 好的,这是因为我的广播接收器仅在我的应用程序位于前台时才起作用。 So quick settings works, but not settings because I am on the settings screen. 因此快速设置有效,但设置无效,因为我在设置屏幕上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM