简体   繁体   中英

How to make my app device owner without NFC and ADB shell command?

I have an android app which is installed on 100+ devices. (Android 5.1.1 API22 and 6.0.1 API 23)

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.

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.

DevicePolicyManager deviceManger = (DevicePolicyManager)Forms.Context.GetSystemService(Context.DevicePolicyService); ComponentName demoDeviceAdmin = new ComponentName(Forms.Context, Java.Lang.Class.FromType(typeof(DeviceAdmin))); 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'

If you don't have any accounts set up, you can set it programmatically using 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

There are a few different ways you get take device owner of an Android Device. Depending on if the devices are owned by you or its a BYOD, you can use different methods. This table by Google summarizes all the possible ways you can take device ownership. You can find it here .

i have created a method MakeOwner() and called in the onCreate method my by lucky it worked well...

 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();
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM