In Level5 above (included), the method in the Activity class: Publicvoid Onattachedtowindow () captures the home key.
The specific code is as follows:
Mainactivity.java
package com.lingdududu.test;
Import android.app.Activity;
Import Android.os.Bundle;
Import android.view.KeyEvent;
Import Android.view.WindowManager;
Import Android.widget.Toast; The public class Mainactivity extends activity {/** called the ' when ' is the ' The activity ' is the ' the '. * Private Boolean created
Mekey = false;
public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main); @Override public void Onattachedtowindow () {//TODO auto-generated Method stub if (!catchhomekey) {th
Is.getwindow (). SetType (WindowManager.LayoutParams.TYPE_KEYGUARD);
} Super.onattachedtowindow (); @Override public boolean onKeyDown (int keycode, keyevent event) {//TODO auto-generated method stub if (key
Code = = keyevent.keycode_home) {toast.maketext (Mainactivity.this, "You clicked the Home button", Toast.length_long). Show ();
Return Super.onkeydown (KeyCode, event); }
}
When we click on the Home button, the program does not return to the main interface, but stays on the current page, and can capture the toast display information.
Effect Chart:
The above is an example of Android getting, shielding home keys, hoping to help small partners in need.