Skip to content Skip to sidebar Skip to footer

Waking Up Device Do Not Work

I used this code to wake up my device (Moto G 1 gen) when screen is off, but it seems that it doesn't work. It works only when screen is on. edit: Now it works, but CallScreen.clas

Solution 1:

ELAPSED_REALTIME_WAKEUP will only power on the CPU, and that only until onReceive() of your BroadcastReceiver returns.

So:

  1. The CPU may fall asleep again before your activity appears, as startActivity() is asynchronous, and onReceive() will return before startActivity() really begins its processing

  2. ELAPSED_REALTIME_WAKEUP does not turn on the screen, which you appear to want

  3. ELAPSED_REALTIME_WAKEUP does not unlock the device, which you appear to want

Solution 2:

Okay, I got it. Seems to me that FLAGS don't do their job properly so the beef is after setContentView:

PowerManager.WakeLock wl
...
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN |
                    WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
                    WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                    WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN |
                    WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
                    WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                    WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.activity_call_screen);

    PowerManagerpm= (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "My Tag");
    wl.acquire();

    KeyguardManagerkeyguardManager= (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLockkeyguardLock= keyguardManager.newKeyguardLock("TAG");
    keyguardLock.disableKeyguard();

Post a Comment for "Waking Up Device Do Not Work"