0

My application has a function that requires to return to LockScreen after pushing a button. Is there any way to switch to LockScreen automatically? Thanks.

Nguyen
  • 2,019
  • 1
  • 24
  • 31

3 Answers3

2

Try this

KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE); 
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE); 

For locking,

lock.reenableKeyguard();

and for disable lock,

lock.disableKeyguard()
kumar_android
  • 2,273
  • 1
  • 21
  • 30
0

Finally, I can recall LockScreen by calling recreateMe() call back function in KeyguardStatusViewManager

mCallback.recreateMe(null);

Nguyen
  • 2,019
  • 1
  • 24
  • 31
0

Do you want showing lockscreen when after pushing button?
If you want this, I will help you.
I tried this, finally I could this. First, button's onClickEvent is doing sleep.
After then, you try turn on screen your device.

First,

DevicePolicyManager dpm = ( DevicePolicyManager )getSystemService( DEVICE_POLICY_SERVICE ); 
dpm.lockNow();

this code make your device go to sleep for lock.
after,

wake = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "wakeLock");
wake.acquire();
wake.release();

this code make turn on screen your device.
This link help you.
How to call android default LockScreen?
you can try it!

Community
  • 1
  • 1
Amadas
  • 703
  • 1
  • 5
  • 10