如何忽略android 3.0中“最近活动按钮”的按钮单击

我的问题是自我解释.
我搜索了很多,但找不到处理近期活动按钮点击的方法.
我想忽略来自android 3.0平板电脑状态栏的最近活动按钮的硬件按钮点击.

目前我到目前为止所尝试的是:

public boolean onKeyDown(int keyCode, KeyEvent event) {

       if(keyCode == KeyEvent.KEYCODE_BACK) 
       { 
              return true;
       }
       // in the same way I have written it for KEYCODE_HOME
}

你能告诉我应该写什么来处理最近的活动按钮吗?

提前感谢你. 🙂

编辑:这是我现在尝试过的. KEYCODE_APP_SWITCH无效.

public boolean onKeyDown(int keyCode, KeyEvent event) {
        Log.e("INSIDE", "LOCKDEMO");
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            Log.e("KEY EVENT", "BACK");
            return true;
        }
        if (keyCode == KeyEvent.KEYCODE_HOME) {
            Log.e("KEY EVENT", "HOME");
            return true;
        }
        if(keyCode == KeyEvent.FLAG_FROM_SYSTEM) {
            Log.e("KEY EVENT", "SYSTEM");
            return true;
        }
        if(keyCode == KeyEvent.FLAG_KEEP_TOUCH_MODE) {
            Log.e("KEY EVENT", "TOUCH MODE");
            return true;
        }
        if(keyCode == KeyEvent.FLAG_SOFT_KEYBOARD) {
            Log.e("KEY EVENT", "SoFT KEYBOARD");
            return true;
        }
        if(keyCode == KeyEvent.FLAG_VIRTUAL_HARD_KEY) {
            Log.e("KEY EVENT", "HARDWARE KEY");
            return true;
        }
        if(keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
            Log.e("KEY EVENT", "APP SWITCH");
            return true;
        }

        Log.e("KEY EVENT", "NOT HANDLED");
        return super.onKeyDown(keyCode, event);
    }

当我按下RecentAppBtn时,它甚至不打印最后一个Log语句,即事件未处理.

最佳答案
从偷看到文档,我认为KeyEvent.KEYCODE_APP_SWITCH是你正在寻找的.

但是,当您按下应用程序切换器时,您还可以使用KeyEvent.getKeyCode()-method(在事件参数上)查看触发了哪些键代码(以及是否有任何键被触发).

我玩了一段时间,我已经得出结论,这是不可能的.

KEYCODE_APP_SWITCH事件未传送到onKeyDown()dispatchKeyEvent().Ergo,它无法处理.

此外,您将在Android 4设备上遇到问题,因为KEYCODE_HOME-event也不再被分派到上述任何方法.查看文档:

Key code constant: Home key. This key is handled by the framework
and is never delivered to applications
.

似乎没有真正简单的方法来自己创建一个真正的锁屏.见这个讨论:Developing a custom lock screen

可以在默认锁定屏幕上显示一些自定义信息:Is there a way for me to show a customized message on the lock screen?

为了完整起见:在Android L中,您将能够“锁定应用程序中的用户”,因此您无需手动覆盖硬件密钥.这是relevant information

The L Developer Preview introduces a new task locking API that lets
you temporarily restrict users from leaving your app
or being
interrupted by notifications. This could be used, for example, if you
are developing an education app to support high stakes assessment
requirements on Android. Once your app activates this mode, users will
not be able to see notifications, access other apps, or return to the
Home screen, until your app exits the mode.

转载注明原文:如何忽略android 3.0中“最近活动按钮”的按钮单击 - 代码日志