Require a password to uninstall/remove application

前端 未结 5 1203
悲&欢浪女
悲&欢浪女 2020-11-27 15:41

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?

5条回答
  •  青春惊慌失措
    2020-11-27 16:30

    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.

提交回复
热议问题