关闭 运行 个应用程序

Close running applications

我正在尝试关闭特定的 3 个应用程序(如果已在后台应用程序中打开)运行。 我试过这样

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    CloseApps();
}

private void CloseApps() {
    ActivityManager actvityManager = (ActivityManager)
            this.getSystemService(ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();

    for (ActivityManager.RunningAppProcessInfo runningProInfo : procInfos) {
        if (runningProInfo.processName.equals("com.aaa.aaaa")) {
            actvityManager.killBackgroundProcesses(runningProInfo.processName);
        }else if (runningProInfo.processName.equals("com.ccc.ccc")) {

            actvityManager.killBackgroundProcesses(runningProInfo.processName);
            }
        else if (runningProInfo.processName.equals("com.bbb.bbb.ad")){

            actvityManager.killBackgroundProcesses(runningProInfo.processName);
        }
    }
}

注意:我正在开发 android 7.1 版本。

我找到了这个问题的答案

private void CloseApps() {
    Process suProcess = null;
    try {
        suProcess = Runtime.getRuntime().exec("su");
        DataOutputStream dataOutputStream = new DataOutputStream(suProcess.getOutputStream());
        dataOutputStream.writeBytes("am force-stop com.aaaa.aaaa" + "\n");

 } catch (IOException e) {
        e.printStackTrace();
    }.