how to wakeup android phone from sleep?

jiawen picture jiawen · Apr 14, 2014 · Viewed 11.9k times · Source

How to wakeup android phone from sleep (suspend to mem) programmably? I don't want to acquire any wakelock, which means the phone goes into "real" sleep with the cpu disabled. I guess I can use some kind of RTC (real time clock) mechanism?

Does anyone have any examples?

Thanks.

Answer

Sophia Taylor picture Sophia Taylor · Apr 14, 2014

In order to let the Activity wake up the device and not require a password/swipe, you only need to add a few flags. To get that, include to your code:

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 will wake up your App activity.