Require a password to uninstall/remove application

I would like to require that a user type a password before being allowed to uninstall/remove my application. How can I implement this functionality?


Solution 1:

You could do this by:

  • The first time your app is installed, install a separate application/package ("watcher").
  • The only classes "watcher" contains is a BroadcastReceiver that listens for ACTION_PACKAGE_REMOVED
  • Add a BroadcastReceiver to your application that also listens for ACTION_PACKAGE_REMOVED
  • When a intent is broadcast to one of your receivers, check if the other component is still installed. If is isn't (the user just uninstalled it), prompt for the password - if it's wrong, reinstall the other component. If it's right, uninstall yourself.

Solution 2:

You can exec logcat and get the start activity intent information. You will find that before the uninstall activity is displayed, there is a text msg such as: Starting activity: Intent { act=android.intent.action.DELETE dat=package:com.comodo.pimsecure cmp=com.android.packageinstaller/.UninstallerActivity } then you can pop a activity ask for password now.

Solution 3:

It is possible. you can do it with DeviceAdminReceiver api. (i don't no how)

Solution 4:

This is a hard problem. I can think of at least one non-evil use-case for it.

e.g. Stolen Phone Recovery app - you wish to deter ne'er-do-wells from uninstalling the app.

In this case, I can think of two sensible assumptions which would stop me implementing what you're looking for:

  • the thief is unaware of your app, so will not try to uninstall it.
  • the thief is aware of your app, and switch it off until he can get it to an iron box* to re-install the OS.

* For the uninitiated: an iron box will prevent the device sending or receiving electromagnetic signals.

Of course, this answer amounts to You Ain't Going To Need It, though I suspect you have already thought this through.