Possible Duplicate:
Lock the android device programmatically
I try to lock and unlock the screen by click on the button in android. Help me to complete the code. I used following code to lock screen but I face problem in unlocking.
     Window mywindow = getWindow();                  
     WindowManager.LayoutParams lp = mywindow.getAttributes();
     mywindow.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
     mywindow.setAttributes(lp);
     s=false;
  //   Log.w(LOG_TAG, "Screen goes off!");
     } else {
         lock.setImageResource(R.drawable.unlockicon);
     Window mywindow = getWindow();
     WindowManager.LayoutParams lp = mywindow.getAttributes();
     mywindow.clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
     mywindow.setAttributes(lp);
     s=true;