我有以下的广播接收器来掌握我的中断过滤器中的变化。
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");
}
}
}
}当我切换快速设置免打扰按钮时,这真的很有效,但当我使用实际设置面板中的按钮打开或关闭免打扰时,没有检测到任何更改。为什么会这样,有什么显而易见的原因吗?
发布于 2018-12-27 19:05:52
好吧,这是因为我的广播接收器只有在我的应用程序在前台时才能工作。所以快速设置有效,但设置无效,因为我在设置屏幕上。
https://stackoverflow.com/questions/53942678
复制相似问题