【发布时间】:2023-03-27 17:55:01
【问题描述】:
我想使用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 级别 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();
}
【问题讨论】:
标签: android