Remove Device Owner Android

2019-06-04 01:31发布

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

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: Attempt to remove non-test admin ComponentInfo{....AppAdminReceiver} 0.

The method described in the previous link seems to be deprecated in Android Oreo which is the OS I'm building my app for.

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.

标签: java android adb
2条回答
smile是对你的礼貌
2楼-- · 2019-06-04 02:12

I have found following ways to activate a device owner

  1. QR code provisioning
  2. "adb shell dpm set-device-owner" command
  3. NFC provisioning

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

  1. Factory reset
  2. 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.

查看更多
劳资没心,怎么记你
3楼-- · 2019-06-04 02:32

You can do it in settings. Just open settings and type "admin" in the search box. Then select "Device admin apps", click on your app and "Deactivate this device admin app"

Alternative way to that page might be Apps & Notifications -> Scroll down and select Advanced -> Special app access -> Device admin apps

查看更多
登录 后发表回答