设备管理员API,如何成为设备所有者?

7
我想使用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.htmlhttp://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();
}

我收到了消息:在此输入图片描述

1个回答

3
成为设备所有者有两种可能性:

dpm set-device-owner:将给定组件设置为活动管理员,并将其包设置为设备所有者。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接