Android SecurityException: Admin does not own the profile

lyc001 picture lyc001 · Mar 30, 2015 · Viewed 10k times · Source

I have a device manager application and I am trying to use setScreenCaptureDisabled(..) function of DevicePolicyManager class available since API 21.

DevicePolicyManager pManager = (android.app.admin.DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
pManager.setScreenCaptureDisabled(admin.getReceiverName(), true);

I am getting the following error:

03-30 13:50:24.623: E/AndroidRuntime(11564): 
java.lang.SecurityException: Admin 
ComponentInfo{com.example.xxv/com.example.xxv.DeviceAdminReceiver} 
does not own the profile

Any idea how I can solve this problem?

If there is any permission required, can you please indicate what it is.

Answer

Jonathan Twite picture Jonathan Twite · Feb 8, 2017

Your app needs to become either the device owner or profile owner. The easiest way to do this for one device is to use adb as here:

http://florent-dupont.blogspot.co.uk/2015/01/android-shell-command-dpm-device-policy.html

Basically from a command prompt

adb shell 
dpm set-device-owner com.foo.deviceowner/.DeviceAdminRcvr

where com.foo.deviceowner is your app package, and DeviceAdminRcvr is the DeviceAdminReceiver in your package. Note that you will get a java.lang.IllegalStateException unless you have removed all accounts from the device (Settings > Accounts).

The other method is to create a NFC provisioning app as:

https://source.android.com/devices/tech/admin/provision.html