还有,这是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); }
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.");
}
}
}
但是现在我在android虚拟机上的确是可以在上层app捕获到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;
}