How can I programmatically turn off screen in android?
<p>I want to turn off the screen when the user clicks a button. I am trying to do it with PowerManager class but I don't obtain good results. What is the best way to turn off the screen in android?.</p>

<p>I am using the code below:</p>

<blockquote>
<pre><code>    PowerManager pm = (PowerManager)this.getSystemService(
            Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(
            PowerManager.PARTIAL_WAKE_LOCK,
            "");
    wl.acquire();
</code></pre>
</blockquote>

<p>But only work this code:</p>

<blockquote>
<pre><code>    WindowManager.LayoutParams params = getWindow().getAttributes();
    params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
    params.screenBrightness = 0;
    getWindow().setAttributes(params);
</code></pre>
</blockquote>

<p>But, this code only set brightness to 0 but no turns off the screen.</p>

<p>Thanks a lot.</p>