Home key Masking

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.