Android - How can I wake up the phone from a hard sleep to take a picture?

人走茶凉 提交于 2019-11-28 06:36:43

I have finally gotten somewhere now.

I have to create a wakelock using these two flags

PowerManager.SCREEN_BRIGHT_WAKE_LOCK|PowerManager.ACQUIRE_CAUSES_WAKEUP

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK|PowerManager.ACQUIRE_CAUSES_WAKEUP, "bbbb");
wl.acquire();

Then the device wakes up, and starts at the keyguard screen.

But the only way I can get past the keyguard screen and take a picture is to use these flags on the Activity's window:

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
    | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
    | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

But this is only available with Android 2.0, and doesn't work in 1.6.

You can also disable the Keyguard screen with

KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
km.newKeyguardLock(TAG).disableKeyguard();

provided you have the DISABLE_KEYGUARD permission.

That's available since API Level 1.

Are you doing something like this in your onResume method

.... onResume() {
    ....
    WakeLock myWakeLock = .....;
    ...
}

If so, as soon as the method exits, the WakeLock is released, and the device is free to do whatever it feels like doing ( which is likely to go back to sleep ) and you will need to store the WakeLock in the class somewhere, not as a function local.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!