我试图杀死我的另一个应用程序。但是这段代码无法杀死我的另一个应用程序。我知道杀死另一个应用程序是一个坏主意。但我有一个学习的目的,我曾试图杀人。我的代码部分:
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;
}
}
}
});
我添加了权限,它们是:
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.GET_TASKS" />
每次我看到LogCat时,特定的应用程序都在后台运行。我错在哪里?