安卓拦截最新的应用程序按钮 [英] android intercept recent apps button

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

问题描述

我的意思为儿童的应用程序,我不希望他们能够点击最近的应用程序按钮(就是那个看起来像在彼此的顶部的两个矩形)。我照顾捕获后退按钮和主屏幕按钮和我搜索并阅读了很多关于关于设法捕捉到最近的应用程序按钮,但大多数说你不能或者他们做到这一点是非常值得怀疑的。

I have an application meant for children and I do not want them to be able to click the "Recent Apps" button (the one that looks like two rectangles on top of each other). I am taking care of capturing the back button and the home button and I have searched and read a lot about about trying to capture the Recent Apps button, but most say you cannot or the way they do it is very questionable.

应用程序孩子的地方会弹出一个观点,说:操作不允许,并重定向到它,如果你preSS的最新应用程序键,如果你是在一个不同的应用程序,这个工程即使主屏幕,所以他们是怎么做的呢?

The App "Kids Place" pops up a view that says "Action Not Allowed" and redirects you to its home screen if you press the Recent Apps button, this works even if you are in a different app, so how are they doing this?

任何建议,提示将AP preciated。

Any suggestions, hints would be appreciated.

感谢。

推荐答案

在很多搜索和编码,我发现目前最好的解决方案是这样的:

After lots of searching and coding the current best solution I found is the following:

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

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

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

这需要您使用<使用-权限的Andr​​oid:名称=android.permission.GET_TASKS/>

在使用这种方法,当用户presses最近的应用程序按钮,它会导致你的活动将通过活动的生命周期如下:在onPause - > onWindowFocusChanged - > onResume。

When using this approach when the user presses the recent apps button it will cause your activity will go through the activity lifecycle as follows: onPause -> onWindowFocusChanged -> onResume.

要用户的行为看来,pressing最近应用程序按钮没有反应。注:我发现,如果你preSS最近的应用程序按钮快速地将显示该视图短暂的时间。

To the user the behavior appears that pressing the recent apps button has no response. NOTE: that I have found that if you press the recent apps button quickly it will display that view for brief time.

这是不是最好的解决方案,但它是一个刺吧。如果你有一个更好的解决方案,请分享。

This is not the best solution, but it is a stab at it. If you have a better solution please share.

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

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