title: No active admin owned ... - locking a screen in Android
body: <p>I want to simply lock the screen. Here's what I did:</p>
  
  <pre><code>public class MainActivity : ActionBarActivity() {
      var dpm: DevicePolicyManager? = null
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
          dpm = getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
      }
  
      override fun onCreateOptionsMenu(menu: Menu?): Boolean {
          getMenuInflater()?.inflate(R.menu.menu_main, menu)
          dpm?.lockNow()
          return true
      }
  }
  </code></pre>
  
  <p>It's in Kotlin but those who Java will understand it.</p>
  
  <p>And manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="android.me.com.app123" &gt;
      &lt;uses-permission
          android:name="android.permission.USES_POLICY_FORCE_LOCK"&gt;
      &lt;/uses-permission&gt;
  
      &lt;application
          android:allowBackup="true"
  </code></pre>
  
  <p>The error is:</p>
  
  <pre><code>android.me.com.app123 E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: android.me.com.app123, PID: 22964
      java.lang.SecurityException: No active admin owned by uid 10121 for policy #3
              at android.os.Parcel.readException(Parcel.java:1472)
  </code></pre>
  
  <p>Haven't I gotten enough permissions when I said "android.permission.USES_POLICY_FORCE_LOCK"? If not how to fix it?</p>