问题
Hey guys I've a question and I have been looking for days to find a solution.
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");
回答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
回答2:
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.
回答3:
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();
}
}
来源:https://stackoverflow.com/questions/40359917/how-to-make-my-app-device-owner-without-nfc-and-adb-shell-command