Deactivate App as Android administrator


I am wanting to deactivate my application as an administrator from Java by launching an Intent, since with the following code, it launches the Intent to Activate it

    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, angelDevicePolicyAdmin);
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,  "Administración del dispositivo");

I would like to launch this same activity but to deactivate it when activated, the inverse of the above But I do not see something that you do not contrary to this

asked by JDeveloper 13.07.2016 в 22:50

1 answer


Enter the name of the class of your device admin where this DeviceAdminSample this helps you to deactivate it:

public void disableDeviceAdmin() {
    ComponentName devAdminReceiver = new ComponentName(this, DeviceAdminSample.class);
    DevicePolicyManager dpm = (DevicePolicyManager) this.getSystemService(Context.DEVICE_POLICY_SERVICE);

To check if it is active, try:

public boolean isDeviceAdminEnabled() {
    DevicePolicyManager mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    ComponentName mAdminName = new ComponentName(this, DeviceAdminSample.class);
    return (mDPM != null && mDPM.isAdminActive(mAdminName));
answered by 21.07.2017 в 18:15