Is it possible to programmatically deactivate a (third-party) Device Administrator app?
I was able to retrieve all the apps with Device Administrator activated using the DevicePolicyManager and getActiveAdmins():
final DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
final List<ComponentName> adminList = dpm.getActiveAdmins();
for ( ComponentName app : adminList ) {
Log.d(TAG, "App: ", app.getPackageName());
}
However, in order to deactivate them, I cannot use removeActiveAdmin(...), since it won't remove a component that is not my own app.
I was thinking to use an Intent and startActivity() in order to open the Device Administrator's deactivation page of that specific component I want to deactivate. Is it possible?
No. It is not possible to programmatically activate one, either.
There is no entry point in the Settings app to directly go to the remove-a-device-admin screen, let alone a documented
Intent
action for it. You can add device administrators this way, but not remove them.actually, it is possible to go directly to the admin screen, but i'm not sure how safe it is, as the API itself isn't available and the paths might change over different android versions and roms.
here's what i've tested:
this will go directly to the activate/de-activate screen of the app you choose:
this will go to the list of admin apps:
if anyone has a more official ,safer way to do it, please write it down.
those are quite risky, so you could first use this method:
you can add try-catch for each of the methods, and if all failed , use:
This should work:
You'll need to add this in manifest in your activity intent filter: