0

Possible Duplicate:
Lock the android device programatically

I was trying to lock phone using a application,

I have tried the following code, but no use,I inserted user permissions too.

KeyguardManager manager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
KeyguardLock lock = manager.newKeyguardLock("hh");
lock.disableKeyguard();
lock.reenableKeyguard();

Please suggest me a code to lock the phone.

Community
  • 1
  • 1
  • Please refer to following link : http://stackoverflow.com/questions/4545079/lock-the-android-device-programatically – Mohanish Mar 09 '12 at 14:10

1 Answers1

0

Add this permission in AndroidManifest.xml file

<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/> 

and

KeyguardManager mgr = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE); 
KeyguardLock lock = mgr.newKeyguardLock(KEYGUARD_SERVICE); 
lock.reenableKeyguard();
Ant4res
  • 1,217
  • 1
  • 18
  • 36
Pradeep Sodhi
  • 2,135
  • 1
  • 19
  • 19