除了NFC以外,实际上还有一种方法是将应用程序设置为设备所有者应用程序。
您可以使用adb shell中的dpm命令行工具。
用法:
usage: dpm [subcommand] [options]
usage: dpm set-device-owner
usage: dpm set-profile-owner
dpm set-device-owner: Sets the given component as active admin, and its package as device owner.
dpm set-profile-owner: Sets the given component as active admin and profile owner for an existing user.
更新:dpm实用程序实际上很简单。其目标是在引用Device / Profile所有者应用程序的/data/system/device_owner.xml下创建一个名为device_owner.xml的新文件。
然后,Android平台正在阅读此文件,以检查哪个应用程序被视为设备所有者或配置文件所有者应用程序。
在根深蒂固的设备上,您可能确实是create this file by yourself,但由于dpm工具正在做,您最好使用它(DRY原则):
例如通过Runtime.exec()命令:
Runtime.getRuntime().exec("dpm set-device-owner com.foo.deviceowner/.DeviceAdminRcvr");
另请注意,只有在用户没有设置帐户(确保在“设置>帐户”中没有设置任何帐户)之前,此工具才有效。