Android 4.0 disable System Home key

Source: Internet
Author: User

2.2 Disable the System home key. Don't say it here.

Recent projects have a requirement to disable all keys for the system. Like menu, home, back. At the same time, if you want to click Response and view pop-up.

Is that the UI part is normal.

Back key our own onkeydown disabled good happy.

Personally feel 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 very long time, basically is not used. Because they are all said to be due to system security reasons. 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.

Just when I'm close to disappointment. Casually into a search page in a big God's github,https://github.com/shaobin0604/android-homekey-locker, random download tried, incredibly work.

More importantly, the great God is our Chinese.

It's too bull.


Worship. Here is not a detail of how the great God is realized, the secret is to create a overlaydialog, to it set a number of parameters like flag_show_when_locked,flag_not_touch_modal and so on.

Students who want to study, please download the source code for your own learning.

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.

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

4. Add 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. Add in your own Destroy method:

@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.