Start Activity screen even if screen is locked in Android

You need the following permission in AndroidManifest.xml file:

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

Check the manifest details here. You can check this link on you query.


You can achieve this in two ways:

  1. using wake lock as explained by @Yup in this post.

  2. using window flags.

Using window flags:

Open the Activity A which you want to start in onReceive(...). Paste this in onCreate() of that Activity A

final Window win= getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

Make sure you're not pasting it before setContentView(...) :-)