Android SecurityException:管理员不拥有配置文件

lyc*_*001 6 android android-activity android-securityexception android-5.0-lollipop

我有一个设备管理器应用程序,并且尝试使用自API 21起可用的DevicePolicyManager类的setScreenCaptureDisabled(..)函数。

DevicePolicyManager pManager = (android.app.admin.DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
pManager.setScreenCaptureDisabled(admin.getReceiverName(), true);
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

知道如何解决这个问题吗?

如果需要任何许可,请说明一下。

Jon*_*ite 5

您的应用必须成为设备所有者或配置文件所有者。对一台设备执行此操作的最简单方法是使用adb,如下所示:

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
Run Code Online (Sandbox Code Playgroud)

这里com.foo.deviceowner是您的应用程序包,DeviceAdminRcvrDeviceAdminReceiver在你的包。请注意,java.lang.IllegalStateException除非您从设备(Settings> Accounts)中删除了所有帐户,否则您将获得一个。

另一种方法是将NFC设置应用程序创建为:

https://source.android.com/devices/tech/admin/provision.html


AAD*_*ing -1

您是否正确注册为DeviceAdminReceiver

根据此处的Android 文档,调用设备管理员必须是设备或配置文件所有者。如果不是,将会抛出安全异常。

从日志中可以清楚地看出您不拥有该个人资料!