删除设备所有者Android
我是Java和Android开发人员中的新手,来自更多的c ++背景。我使用此问题创建了一个Kiosk / COSU应用程序作为指导。我使用
I'm quite new in Java and Android dev coming from a more c++ background. I've created a Kiosk/COSU app using this question as guidance. I set the app as device admin using
adb shell dpm set-device-owner ...../.AppAdminReceiver
我想在不恢复设备出厂设置的情况下禁用活动设备所有者。我已经尝试使用此
和其他几个,但似乎不起作用。代码已执行,但该应用仍然是设备所有者。我也尝试将 android:testOnly = true
添加到AndroidManifest.xml,然后使用 adb shell dpm remove-active-admin .. ... /。AppAdminReceiver
,如此处所示但出现错误
I'd like to disable the active device owner without factory resetting the device. I've tried programatically using questions like this
and a few others but it doesn't seem to work. The code executes but the app is still the device owner. I've also tried adding android:testOnly="true"
to the AndroidManifest.xml and then using adb shell dpm remove-active-admin ...../.AppAdminReceiver
as seen here but I get the error
java.lang.SecurityException:尝试删除非测试管理员ComponentInfo {.... AppAdminReceiver } 0
。
上一个链接中描述的方法在Android Oreo(我为其构建应用程序的操作系统)中似乎已弃用。
The method described in the previous link seems to be deprecated in Android Oreo which is the OS I'm building my app for.
如何在Oreo中删除设备所有者?只要我不需要将设备恢复出厂设置,我都不介意通过adb或以编程方式完成。
How can I remove the device owner in Oreo? I don't mind if it's done via adb or programmatically, as long as I don't need to factory reset the device.
我发现了以下激活设备所有者的方法
I have found following ways to activate a device owner
- QR码设置
- adb shell dpm set-device-owner命令
- NFC设置
激活后,设备所有者,您将无法从设置中停用它。
Once you have activated the device owner, you won't be able to deactivate it from settings.
有两种删除设备所有者的方法
There are two ways to remove a device owner
- 恢复出厂设置
-
第二个操作只能通过设备所有者的应用程序代码完成,如下所示
- Factory reset
The second can only be done from the device owner application code, it is as follows
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
devicePolicyManager.clearDeviceOwnerApp(this.getPackageName());
我在应用程序中创建了一个隐藏选项
I have created a hidden option in the application to run this.
**请注意,如果要添加此代码并运行应用程序以删除所有者特权,则应使用相同的密钥对应用程序进行签名。
**Please note that if you want to add this code and run the application to remove owner privileges, the application should be signed with the same key.