-1

如果已经在后台应用程序中打开并运行,我正在尝试关闭特定的 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 版本。

4

1 回答 1

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();
    }.
于 2018-01-18T05:22:01.533 回答