How to programmatically lock screen in Android?

Mecid picture Mecid · Aug 29, 2010 · Viewed 37k times · Source

Possible Duplicate:
Lock the android device programatically

How can I programmatically lock the screen in Android?

Answer

YoK picture YoK · Aug 29, 2010

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()