Simple implementation of android4.0 masking the HOME key

  • 2020-05-27 07:08:25
  • OfStack

In android2.2 2.3 it can be rewritten by activity


@Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}

This function shields the Home key.

This method will not work after android 4.0. Here's how to block the Home key after android 4.0.


public static final int FLAG_HOMEKEY_DISPATCHED = 0x80000000;

Add the following code to the onCreate function

this.getWindow().setFlags(FLAG_HOMEKEY_DISPATCHED, FLAG_HOMEKEY_DISPATCHED);


The above method can shield the Home key in android4.0 after personal test.


Related articles: