Android 4.0 disable System Home key

Source: Internet
Author: User

2.2 Disable the System home key, not here to say.

Recent projects have a requirement to disable all keys for the system, like menu, home, back. Also, if you want to click the response and view pop-up. Is that the UI part is normal.

Back key our own onkeydown disabled good happy.

Personally think the simplest wording, please visit:

http://blog.csdn.net/yiding_he/article/details/38527813


The key here is to disable the system home key after 4.0.

On the internet for a long time, basically it is not available. Because it's all about system security, the Android system absorbs the event (Home,menu) at the framework level and is not distributed to the application layer at all.

The Menu key can ' t be disabled for security reasons, this key is handled by the framework and is never delivered to Applic Ations.

http://stackoverflow.com/questions/15459407/disable-home-button-in-android-4-0

See, the Foreigner's stack overflow said there is no way.

As I approached the disappointment, casually entered a search page in a big God's github,https://github.com/shaobin0604/android-homekey-locker, casually downloaded to try, unexpectedly work.

More importantly, the great God is our Chinese. It's too bull.


Worship, here does not dwell on how the great God is realized, the secret is to build a overlaydialog, give it set some parameters like flag_show_when_locked,flag_not_touch_modal and so on.

Students who want to study, please download the source code to learn.

Here are just a few words to use:

1. To Https://github.com/shaobin0604/Android-HomeKey-Locker, download the Code of the Great God.

The Homekeylocker.java in 2.HomeLockLib is placed under its own util package.

Overlaydialog related portions of styles in 3.HomeLockLib are copied to their styles.

4. Join in your own androidmanifest

< uses-permission android:name="Android.permission.SYSTEM_ALERT_WINDOW"/>

5. New Homekeylocker object where you want to lock the key.

Private Homekeylocker Mhomekeylocker;mhomekeylocker = new Homekeylocker ();


After that, you need to use the LOCK key:

Mhomekeylocker. Lock (mactivity. this);

Unlock using:

Mhomekeylocker.unlock ();

6. In your own Destroy method, add:

@Overrideprotected void OnDestroy () {Super.ondestroy (); Mhomekeylocker.unlock (); mhomekeylocker = null;}


So that you can play happily.



Android 4.0 disable System Home key

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.