[英]How to make my app device owner without NFC and ADB shell command?
I have an android app which is installed on 100+ devices.我有一个安装在 100 多台设备上的 android 应用程序。 (Android 5.1.1 API22 and 6.0.1 API 23)
(Android 5.1.1 API22 和 6.0.1 API 23)
https://developer.android.com/reference/android/app/admin/package-summary.html https://developer.android.com/reference/android/app/admin/package-summary.html
I went through all these references but no luck.我浏览了所有这些参考资料,但没有运气。
Using the devicePolicyManager, I get the error: XXXXX App is not the device owner.使用 devicePolicyManager,我收到错误消息:XXXXX 应用程序不是设备所有者。
I know there is a way to get device owner by shell command (ADB), but I can't do that on all the devices individually via usb.我知道有一种方法可以通过 shell 命令 (ADB) 获取设备所有者,但是我无法通过 USB 在所有设备上单独执行此操作。
DevicePolicyManager deviceManger = (DevicePolicyManager)Forms.Context.GetSystemService(Context.DevicePolicyService);
DevicePolicyManager deviceManger = (DevicePolicyManager)Forms.Context.GetSystemService(Context.DevicePolicyService); ComponentName demoDeviceAdmin = new ComponentName(Forms.Context, Java.Lang.Class.FromType(typeof(DeviceAdmin)));
ComponentName demoDeviceAdmin = new ComponentName(Forms.Context, Java.Lang.Class.FromType(typeof(DeviceAdmin))); deviceManger.SetGlobalSetting(demoDeviceAdmin, "wifi_device_owner_configs_lockdown", "1");
deviceManger.SetGlobalSetting(demoDeviceAdmin, "wifi_device_owner_configs_lockdown", "1");
The source code says, 'Device owner can only be set on an unprovisioned device, unless it was initiated by “adb”, in which case we allow it if no account is associated with the device'源代码说, “设备所有者只能在未配置的设备上设置,除非它是由“adb”启动的,在这种情况下,如果没有与设备关联的帐户,我们将允许它”
If you don't have any accounts set up, you can set it programmatically using dpm:如果您没有设置任何帐户,则可以使用 dpm 以编程方式进行设置:
try {
Runtime.getRuntime().exec("dpm set-device-owner com.example.deviceowner/.MyDeviceAdminReceiver");
} catch (Exception e) {
Log.e(TAG, "device owner not set");
Log.e(TAG, e.toString());
e.printStackTrace();
}
Reference: http://florent-dupont.blogspot.fr/2015/01/android-shell-command-dpm-device-policy.html参考: http : //florent-dupont.blogspot.fr/2015/01/android-shell-command-dpm-device-policy.html
There are a few different ways you get take device owner of an Android Device.您可以通过几种不同的方式获取 Android 设备的设备所有者。 Depending on if the devices are owned by you or its a BYOD, you can use different methods.
根据设备是您拥有还是 BYOD,您可以使用不同的方法。 This table by Google summarizes all the possible ways you can take device ownership.
Google 的这张表格总结了您获取设备所有权的所有可能方式。 You can find it here .
你可以在这里找到它。
i have created a method MakeOwner() and called in the onCreate method my by lucky it worked well...我创建了一个方法 MakeOwner() 并在 onCreate 方法中调用,幸运的是它运行良好......
public void MakeOwner(){
try {
Runtime.getRuntime().exec("dpm set-device-owner com.exampledemo.parsaniahardik.scanbarcodeqrdemonuts/.BasicDeviceAdminReceiver");
} catch (Exception e) {
Log.e(TAG, "device owner not set");
Log.e(TAG, e.toString());
e.printStackTrace();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.