From: http://zhifeiji512.iteye.com/blog/1055358
1. Add this section in ActivityCodeYou can block the Home Key (the home key is captured in the onkeydown event ).
Public void onattachedtowindow () {This. getwindow (). settype (windowmanager. layoutparams. type_keyguard); Super. onattachedtowindow ();}
2.Because the Android system processes the power key with the Home Key in phonewindowmanager, it will not return to the upper-layer application. The following is the system source code:
\ Frameworks \ Policies \ base \ phone \ com \ Android \ internal \ Policy \ impl \ phonewindowmanager. java 1089 line if (code = keyevent. keycode_home) {// if a system window has focus, then it doesn' t make sense/right now to interact with applications. windowmanager. layoutparams attrs = win! = NULL? Win. getattrs (): NULL; If (attrs! = NULL) {final int type = attrs. type; If (type = windowmanager. layoutparams. type_keyguard | type = windowmanager. layoutparams. type_keyguard_dialog) {// The "app" is keyguard, so give it the key return false;} final int typecount = window_types_where_home_doesnt_work.length; For (INT I = 0; I <typecount; I ++) {If (type = window_types_where_home_doesnt_work [I]) {// don't do anything, but also don't pass it to the app return true ;}}}
Type =
Windowmanager. layoutparams. in the type_keyguard clause, we can see that android has made a special judgment on the screen lock, so I simulate this implementation. The only difference is that the onattachedtowindow () method in the activity requires more than 5 APIs.