sabato 20 febbraio 2016

How to remove Android apps that you can't uninstall

My Android app Turn off screen is used every day by thousands of people. The app allows the user to turn off the screen of the device and put it on standby, extending physical power button lifetime. It needs the Device Administrator API in order to work properly, so when a user uses my app for the first time he has to make turn off screen a device Administrator app. This operation is quite simple and fast, but it makes the app apparently unremovable. In fact when we try to delete a device Administrator app the remove button is disabled:

Fortunatly the solution is simple, we have to deactivate the device administrator right of the app. These are the steps we need: go to the settings, and navigate to security

Then select Device administrators

Tap on Turn off screen to deactivate the device administrator right

Finally tap on deactivate

At this point the uninstall button is enabled, so we can remove the app

In order to make this operation faster I put in the main activity of my app an uninstall option, which automatically deactivates the administrator device and shows the uninstalling activity.