我想使用
但是当我调用
DevicePolicyManager
方法:setSecureSetting
。这个方法需要配置文件或设备所有者:
我的应用程序已经激活了设备管理员,因为当我调用由配置文件或设备所有者调用以更新Settings.Secure设置。
isAdminActive
时它返回true。但是当我调用
setSecureSetting
时,出现异常: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)
那么,如何在API上成为设备所有者? 我在http://developer.android.com/guide/topics/admin/device-admin.html或http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html中找不到相关信息。
我在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();
}