Home » Android » Android listens for the home key and the menu key

Android listens for the home key and the menu key

The

Android listens for the home key and the menu key,


code paste, you can use
in the past


// registered broadcasting

registerReceiver (homeKeyEventReceiver, new, IntentFilter (
)
(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));


// monitor home menu key and
key
private, BroadcastReceiver, homeKeyEventReceiver = new, BroadcastReceiver () {

String REASON = "reason";

String HOMEKEY = "Homekey";

String RECENTAPPS = "recentapps";



@Override

Public, void, onReceive (Context, context, Intent, intent) {

String action = intent.getAction ();

If (action.equals (Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {

String reason = intent.getStringExtra (REASON);

If (TextUtils.equals (reason, HOMEKEY)) {

Click on Home / /

Toast.makeText (getApplicationContext (), Home, 1).Show ();

} else if (TextUtils.equals (reason, RECENTAPPS)) {

Click the menu button / /

Toast.makeText (getApplicationContext ()), menu key, 1).Show ();

}

}

}

};



copyright notice: This article is original article for blogger. Without permission from blogger,.

must not be reprinted

Latest