How to lock a device in android
<p>How to lock a android device or screen??. Here is my code.    </p>

<pre><code>public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    context = this;
    Button b = new Button(context);
    b = (Button)findViewById(R.id.button1);
    b.setOnClickListener(new OnClickListener() {
    @Override
      public void onClick(View v) {
       // TODO Auto-generated method stub
      System.out.println("inside button");
      PowerManager pManager = (PowerManager)                                                                                                                   
          getSystemService(Context.POWER_SERVICE);         
      PowerManager.WakeLock wl = pManager.newWakeLock(PowerManager.
            PARTIAL_WAKE_LOCK, "lock screen");                  
              wl.acquire();
              wl.release();

                }
            });
        }
</code></pre>

<p>Here I am using a button. when user clicks on then the screen should be lock. But this code is not working. Is have to use BraodCastRecievr??. I included this permmission in manifest</p>

<pre><code>&lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
</code></pre>

<p>But also not working</p>
