简体   繁体   English

防止用户杀死Android上的应用程序

[英]Preventing user from killing an application on Android

I am trying to figure out how I can prevent a user from killing an application using force-stop. 我试图弄清楚如何防止用户使用强制停止功能杀死应用程序。 I am trying to detect when user opens an activity such as Settings-Applications-Manage Applications and tries to force-stop a protected app. 我试图检测用户何时打开活动(例如“设置”-“应用程序”-“管理应用程序”)并尝试强制停止受保护的应用程序。 Also there are some task manager apps that allow you to kill processes. 另外,还有一些任务管理器应用程序可让您终止进程。

I know it is possible in Android, since apps like AppLock or Super AppLock do it. 我知道这在Android中是可能的,因为诸如AppLock或Super AppLock之类的应用程序都可以做到这一点。 I just can't find any information on how to do it. 我只是找不到有关如何执行操作的任何信息。

Right now I am trying to poll ActivityManager.RunningTaskInfo to detect the restricted activities, however that does not work well as they have different names on different devices. 现在,我正在尝试轮询ActivityManager.RunningTaskInfo以检测受限制的活动,但是,由于它们在不同设备上具有不同的名称,因此无法正常工作。

Is there a better way to do it? 有更好的方法吗? How do AppLock and similar apps implement this functionality? AppLock和类似的应用程序如何实现此功能?

Quite similar and relevant question was already asked and replied. 已经提出并回答了很多类似和相关的问题

Long story in short, no you cannot prevent user or the operating system to kill your application off due to memory management. 简而言之, 您不能阻止用户或操作系统由于内存管理而杀死您的应用程序。

I think I figured it out. 我想我知道了。

Using ActivityManager.getRunningTasks() function seems to be the best solution. 使用ActivityManager.getRunningTasks()函数似乎是最好的解决方案。 Then you just need to pop-up an Activity (with pin code) every time the top task is "com.android.settings.applications.RunningServiceDetails" or "com.android.settings.applications.InstalledAppDetails". 然后,您只需在每次首要任务是“ com.android.settings.applications.RunningServiceDetails”或“ com.android.settings.applications.InstalledAppDetails”时弹出活动(带有密码)即可。

Unfortunately, there is no way to see if the user is trying to kill a protected application or some other application, so the access is restricted to all of them. 不幸的是,无法查看用户是否试图杀死受保护的应用程序或某些其他应用程序,因此访问仅限于所有应用程序。

There are also a bunch of task managers on the market that use ActivityManager.killBackgroundProcesses() method to kill the process, but you can bring the app back to life by using alarms. 市场上还有很多任务管理器,它们使用ActivityManager.killBackgroundProcesses()方法终止进程,但是您可以通过使用警报使应用程序恢复活力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM