Android SecurityException:管理员不拥有配置文件 [英] Android SecurityException: Admin does not own the profile
问题描述
我有一个设备管理器应用程序,我正在尝试使用自API 21起可用的DevicePolicyManager类的setScreenCaptureDisabled(..)函数.
I have a device manager application and I am trying to use setScreenCaptureDisabled(..) function of DevicePolicyManager class available since API 21.
DevicePolicyManager pManager = (android.app.admin.DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
pManager.setScreenCaptureDisabled(admin.getReceiverName(), true);
我遇到以下错误:
03-30 13:50:24.623: E/AndroidRuntime(11564):
java.lang.SecurityException: Admin
ComponentInfo{com.example.xxv/com.example.xxv.DeviceAdminReceiver}
does not own the profile
有什么办法可以解决这个问题吗?
Any idea how I can solve this problem?
如果需要任何许可,请说明一下.
If there is any permission required, can you please indicate what it is.
推荐答案
您的应用需要成为设备所有者或配置文件所有者.对一台设备执行此操作的最简单方法是使用adb,如下所示:
Your app needs to become either the device owner or profile owner. The easiest way to do this for one device is to use adb as here:
http://florent-dupont.blogspot.co.uk/2015/01/android-shell-command-dpm-device-policy.html
基本上在命令提示符下
adb shell
dpm set-device-owner com.foo.deviceowner/.DeviceAdminRcvr
其中 com.foo.deviceowner
是您的应用程序包,而 DeviceAdminRcvr
是您程序包中的 DeviceAdminReceiver
.请注意,除非您从设备中删除了所有帐户( Settings
> Accounts
),否则您将得到一个 java.lang.IllegalStateException
.
where com.foo.deviceowner
is your app package, and DeviceAdminRcvr
is the DeviceAdminReceiver
in your package. Note that you will get a java.lang.IllegalStateException
unless you have removed all accounts from the device (Settings
> Accounts
).
另一种方法是将NFC设置应用程序创建为:
The other method is to create a NFC provisioning app as:
https://source.android.com/devices/tech/admin/Provision.html
这篇关于Android SecurityException:管理员不拥有配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!