I want to use the DevicePolicyManager : setSecureSetting . This method is needed by the profile or device owner:
Called by the profile or device owners to update settings. Security Settings.
My application activated Device Admin because when I called isAdminActive , it returns true.
But when I called setSecureSetting , I got an 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 the owner of the device in the API? I can not 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 at 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 a message: 
source share