tags:

views:

69

answers:

1

Hi friends, I want to lock the screen through my program. i am using the following code to do the same..But its not working for me..I dont 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>
A: 

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

elevine
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..