简体   繁体   English

如何在没有 NFC 和 ADB shell 命令的情况下让我的应用程序设备所有者?

[英]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.

相关问题 使用adb shell dpm set-device-owner的无根设备(Android L)(无NFC)上的设备所有者 - Device owner on a nonrooted device (Android L), without NFC, using adb shell, dpm set-device-owner 如何让我的应用成为设备所有者? - How to make my app a device owner? 在Android Lollipop中不使用NFC的设备所有者 - Device Owner without using NFC in Android Lollipop 如何使用 adb shell 命令验证 android 设备屏幕开启或关闭 - How to verify android device Screen ON or OFF using adb shell command Android 设备:如何通过“adb shell cmd wifi”命令连接wifi? - Android device: How to connect wifi by "Adb shell cmd wifi" command? ADB shell 命令取消和删除我的应用程序中的所有作业 - ADB shell command to cancel and remove all jobs in my app 通过 adb shell 命令授予我的应用权限 - grant my app permission through adb shell command adb shell dpm set-device-owner与Unity问题 - adb shell dpm set-device-owner with Unity issue 由于设备上存在帐户,因此无法使用adb将应用设置为设备所有者 - set App to Device Owner using adb not working due to Accounts on device adb shell 命令查找设备内存 - adb shell command to find the device RAM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM