Question

In my application I have option (checkbox) to enable/disable device admin programatically, it works when I have admin disabled and try to enable it, but when I disable it, what it does is, disables the device admin without prompting for deactivation window to ask for deactivation. Now what I need is to do it the right way, I want application to show proper screen asking for deactivate device admin. I have following code snippet taken from android developer site,

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    if (isChecked) {
        // Activate device administration
        Intent intent = new Intent(
                DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceAdmin);
        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                "Activate service to get access");
        startActivityForResult(intent, ACTIVATION_REQUEST);
    } else {
        try {
            devicePolicyManager.removeActiveAdmin(deviceAdmin);
            isAdminActive = false;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Was it helpful?

Solution 2

This is not possible AFIK. This is right of user.

API will always show a dialog for confirmation about DE-activation of Device Admin

Although EDM APIs gives a way where you can do silent DE-activation of Device administrator. So user can not see the UI of deactivation of particular Device admin. But EDM APIs are not easily available, they are for commercial uses.

OTHER TIPS

This should work

   ComponentName devAdminReceiver = new ComponentName(context, DeviceAdminReceiver.class);
   DevicePolicyManager dpm = (DevicePolicyManager)context.getSystemService(Context.DEVICE_POLICY_SERVICE);
   dpm.removeActiveAdmin(devAdminReceiver);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top