I am working on a app in which I have to lock and unlock the screen programmatically. Kindly help ! I have no any idea how to develop this type of functionality which support each version of Android OS.
Android screen lock/ unlock programmatically [duplicate]
Asked Answered
Check out this post. It may help you. [Lock/Unlock Screen][1] [1]: https://mcmap.net/q/372695/-how-to-display-activity-when-the-screen-is-locked –
Capitalization
check github.com/amirarcane/lock-screen –
Almost
To Unlock
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
final KeyguardManager.KeyguardLock kl = km .newKeyguardLock("MyKeyguardLock");
kl.disableKeyguard();
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
wakeLock.acquire();
worked for me. but deprecated method warnings appear. –
Corinnacorinne
Worked like Zalo app, Viber app ... Really good. –
Rabassa
@Barend Not working on Android 4.4 also What should I do to lock the device? –
Candelariacandelario
Both are depreciated. –
Dioptrics
Does not work with encrypted device running marshmallow, but worked on non-Encrypted device running lollipop. –
Perchloride
Doesn't work on Nougat (7.0) with secure screen lock. –
Hornbook
Very very nice. –
Linalinacre
On Android 7.1.1 (OnePlus 3) it sets screen on but doesn't disable (fingerprint protected) screen guard –
Lorenzoloresz
This link might help you solve your Problem :
Unlock and Lock Programmatically
//Get the window from the context
WindowManager wm = Context.getSystemService(Context.WINDOW_SERVICE);
//Unlock
Window window = getWindow();
window.addFlags(wm.LayoutParams.FLAG_DISMISS_KEYGUARD);
//Lock device
DevicePolicyManager mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
With short content in your link, you can paste here in case that page die. –
Liebfraumilch
@Nicaea PL check this –
Bogus
This unlock does not work on 4.4.4, the other answer worked. Though with tons of depreciated calls. –
Compare
non of these answer work for 4.4 –
Rohrer
© 2022 - 2024 — McMap. All rights reserved.