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 :
To programmatically set a package as the device owner, you need to use the Android Device Policy API. The following code shows how to do it programmatically:
In the code above, you need to create a
DeviceAdminReceiverclass and override the
onEnabledmethod. In the
onEnabledmethod, you can use the
DevicePolicyManagerclass to set the device owner.
After creating the class, you need to declare it in the
device_admin_receiver.xmlfile should look like this:
DeviceOwnerReceiverclass is declared and the device owner is set, your app can run as the device owner.