我正在关注此tutorial将应用程序设置为设备所有者。在该教程中,有一节“使用adb设置设备所有者”。这里的教程说明在安装Kiosk模式演示应用程序后,运行以下命令:
adb shell dpm set-device-owner sdg.example.kiosk_mode/.AdminReceiver
这给了我错误:
adb server is out of date. killing...
* daemon started successfully *
java.lang.IllegalStateException: Not allowed to set the device owner because there are already several users on the device
at android.os.Parcel.readException(Parcel.java:1629)
at android.os.Parcel.readException(Parcel.java:1574)
at android.app.admin.IDevicePolicyManager$Stub$Proxy.setDeviceOwner(IDevicePolicyManager.java:5146)
at com.android.commands.dpm.Dpm.runSetDeviceOwner(Dpm.java:114)
at com.android.commands.dpm.Dpm.onRun(Dpm.java:82)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
at com.android.commands.dpm.Dpm.main(Dpm.java:38)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:257)
我跟着这个SO link和Diego Plascencia Lara的答案帮助我摆脱了
adb server is out of date. killing...
* daemon started successfully *
但是在运行adb shell dpm set-device-owner sdg.example.kiosk_mode/.AdminReceiver
命令后仍然发生以下错误:
java.lang.IllegalStateException: Not allowed to set the device owner because there are already several users on the device
at android.os.Parcel.readException(Parcel.java:1629)
at android.os.Parcel.readException(Parcel.java:1574)
at android.app.admin.IDevicePolicyManager$Stub$Proxy.setDeviceOwner(IDevicePolicyManager.java:5146)
at com.android.commands.dpm.Dpm.runSetDeviceOwner(Dpm.java:114)
at com.android.commands.dpm.Dpm.onRun(Dpm.java:82)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
at com.android.commands.dpm.Dpm.main(Dpm.java:38)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:257)
为什么会发生此错误,如何删除?我之前曾尝试将不同的应用程序设置为设备所有者,但我认为我没有设法完全取消它们,并且在完成使应用程序在设备上运行的整个过程时总会出现一些错误。
没有工厂重置设备,有一种解决这个问题的方法。只需从设备中删除所有帐户(在“设置” - >“帐户”中)。您可能希望在执行此操作之前同步数据,以便以后可以还原它们。删除所有帐户后,将手机连接到计算机并运行命令:
adb shell dpm set-device-owner sdg.example.kiosk_mode/.AdminReceiver
如果你收到这样的消息:
Success: Device owner set to package ComponentInfo{org.bluetooth.bledemo/org.bluetooth.bledemo.AdminReceiver}
Active admin set to component {org.bluetooth.bledemo/org.bluetooth.bledemo.AdminReceiver}
认为自己成功了。现在,您可以添加先前删除的所有帐户。
另一种方式:正如Steve Miskovetz在答案中所指出的,出厂重置是将应用设置为设备所有者的方法之一,如果之前您的手机有帐户(例如Gmail帐户)。但在Android和/或某些手机的最新版本中,在重置工厂后,除非您设置了Google帐户,否则他们不允许继续前进。因此,为了解决此问题,请继续注册您的Google帐户,当您的手机恢复正常可操作状态时,请通过设置 - >帐户删除该帐户。现在你所需要的只是enable developer mode and then USB debugging。之后,将手机连接到计算机并运行命令adb shell dpm set-device-owner sdg.example.kiosk_mode/.AdminReceiver
。
这篇文章对dpm命令给出了很好的概述:http://florent-dupont.blogspot.fr/2015/01/android-shell-command-dpm-device-policy.html
在帖子的末尾附近,添加了此更新:“设备所有者只能在未设置的设备上设置,除非它是由”adb“启动的,在这种情况下,如果没有帐户与设备关联,我们会允许它”源代码。因此,在使用dpm命令之前,请确保您没有与当前用户集关联的任何帐户(如Gmail)“
我建议您在执行恢复出厂设置后使用dpm安装和设置应用程序,在没有设置任何帐户的情况下通过Google向导,从设置中启用开发人员模式,最后启用“USB调试”...如果这是可行的选项为了你...