我在广播接收器中的意图动作有一些问题,当警报在日志动作ALARM_ALERT输出中振铃时,但当我在我的手机Huawei Honor 5A上关闭警报时,我在日志ALARM_DONE中看不到动作。 注意:我在Android上的Genymotion上测试了这个代码,这个工作正常,但是在我的手机上安装MUI,也许这是问题?
public class BootReceiver extends BroadcastReceiver {
private static final String TAG = "LockScreen/BootReceiver";
@SuppressLint("WrongConstant")
@Override
public void onReceive(final Context context, Intent intent) {
String action = intent.getAction();
Log.e(TAG,"onReceive " + action);
//If the screen was just turned on or it just booted up, start your Lock Activity
if (action.equals("com.android.deskclock.ALARM_ALERT") ||
action.equals("com.android.deskclock.ALARM_SNOOZE"))
{
UserHolder.setRingState(true);
}
if(action.equals("com.android.deskclock.ALARM_DISMISS") ||
action.equals("com.android.deskclock.ALARM_DONE")) {
UserHolder.setRingState(false);
}
if (action.equals(Intent.ACTION_SCREEN_OFF)
|| action.equals(Intent.ACTION_SCREEN_ON)
|| action.equals(Intent.ACTION_BOOT_COMPLETED)) {
if (action.equals(Intent.ACTION_SCREEN_OFF)) {
//LockScreenService.service.stopForeground(true);
UserHolder.saveScreenOff(context);
}
Parameters parameters = Parameters.getFromDB();
if (!UserHolder.isAlarm() &&!UserHolder.callIsRunning()
&& UserHolder.isLogin() && parameters.getUserWidgetOnoff() == 1) {
Intent i = new Intent(context, LockScreenActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//i.addFlags(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY);
context.startActivity(i);
} else {
Logger.info("ignore onReceive " + action);
}
}
意图过滤器:
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_BOOT_COMPLETED);
filter.addAction("com.android.deskclock.ALARM_ALERT");
filter.addAction("com.android.deskclock.ALARM_SNOOZE");
filter.addAction("com.android.deskclock.ALARM_DISMISS");
filter.addAction("com.android.deskclock.ALARM_DONE");
清单:
<receiver
android:name=".receiver.BootReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="com.android.deskclock.ALARM_ALERT" />
<action android:name="com.android.deskclock.ALARM_SNOOZE" />
<action android:name="com.android.deskclock.ALARM_DISMISS" />
<action android:name="com.android.deskclock.ALARM_DONE" />
</intent-filter>
</receiver>