Disable Android Application Uninstallation using Device Administration

Android platform offers system-level device management capabilities through the Device Administration APIs. If an application package component is registered as system administrator, it can provide device administration features at the system level. An active system admin package can not be uninstalled until removed as system administrator. We will make benefits of this property to disable android application uninstallation by registering and activating system admin component.

 Sample Application




In AndroidManifest.xml,
1. We need to declare a receiver which will subclass DeviceAdminReceiver.
2. Permission attribute should be declared with value android.permission.BIND_DEVICE_ADMIN
3. meta-data tag defining device admin policies usage.
4. intent-filter for admin enable, admin disable and admin disable request.

Create file /res/xml/device_admin.xml, this file will define system label capabilities granted on activation. I have not defined any policies as out motto is to just register and activate a system admin to make our application not uninstallable. Just to brief I have mentioned type of policy management you can be granted.

Create receiver class SampleDeviceAdminReceiver.java and it will extend DeviceAdminReceiver. We will override few functions to get admin enable and disable status.

Create a class PolicyManager.java, we will define api to check admin active status and removing admin component.

In our main layout /res/layout/activity_main.xml, we will add two buttons to activate and deactivate admin.

In application’s launcher activity MainActivity.java in sample app, we will implement View.OnCLickListener to handle onclick events of buttons. For activation of admin, we need to start activity with intent action as DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN. And to specify admin component we will add extars with Key as DevicePolicyManager.EXTRA_DEVICE_ADMIN. You can attach admin activation explanation as well so that user know your intention to do it.

Once you enable admin component from your package, your application can not be uinstalled until it is deactivated. It can be verified by uninstalling it or in application info. No other application can remove your active component from there source, it can be removed only if call is from package which is owner of this admin component.

Once you disable this admin, your application can be uninsatlled.

Many applications featuring enterprise management or application lock apps use this feature. Option is provided to user to enable this feature. Though a sophisticated android user can always activate/deactiavte your active system admin from Settings->Security->Device Administrators.

You may also like...

  • Menashe Ungar

    I am working on a sort of simplified MDM for my company, but the fact that a user can disable an administrator so simply makes all this stuff unusable. Is there a way for a device company owned to prevent this?

  • mgodot

    555555,not work in android 6.0,