0

Possible Duplicate:
Lock the Android device programmatically

Does the application have the ability to lock the screen? I have tried the following code, but nothing happens.

KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.reenableKeyguard();
Cœur
  • 37,241
  • 25
  • 195
  • 267
Kakey
  • 3,936
  • 5
  • 29
  • 45

1 Answers1

0

Your code looks fine and it should work..

Have you included the required permission in android manifest file.

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

And for further reference, If you want the source code for screen lock implementation, then please check this question posted in stackoverflow and a link from android developer site.

Source of Android's lock screen

http://developer.android.com/guide/topics/admin/device-admin.html

http://developer.android.com/reference/android/app/KeyguardManager.KeyguardLock.html

Community
  • 1
  • 1
Krishna
  • 1,454
  • 5
  • 16
  • 31
  • @ Krishna I want to lock a screen when we click on a button i use the above keyguard code and i gave the permisssion .But i did not got anything can u suggest me – Pinki Aug 03 '11 at 05:07
  • @ Pinki Same code worked for me in android 1.5, I don't know about how it works in later versions.. and moreover could you please elaborate on what problem you got when trying this... – Krishna Aug 03 '11 at 05:31