Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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");

like image 853
Guest Avatar asked Mar 10 '23 18:03

Guest


1 Answers

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

like image 193
Steve Miskovetz Avatar answered May 12 '23 05:05

Steve Miskovetz