I'm aware of the command "adb shell dpm set-device-owner pacakgename"
I want to know if there's a way to programmatically ask and set device owner for one app after it's launched
basically the opposite of :
DevicePolicyManager.clearDeviceOwnerApp("com.package.something");
Thanks in advance!
You can only set the device owner if there is no user account on the device, or the device is rooted. This normally means you can only set the device owner immediately after a factory reset. You can set the device owner using NFC provisioning (I've never done this) or in an adb
shell. The adb
method requires the user to enable developer mode, connect the Android device to a computer, and type a command into the shell.
Pseudocode for becoming the device owner:
if the app is not the device owner
if there is a user account
inform the user that the app cannot become the device owner
else if the app is a device administrator
instruct the user to run the adb command
else
request to become a device administrator
My Device Owner app is a complete working example, including how the command that the user must type is generated from the app's package name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With