首页 > 解决方案 > 以编程方式将包设置为设备所有者

问题描述

我知道命令"adb shell dpm set-device-owner pacakgename"

我想知道是否有一种方法可以在启动后以编程方式询问并设置一个应用程序的设备所有者

基本上与以下相反:

DevicePolicyManager.clearDeviceOwnerApp("com.package.something");

提前致谢!

标签: androidadministratorowner

解决方案


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.


推荐阅读