Android 4.0 disables the system home key, android4.0

Source: Internet
Author: User

Android 4.0 disables the system home key, android4.0

2.2 disable the system home key.

Recently, the project has a requirement to disable all system keys, such as menu, home, and back. At the same time, you also want to click the response and view pop-up. That is, the UI part should be normal.

The back key is disabled by onKeyDown.

I personally think that the simplest writing method can be found:


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

After searching for the Internet for a long time, it is basically useless. Because it is said that due to system security reasons, the android system absorbed the event (home, menu) at the framework layer and did not distribute it to the application layer.

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


Look, there is no way for the stack overflow of foreigners.

When I was close to disappointment, I randomly clicked github, ghost.

More importantly, this great god is even Chinese. Too good.

Here, I will not elaborate on how the great gods implement it. The secret is to create an OverlayDialog and set some parameters for it, such as FLAG_SHOW_WHEN_LOCKED and FLAG_NOT_TOUCH_MODAL.

If you want to study, please download the source code.

Here we will only talk about the usage:

1. To the, download the code of the great god.

2. Put HomeKeyLocker. java in HomeLockLib under your Util package.

3. Copy the OverlayDialog related part of styles in HomeLockLib to your styles.

4. Add it to your own AndroidManifest

<Uses-permissionandroid: name = "android. permission. SYSTEM_ALERT_WINDOW"/>

5. The new HomeKeyLocker object is located at the place where you want to lock the key.

private HomeKeyLocker mHomeKeyLocker;mHomeKeyLocker = new HomeKeyLocker();

Use the lock key later:

MHomeKeyLocker. lock (mActivity. this );


MHomeKeyLocker. unlock ();

6. Add the following to your destroy method:

@Overrideprotected void onDestroy() {super.onDestroy();mHomeKeyLocker.unlock();mHomeKeyLocker = null;}

In this way, you can have fun.

How to disable the HOME Key in android403?

The home key is a reserved key and cannot be controlled by the app.
How does android40 shield the home Key?

This can be blocked. I have been engaged in the development of the screen lock software for android phones. In version 2.2 and 2.3, override the following method to override the home key public void onAttachedToWindow () {this. getWindow (). setType (WindowManager. layoutParams. TYPE_KEYGUARD); super. onAttachedToWindow ();} but it cannot be used if it is above 4.0. I just found that there is another way to block and override the Home key on MySQL 4.0, which is very simple. The Code is as follows: public static final int FLAG_HOMEKEY_DISPATCHED = 0x80000000; // you need to define the public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); this. getWindow (). setFlags (FLAG_HOMEKEY_DISPATCHED, FLAG_HOMEKEY_DISPATCHED); // key code setContentView (R. layout. main);} Then rewrite the onKey event. @ Override public boolean onKeyDown (int keyCode, KeyEvent event) {// TODO Auto-generated method stub if (keyCode = event. KEYCODE_HOME) {return true;} return super. onKeyDown (keyCode, event );}

Related Article

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