============ Problem Description ============
I want to apply pop-up dialog box, the program runs in the background, when the condition is reached after the dialog box and the vibration and ringing, but in the lock screen state but did not respond, what is the solution?
============ Solution 1============
Unlock Keyguardmanager manager = (Keyguardmanager) getsystemservice (Keyguard_service); Manager.inkeyguardrestrictedinputmode ()) {//In lock interface, interface is unlocked by Keyguardlock class method Keyguardlock Keyguard = Manager.newkeygu Ardlock (Getlocalclassname ()); Keyguard.disablekeyguard ();}
Unlock requires permission:
<uses-permission android:name= "Android.permission.DISABLE_KEYGUARD"/>
Light the screen powermanager pm = (powermanager) getsystemservice (power_service); mwakelock = Pm.newwakelock ( Powermanager.acquire_causes_wakeup | Powermanager.screen_dim_wake_lock, "Simpletimer"); Mwakelock.acquire ();//.......mwakelock.release ();
To light the screen requires permission:
<uses-permission android:name= "Android.permission.WAKE_LOCK"/>
============ Solution 2============
According to LS method request Force open Lock, there will be press power key, the system will not enter sleep phenomenon
Refer to the following method to have the dialog box appear above the lock screen
The OnCreate method is used
Requestwindowfeature (Window.feature_no_title); Hide Title
Window win = GetWindow ();
Windowmanager.layoutparams winparams = Win.getattributes ();
Winparams.flags |= (WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
Setrequestedorientation (0);
Use when Onresume
protected void Onresume () {
Super.onresume ();
Acquirewakelock ();
}
private void Acquirewakelock () {
if (Mwakelock = = null) {
LOG.I (TAG, "Activity begin Start");
PowerManager pm = (powermanager) getsystemservice (Context.power_service);
Mwakelock = Pm.newwakelock (Powermanager.screen_dim_wake_lock, This.getclass (). Getcanonicalname ());
Mwakelock.acquire ();
}
In OnPause
protected void OnPause () {
Super.onpause ();
......
Releasewakelock ();
}
private void Releasewakelock () {
if (Mwakelock! = null && Mwakelock.isheld ()) {
Mwakelock.release ();
Mwakelock = null;
}
Hope that the LZ has helped!
How do I make a pop-up dialog box in Android with a lock screen and vibrate and ring like an alarm clock?