The home key is a system button that we cannot intercept onKeyDown
, it is not intercepted, we can only get when he was pressed. is through the broadcast receiver.
Public classHomekeyeventbroadcastreceiverextendsBroadcastreceiver {Static FinalString System_reason = "REASON"; Static FinalString System_home_key = "HomeKey"; Static FinalString System_recent_apps = "Recentapps"; @Override Public voidOnReceive (Context context, Intent Intent) {String action=intent.getaction (); if(Action.equals (intent.action_close_system_dialogs)) {String reason=Intent.getstringextra (System_reason); if(Reason! =NULL) { if(Reason.equals (System_home_key)) {//Home key processing point } Else if(Reason.equals (System_recent_apps)) {//Long Home key processing point } } } }}
Register the broadcast receiver in the activity.
Newnew intentfilter (intent.action_close_system_dialogs));
To cancel the registration in the activity destruction method
Unregisterreceiver (receiver);
Home key Monitoring