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.
I have found following ways to activate a device owner
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
The second can only be done from the device owner application code, it is as follows
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.
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