杀死在Android上其他应用程序? [英] Kill another application on Android?

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

问题描述

我试图杀死我的其他应用程序。但是,这code是不能杀我的另一个应用程序。我知道杀了另一个应用程序是一个坏主意。但我有一个学习的目的,我已经试图杀死。我的code部分:

I am try to kill my another application. But this code is not able to kill my another application. I know to kill another application is a bad idea. But I have a learning purpose, and I have tried to kill. My code part:

Button runningApp = (Button) findViewById(R.id.runningApp);
runningApp.setOnClickListener(new View.OnClickListener()
{
    @Override
    public void onClick(View v)
    {
        String nameOfProcess = "com.example.filepath";
        ActivityManager  manager = (ActivityManager)ApplicationActivity.this.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> listOfProcesses = manager.getRunningAppProcesses();
        for (ActivityManager.RunningAppProcessInfo process : listOfProcesses)
        {
            if (process.processName.contains(nameOfProcess))
            {
                Log.e("Proccess" , process.processName + " : " + process.pid);
                android.os.Process.killProcess(process.pid);
                android.os.Process.sendSignal(process.pid, android.os.Process.SIGNAL_KILL);
                manager.killBackgroundProcesses(process.processName);
                break;
            }
        }
    }
});

我已经添加权限,它们是:

I have added Permissions, and they are:

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

我每次可以看到的 LogCat中的,特定的应用程序运行在后台。我在哪里弄错了?

Every time I can see the LogCat, the particular application is running in the background. Where am I mistaken?

推荐答案

您只能杀死一个过程,具有相同的用户ID作为一个正在做杀。如果你试图杀死你自己的过程中,它应该工作。否则,你不能做到这一点(除非你有一个根深蒂固的设备和您的应用程序具有超级用户权限)。

You can only kill a process that has the same userID as the one that is doing the killing. If you are trying to kill your own process it should work. Otherwise you can't do it (unless you have a rooted device and your application has root priviledges).

这篇关于杀死在Android上其他应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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