title: Lock or turn off the screen programmatically
body: <p>I want to <strong>turn off</strong> / <strong>lock the screen</strong> of my device programmatically.</p>
  
  <p>For the moment, when I try :</p>
  
  <pre><code>DevicePolicyManager mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
  mDPM.lockNow();
  </code></pre>
  
  <p>I have this error :</p>
  
  <blockquote>
    <p>java.lang.SecurityException: No active admin owned by uid 10176 for policy #3</p>
  </blockquote>
  
  <p>This is my AndroidManifest.xml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="opteamit.com.belami" &gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
      &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;
      &lt;uses-feature android:name="android.hardware.location.gps" /&gt;
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/&gt;
      &lt;uses-permission android:name="android.permission.CAMERA"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
      &lt;uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /&gt;
  
      &lt;application...
  </code></pre>
  
  <p>What is wrong ?</p>