Android – show activity even if the phone is in locked mode
How can I wake an Android device up and skip the ScreenLock
I want to display a dialog box from the broadcast receiver, but the Android API doesn't allow me to do so, so I use to start an activity from there and change the theme of this activity to theme
Now I want to display this activity even if the phone is in lock mode / sleep mode
Screen I can use the following flag to open Bu, but I have to unlock the key guard manually. I can't see my window on the lock screen
The difference is that I don't use full screen activity, i.e
android:theme="@android:style/Theme.Dialog
In my code I'm using
Window w = getWindow();
w.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
resolvent:
I didn't successfully implement this function by using these flags, but I succeeded by using wakelock and keyguardlock. The following is my work:
public class DismissLock extends Activity {
PowerManager pm;
WakeLock wl;
KeyguardManager km;
KeyguardLock kl;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Log.i("INFO", "onCreate() in DismissLock");
pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
km=(KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
kl=km.newKeyguardLock("INFO");
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP|PowerManager.ON_AFTER_RELEASE, "INFO");
wl.acquire(); //wake up the screen
kl.disableKeyguard();// dismiss the keyguard
setContentView(R.layout.main);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
wl.release(); //when the activiy pauses, we should realse the wakelock
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
wl.acquire();//must call this!
}
}
Of course, you still need to declare permissions in the manifest file
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>