如何以编程方式杀死3,应用程序吗? [英] How to kill an 3rd-app programmatically?

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

问题描述

如何杀死一个应用程序在Android的?

  killPackageProcesses(services.get(我).baseActivity.getPackageName());
 

这是函数killPackageProcesses

 公共无效killPackageProcesses(字符串软件包名){
    INT PID = 0;
    ActivityManager AM =(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
    名单< ActivityManager.RunningAppProcessInfo>的PID =我
            .getRunningAppProcesses();
    的for(int i = 0; I< pids.size();我++){
        ActivityManager.RunningAppProcessInfo信息= pids.get(我);
        如果(info.processName.equalsIgnoreCase(软件包名)){
            PID = info.pid;
        }
    }
    android.os.Process.killProcess(PID);

}
 

这是行不通的。它是如何为其他应用程序工作? 该许可被写入。

 <使用-权限的Andr​​oid:名称=android.permission.KILL_BACKGROUND_PROCESSES/>
 

解决方案

您不能杀灭的Andr​​oid只是任何进程。从处理的文档 < /一>:

  

需要注意的是,虽然该API允许我们要求杀死任何进程   根据PID,内核还是会征收标准限制   其上的PID你实际上能杀死。通常,这只是意味着   运行呼叫者的包/应用程序和所有进程   通过该应用程序创建的其他程序;包共享一个共同的   UID也将能够杀死对方的过程。

另外请注意,你要求你的清单中的权限不工作,你觉得它的方式。按照文档 KILL_BACKGROUND_PROCESS

  

允许应用程序调用killBackgroundProcesses(字符串)。

How to kill an app in android?

killPackageProcesses(services.get(i).baseActivity.getPackageName());

this is the function killPackageProcesses

public void killPackageProcesses(String packagename) {
    int pid = 0;
    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> pids = am
            .getRunningAppProcesses();
    for (int i = 0; i < pids.size(); i++) {
        ActivityManager.RunningAppProcessInfo info = pids.get(i);
        if (info.processName.equalsIgnoreCase(packagename)) {
            pid = info.pid;
        }
    }
    android.os.Process.killProcess(pid);

}

It doesn't work. How does it work for other apps? The permission is written.

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

解决方案

You can't kill just any process in Android. From the documentation on Process:

Note that, though this API allows us to request to kill any process based on its PID, the kernel will still impose standard restrictions on which PIDs you are actually able to kill. Typically this means only the process running the caller's packages/application and any additional processes created by that app; packages sharing a common UID will also be able to kill each other's processes.

Also note that the permission you're requesting in your manifest doesn't work the way you think it does. According to the documentation, KILL_BACKGROUND_PROCESS:

Allows an application to call killBackgroundProcesses(String).

这篇关于如何以编程方式杀死3,应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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