How do I lock the screen?
<p>I'm trying to create an app and I'm nearly complete. I have been trying to figure out how to either put the phone into sleep mode, which would also lock the screen or just lock the screen.</p>

<p>This is how I am currently trying to accomplish this using the PowerManager.</p>

<pre><code>try{
            PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
            PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "FACEDOWN_LOCK");
            wl.acquire();
                // ? Perform operations
                pm.goToSleep(SystemClock.uptimeMillis());
            wl.release();
        }catch(Exception e){
             Toast.makeText(this, e.getMessage() , 10000).show();
        }
</code></pre>

<p>This does NOT work. It gives me permission problems even though my app is signed and I have the permissions enabled in the manifest.xml</p>

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

<p>Is there a proper way to do this? Can it even be done? Any help would be awesome. I have not been able to find any solution as to how you get the phone to lock or go to sleep.</p>
