Company to develop a smart terminal, the device is preloaded with the software developed by the company, but in order to avoid user access to the Android system interface, this time we need to block the key, especially the home button, in the ordinary case, when we click the Home button, Back to our Android system, here, when we click on the Home button, let's return to our app's main interface.
In Android4.0 versions of Android devices, you can override the Onattachedtowindow method to achieve the effect of shielding the home button
@Override publicvoid Onattachedtowindow () { // TODO auto-generated method StubThis . GetWindow (). SetType (WindowManager.LayoutParams.TYPE_ Keyguard_dialog); Super . Onattachedtowindow (); }
However, it is not available on Android devices in the Android4.0 version, but just found another way to mask and rewrite the home button:
1 Public Static Final intflag_homekey_dispatched = 0x80000000;2 @Override3 protected voidonCreate (Bundle savedinstancestate) {4 Super. OnCreate (savedinstancestate);5 This. GetWindow (). SetFlags (flag_homekey_dispatched, flag_homekey_dispatched);//Key Code6 Setcontentview (r.layout.activity_main);7 }8 9 @OverrideTen Public BooleanOnKeyDown (intKeyCode, KeyEvent event) { One //TODO auto-generated Method Stub A if(Keyevent.keycode_home = =keycode) { -Toast.maketext (mainactivity. This, "HOME", Toast.length_short). Show (); - } the return Super. OnKeyDown (KeyCode, event); -}
That way you won't be able to go back to the desktop when you click the Home button again.
==
Home key Masking