开发者

How to kill application using its name?

Is there any way to get package names from application name ?? fo开发者_运维百科r 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(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"/>


There is no direct method of doing this. You can scan through all the packages, and get their application labels, and kill those whichever you wish.

PackageManager

There are quite a few methods which you can use for this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜