Reputation: 2123
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.
Upvotes: 0
Views: 325
Reputation: 703
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!
Upvotes: 0
Reputation: 2123
Finally, I can recall LockScreen by calling recreateMe() call back function in KeyguardStatusViewManager
mCallback.recreateMe(null);
Upvotes: 0
Reputation: 2263
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()
Upvotes: 2