Deactivate App as Android administrator

0

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");
    startActivity(intent);

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

DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN
    
asked by JDeveloper 13.07.2016 в 22:50
source

1 answer

1

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);
    dpm.removeActiveAdmin(devAdminReceiver);
}

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