0

I have some problem with intent action in broadcast receiver, when alarm is ringing in log action ALARM_ALERT output, but when i off alarm on my phone Huawei Honor 5A, i don't see action in log ALARM_DONE. Notice: I test this code on Genymotion on Android, this work fine, but on my phone install MUI, maybe it's problem?

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

    }

Intent filter:

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

Manifest:

        <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>

0 Answers0