I want to simply lock the screen. Here's what I did:
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
}
}
It's in Kotlin but those who Java will understand it.
And manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.me.com.app123" >
<uses-permission
android:name="android.permission.USES_POLICY_FORCE_LOCK">
</uses-permission>
<application
android:allowBackup="true"
The error is:
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)
Haven't I gotten enough permissions when I said "android.permission.USES_POLICY_FORCE_LOCK"? If not how to fix it?