Android 需要密码才能卸载/删除应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1221534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Require a password to uninstall/remove application
提问by arams
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?
我想要求用户在被允许卸载/删除我的应用程序之前输入密码。如何实现此功能?
回答by Isaac Waller
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.
- 第一次安装你的应用程序时,安装一个单独的应用程序/包(“观察者”)。
- “观察者”包含的唯一类是一个广播接收器,它监听
ACTION_PACKAGE_REMOVED
- 将 BroadcastReceiver 添加到您的应用程序中,该应用程序也侦听
ACTION_PACKAGE_REMOVED
- 当一个意图被广播到你的一个接收器时,检查另一个组件是否仍然安装。如果不是(用户刚刚卸载它),提示输入密码 - 如果错误,重新安装其他组件。如果正确,请自行卸载。
回答by Mikonos
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.
您可以执行 logcat 并获取启动活动意图信息。你会发现在显示卸载活动之前,有一个文本msg如: Starting activity: Intent { act=android.intent.action.DELETE dat=package:com.comodo.pimsecure cmp=com.android.packageinstaller/ .UninstallerActivity } 然后你现在可以弹出一个活动要求输入密码。
回答by Sujith Manjavana
It is possible. you can do it with DeviceAdminReceiver
api. (i don't no how)
有可能的。你可以用DeviceAdminReceiver
api来做。(我不知道如何)
回答by jamesh
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 boxwill 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.
当然,这个答案相当于你不需要它,尽管我怀疑你已经考虑过了。
回答by kutu kepik
Protect installing/uninstalling apps by password makes Android more secure from malware/viruses. Your Android become as secure as iPhone.
通过密码保护安装/卸载应用程序使 Android 更安全,免受恶意软件/病毒的侵害。您的 Android 变得像 iPhone 一样安全。
How it works:
这个怎么运作:
Automatic apps installing is prompted to user. You can search the app name. If not secure, Block it.
Root access is prompted to user. Too many ads is an indicator that access is dangerous.
系统会提示用户自动安装应用程序。您可以搜索应用程序名称。如果不安全,请阻止它。
系统会提示用户进行 Root 访问。太多的广告表明访问是危险的。