Unable to set device owner through programmatically

大兔子大兔子 提交于 2020-12-16 03:32:08

问题


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.


回答1:


Need to do this programmatically

Fortunately, that is not possible, for blindingly obvious security reasons.




回答2:


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.

See the documentation here

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

  • Instructions on how to scan the QR Code
  • Device Admin Developer reference for streamlining this into the device admin app


来源:https://stackoverflow.com/questions/61078268/unable-to-set-device-owner-through-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!