7

I want to use DevicePolicyManager method: setSecureSetting. This method need profil or device owner:

Called by profile or device owners to update Settings.Secure settings.

My application has activated Device Admin because when I called isAdminActive it returns true.

But when I called setSecureSetting I got exception:

E/DevicePolicyUtility( 9901): java.lang.SecurityException: Admin ComponentInfo{com.xxxx/com.xxxx.MyDeviceAdminReceiver} does not own the profile
E/DevicePolicyUtility( 9901):   at android.os.Parcel.readException(Parcel.java:1546)
E/DevicePolicyUtility( 9901):   at android.os.Parcel.readException(Parcel.java:1499)
E/DevicePolicyUtility( 9901):   at android.app.admin.IDevicePolicyManager$Stub$Proxy.setSecureSetting(IDevicePolicyManager.java:4300)
E/DevicePolicyUtility( 9901):   at android.app.admin.DevicePolicyManager.setSecureSetting(DevicePolicyManager.java:3399)

So, how to be a device owner on API ? I don't find in http://developer.android.com/guide/topics/admin/device-admin.html or http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html


I try this on API Level 23:

Intent intent = new Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE);
intent.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,ctx.getPackageName());
if (intent.resolveActivity(ctx.getPackageManager()) != null) {
    ctx.startActivity(intent);
} else {
    Toast.makeText(ctx, "Stopping.", Toast.LENGTH_SHORT).show();
}

And I got message:enter image description here

LaurentY
  • 7,495
  • 3
  • 37
  • 55

1 Answers1

3

To become a device owner, there's 2 possibilities

dpm set-device-owner: Sets the given component as active admin, and its package as device owner.

Thanks to Florent Dupont: http://florent-dupont.blogspot.fr/2015/01/android-shell-command-dpm-device-policy.html

LaurentY
  • 7,495
  • 3
  • 37
  • 55