1

Possible Duplicate:
Lock the Android device programmatically

I want to lock the screen through my program. I am using the following code to do the same..But it's not working for me..I don't know where I am wrong..even I am not getting any errors in logcat..I am using 1.6

public class KeyGaurd extends Activity {
KeyguardManager keyguardManager;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
     keyguardManager = 
        (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);

        KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE); 

        lock.reenableKeyguard();
}

And I used the permission also

<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>
Cœur
  • 37,241
  • 25
  • 195
  • 267
user455422
  • 47
  • 1
  • 4

1 Answers1

0

Your code would lock the keyboard, not the device. Try using the lockNow method in DevicePolicyManager.

Eric Levine
  • 13,536
  • 5
  • 49
  • 49
  • HI elevine...Is any other way to do this..?or can u share sample code using DevicePolicyManager.?I am new to android..Its some what difficult for me to understand at this point.. – user455422 Sep 25 '10 at 04:43