给楼主朋友提供另一种解决方式
就是使用
public void onPause(){
super.onPause();
};
这个事件处理

解决方案 »

  1.   

    HOME键你的收不到事件的。这个不用想了,除非你手机的BSP厂商在HOME键按下的时候,发了相应的broadcast。虽然系统的key code定义了HOME的值,但上层的APP是收不到的。
      

  2.   

    还有,这是android这样设计的,因为考虑到完全性,HOME就是直接回到lanucher,所以google认为通常不需要APP去做特别的事情。如果你实在想知道home键的事件处理,你可以参考系统的源码:
    Frameworks\base\policy\src\com\android\internal\policy\impl\PhoneWindowManger.java
    的interceptKeyBeforeDispatching方法。
    它有如下代码: if (mHomePressed) {
                
                // If we have released the home key, and didn't do anything else
                // while it was pressed, then it is time to go home!
                if (keyCode == KeyEvent.KEYCODE_HOME) {
                    if (!down) {
                        mHomePressed = false;
                        
                        if (!canceled) {
                            // If an incoming call is ringing, HOME is totally disabled.
                            // (The user is already on the InCallScreen at this point,
                            // and his ONLY options are to answer or reject the call.)
                            boolean incomingRinging = false;
                            try {
                                ITelephony telephonyService = getTelephonyService();
                                if (telephonyService != null) {
                                    incomingRinging = telephonyService.isRinging();
                                }
                            } catch (RemoteException ex) {
                                Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
                            }
            
                            if (incomingRinging) {
                                Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
                            } else {
                                launchHomeFromHotKey();
                            }
                        } else {
                            Log.i(TAG, "Ignoring HOME; event canceled.");
                        }
                    }
                }
      

  3.   

    感谢leehong2005 那么认真的回复!  
    但是现在我在android虚拟机上的确是可以在上层app捕获到home键的,但是在我自己的手机却不行
    我的手机的系统是自己刷上去的, 作者改了什么源码,我是不知道的。。 
    继续求指导!
      

  4.   

    这是android 系统4.0以后修改了源码,所以只要是系统4.0以后的不能够这样屏蔽home键,现在的修改方式为在
    ocreate()中的setContentView()后面添加
            Window win = getWindow();  WindowManager.LayoutParams lp = win.getAttributes(); 
            lp.flags |= 0x80000000;
            win.setAttributes(lp);
    在onkeydown()事件中添加
        if(event.getKeyCode() == KeyEvent.KEYCODE_HOME){
         return true;
        }