我正在使用以下代码来终止后台应用程序(计算器)。为此,我在运行应用程序时创建了一项服务。它没有杀死后台进程(计算器)我也给予许可的代码有什么问题。"android.permission.KILL_BACKGROUND_PROCESSES"
ActivityManager am = (ActivityManager) getApplicationContext().getSystemService(Activity.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> packageName = am.getRunningTasks(10);
// String packageName = am.getRunningTasks(1).get(0).topActivity.getPackageName();
for (RunningTaskInfo appinfo : packageName)
{
if((appinfo.topActivity.getPackageName().toString()).indexOf("calculator2")!= -1)
{
Log.i(Tag,""+ appinfo.topActivity.getPackageName());
Toast.makeText(MyService.this, ""+appinfo.topActivity.getPackageName(), Toast.LENGTH_SHORT).show();
am.killBackgroundProcesses(appinfo.topActivity.getPackageName());
}
}