阻止/禁用最近的应用程序按钮 [英] Block/disable recent apps button

查看:30
本文介绍了阻止/禁用最近的应用程序按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这里之前有人问过这个问题 Android 禁用最近的任务按钮就像在 SureLock 中,但由于那里的答案不起作用,也许有些人可以分享一些关于这个被遗忘的材料的光.

I know that this question was asked before here Android Disable Recent Task Button like in SureLock, but since the answer there is not working, maybe some can share some light on this forgotten mater.

我也试过:

private void closeRecents() {
     activ.sendBroadcast(new Intent("com.android.systemui.recent.action.CLOSE"));
     Intent closeRecents = new Intent("com.android.systemui.recent.action.TOGGLE_RECENTS");
     closeRecents.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
     ComponentName recents = new ComponentName(SYSTEM_UI_PACKAGE_NAME, RECENTS_ACTIVITY);
     closeRecents.setComponent(recents);
     activ.startActivity(closeRecents);
}

但没有运气

推荐答案

这个答案对我有帮助.它不是最好的,因为现在不推荐使用某些方法.它现在对我(4.4.2)有用,但我也想找到一个更理想的解决方案.

This answer helped me. It is not the best as some methods are now deprecated. It works for me (4.4.2), for now, but I too would like to find a more ideal solution.

    @Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    if (!hasFocus) {
        windowCloseHandler.postDelayed(windowCloserRunnable, 250);
    }
}

private void toggleRecents() {
    Intent closeRecents = new Intent("com.android.systemui.recent.action.TOGGLE_RECENTS");
    closeRecents.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    ComponentName recents = new ComponentName("com.android.systemui", "com.android.systemui.recent.RecentsActivity");
    closeRecents.setComponent(recents);
    this.startActivity(closeRecents);
}

private Handler windowCloseHandler = new Handler();
private Runnable windowCloserRunnable = new Runnable() {
    @Override
    public void run() {
        ActivityManager am = (ActivityManager)getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
        ComponentName cn = am.getRunningTasks(1).get(0).topActivity;

        if (cn != null && cn.getClassName().equals("com.android.systemui.recent.RecentsActivity")) {
            toggleRecents();
        }
    }
};

在此许可下:

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

这篇关于阻止/禁用最近的应用程序按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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