Waking up device do not work

余生长醉 提交于 2019-12-02 11:27:07

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

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

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

    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("TAG");
    keyguardLock.disableKeyguard();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!