Reputation: 508
I tried to execute the following code to set my app as a device owner. I can't use ADB because I have more than 10K android-9 non rooted devices. So, Need to do this programmatically.
String name = AdminReceiver.class.getName();
if (name.startsWith(BuildConfig.APPLICATION_ID)) {
name = name.substring(BuildConfig.APPLICATION_ID.length());
}
final String command = "dpm set-device-owner " + BuildConfig.APPLICATION_ID + '/' + name;
Process process = Runtime.getRuntime().exec(command);
Log.d(TAG,"RETURN VALUE:"process.waitFor();
process.waitFor() always return 1.
Upvotes: 0
Views: 1094
Reputation: 4524
Use QR Enrollment instead!
You can generate a QR Code which contains a URL for your Device Owner package. Then you can scan this code in the factory setup process of the device.
The Data in the QR Code would look something like this:
{
"android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME": "com.google.android.apps.work.clouddpc/.receivers.CloudDeviceAdminReceiver",
"android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM": "I5YvS0O5hXY46mb01BlRjq4oJJGs2kuUcHvVkAPEXlg",
"android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION": "https://play.google.com/managed/downloadManagingApp?identifier=setup"
}
Simply replace the information with your own device owner package information. After scanning, the device will download, install, and set up the device owner.
If you become an EMM Partner with Google, you can even do Zero-Touch-Enrollment by getting preconfigured android devices from the manufacturers. But Google stopped approving requests for custom device policy managers and you must use the Android Management API now.
Footnotes
Upvotes: 1
Reputation: 1006539
Need to do this programmatically
Fortunately, that is not possible, for blindingly obvious security reasons.
Upvotes: 4