如何使用它的名字杀应用程序? [英] How to kill application using its name?

查看:92
本文介绍了如何使用它的名字杀应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法让从应用程序名包名? 对于例如,如果应用程序的名称是位置,我能得到它的包名com.android.location,这样我可以用它杀死。

Is there any way to get package names from application name ?? for e.g if app name is location , can I get its package name com.android.location, so that I can kill it using

am.killBackgroundProcesses(包名)

am.killBackgroundProcesses(package name)

或有人直接知道任何功能的使用应用程序名称将其杀死。任何其他建议?

or someone knows any function directly to kill using app name. any other suggestions ??

推荐答案

这将让所有正在运行的进程,并通过他们都找到一个具有指定名称和终止进程。

This will get all running process and go through all of them to find the one with the specified name and kill the process.

String nameOfProcess = "location";
ActivityManager  manager = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> listOfProcesses = manager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo process : listOfProcesses)
{
    if (process.processName.contains(nameOfProcess))
    {
        // Ends the app
        manager.restartPackage(process.processName);
        break;
    }
}

要使用此方法,您将需要以下权限:

To use this method, you will need the following permissions:

<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.RESTART_PACKAGES"/>

这篇关于如何使用它的名字杀应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆