Wake Android Device up

The question:

Hey i need to wake my sleeping android device up at a certain time.
Any suggestions?

P.S. Wake up: turn display on and maybe unlock phone

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

To wake up the screen:

PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");

To release the screen lock:

KeyguardManager keyguardManager = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE); 
KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("TAG");

And the manifest needs to contain:

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />

For more details about PowerManager, refer to the API documentation: http://developer.android.com/reference/android/os/PowerManager.html

EDIT: this answer is reported as deprecated.

Method 2

Best is to use some appropriate combination of these window flags:


If you want to run on older versions of the platform that don’t support the desired flag(s), you can directly use wake locks and keyguard locks… but that path is fraught with peril.

ONE IMPORTANT NOTE: Your activity must be full screen in order for the above flag combination to work. In my app I tried to use these flags with an activity which is not full screen (Dialog Theme) and it didn’t work. After looking at the documentation I found that these flags require the window to be a full screen window.

Method 3

I found a way and it is not that complex… works on any API version.

You need to use PowerManager.userActivity(l, false) method and register your activity as broadcast received for SCREEN_OFF intent:

In your actiivity OnCreate put something like:

mReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
        Log.v(TAG, "Screen OFF onReceive()");
        screenOFFHandler.sendEmptyMessageDelayed(0, 2000L);

It will kick off the handler after 2 seconds of Screen Off event.

Register receiver in your onResume() method:

IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
registerReceiver(mReceiver, filter);
Log.i(TAG, "broadcast receiver registered!");

Create a handler like the one below:

private Handler screenOFFHandler = new Handler() {

    public void handleMessage(Message msg) {

        // do something
        // wake up phone
        Log.i(TAG, "ake up the phone and disable keyguard");
        PowerManager powerManager = (PowerManager) YourActivityName.this
        long l = SystemClock.uptimeMillis();
        powerManager.userActivity(l, false);//false will bring the screen back as bright as it was, true - will dim it

Request permission in your manifest file:

<uses-permission android:name="android.permission.WAKE_LOCK" />

Do not forget to unregister broadcast receiver when you are done. You may do that in onDestroy() for example (which is not guaranteed)

Log.i(TAG, "broadcast UNregistred!");

Method 4

If you are showing a window when waking up, you can get it working easily by adding few flags to your activity, without using a wake lock.

protected void onCreate(Bundle savedInstanceState) {
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

Method 5

On newer devices you should use something like this, since the mentioned Flags are deprecated.

class AlarmActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {


        // Keep screen always on, unless the user interacts (wakes the mess up...)


        (getSystemService(KeyguardManager::class.java) as KeyguardManager).requestDismissKeyguard(this,
            object: KeyguardManager.KeyguardDismissCallback(){
                override fun onDismissCancelled() {
                    Log.d("Keyguard", "Cancelled")

                override fun onDismissError() {
                    Log.d("Keyguard", "Error")

                override fun onDismissSucceeded() {
                    Log.d("Keyguard", "Success")

KeyguardManager.requestDismissKeyguard only wakes up the device, if the setter setTurnScreenOn(true) was called before.

I tested this on my Android Pie device.

Method 6

Try with the below code after setContentView(R.layout.YOUR_LAYOUT); in activity onCreate() method

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
        Log.d(TAG, "onCreate: set window flags for API level > 27");
                        | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        KeyguardManager keyguardManager = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
        keyguardManager.requestDismissKeyguard(this, null);
    } else {
        Log.d(TAG, "onCreate: onCreate:set window flags for API level < 27");
                        | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                        | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                        | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                        | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

Method 7

Settling an alarm programatically will wake up the phone(play a sound) and i guess the turn on display would be an option there.

I donot think there would be an exposed API that will unlock the phone automatically.

Method 8


will dismiss the general keyguard and cause the device to unlock.

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment