Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically lock screen in Android? [duplicate]

Possible Duplicate:
Lock the android device programatically

How can I programmatically lock the screen in Android?

like image 989
Mecid Avatar asked Aug 29 '10 11:08

Mecid


People also ask

How do you double lock the screen?

Double-Tap to Lock and Unlock Android This feature can also be used to lock your phone—double-tap to lock, double-tap to unlock. Alternatively, if double-tapping your screen to lock and unlock your Android still isn't working, you can use a third-party app like Screen Off.


2 Answers

Check this class : com.android.internal.policy.impl.LockScreen

Referenced from here: Can you lock screen from your app?

Also check code for enabling and disabling lock Screen in Android. (Referenced from here)

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

For locking the screen use,

lock.reenableKeyguard();

and for disabling the lock use,

lock.disableKeyguard()
like image 113
YoK Avatar answered Oct 20 '22 18:10

YoK


In order to do this you need to use the Device Administration API that was added in (I think) 2.2. Once your app is registered on the device as a device administrator, you can then use DevicePolicyManager.lockNow() to lock the screen. The DeviceAdmin sample application in the SDK is a good place to look as well.

like image 32
Adam Avatar answered Oct 20 '22 18:10

Adam