如何禁用最近使用的应用对话框按钮

如何禁用最近使用的应用对话框按钮

本文介绍了如何禁用最近使用的应用对话框按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个配置文件启动:家长和孩子的孩子不能进入商店和设置。我使用的是平板电脑8。home键和访问最近的任务按钮将不会在状态栏中。我的问题,如果孩子获得最近的任务。他将能够访问的设置,所以我怎么能禁止访问最近的任务。我试过的的,但它并没有为我工作,我尝试:

I have a launcher with two profile: parent and child the child can not access to the store and settings. I am using a tablet 8". home button and access to recent tasks button are not in the status bar. My problem that if child access to recent tasks. He will be able to access to the settings. So how can I disable access to recent tasks. I tried the code given in disable access to recent tasks, but it didn't work for me. I tried:

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

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

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();
        }
    }
};

它躲到了访问,但它不是一个有效的解决方案。孩子可以访问到状态栏可以这么设置。

It hid the access, but it is not an effective solution. The child may access to the status bar so to settings.

推荐答案

我已经找到了最好的方法是做到这一点:

The best way I have found is to do this:

public class BaseActivity extends Activity {
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);

            Log.d("Focus debug", "Focus changed !");

        if(!hasFocus) {
            Log.d("Focus debug", "Lost focus !");

            Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
            sendBroadcast(closeDialog);
        }
    }
}// all credit goes here: http://www.juliencavandoli.com/how-to-disable-recent-apps-dialog-on-long-press-home-button/

这是不是我自己的code,但这只是从显示隐藏最近使用的应用列表。

This is not my own code, but this just hides the recent apps list from showing.

这篇关于如何禁用最近使用的应用对话框按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 05:18