在Android中如何禁用近期任务/应用程序按钮 [英] How to disable the Recent Tasks/Apps button in Android

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

问题描述

我要建为Android孩子玩的应用程序。我需要禁用所有键时,它正在使用中。 我已经设置了应用程序作为家庭应用和残疾人的返回键(即取主页和返回按钮的照顾)。 为了明确近期任务列表中的我已经创建虚拟Activites其启动,然后完成应用程序启动时的列表。虚拟Activites如下:

I'm building a child play application for Android. I need to disable all keys when it is in use. I have set the Application as the Home App and disabled the back key (that takes care of the Home and Back button). In order to clear the recent tasks list I've created a list of Dummy Activites which start and then finish when the application starts. The Dummy Activites look like:

public class Dummy1 extends Activity
{
  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
   finish();
}
}

然后在我的onCreate应用我执行:

And then in my onCreate of the application I perform:

this.pm.setComponentEnabledSetting(new ComponentName(this, Dummy1.class),   PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

Intent localIntent1 = new Intent(this, Dummy1.class);
localIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(localIntent1); 

这需要当有人试图按住Home键显示最近的任务,我创建了这8照顾,他们都是空的,所以用户无法点击更改应用程序。

This takes care of when someone tries to hold the Home key to display the recent tasks as I create 8 of these and they're all empty so the user can't click to change apps.

现在唯一的按钮,我似乎不能禁用的近期任务/应用程序按钮(mainlyon HTC设备,即一个X,一个S,等)。此按钮似乎依然带来了所有的近期任务(即使是在我的虚拟任务),我似乎无法找到一个钩的时候该按钮pressed被解雇的事件?任何帮助或建议,将不胜AP preciated。

Now the only button I can't seem to disable is the "Recent Tasks/Apps" button (available mainlyon HTC devices, ie. One X, One S, etc). This button seems to still bring up all the recent tasks(even though my dummy tasks were created) and I can't seem to find a "hook" for the event that is fired when this button is pressed? Any help or suggestions would be greatly appreciated.

注:我知道这是做,能够既然喜欢ToddlerLock应用程序都做到了....我只是似乎无法弄清楚

Note: I know it's do-able since apps like ToddlerLock have done it....I just can't seem to figure it out.

在此先感谢!

推荐答案

这将关闭RecentActivity对话框。把它放在你的活动课。

This will close the RecentActivity dialog. Put it in your activity class.

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

您需要把下面的许可,您的清单。

You will need to put the following permission in your manifest.

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

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

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