It is used, so write it down, lest you forget it later.
1 Public classHomelistenerextendsBroadcastreceiver {2 Private Static FinalString Log_tag = "Homereceiver";3 Private Static FinalString System_dialog_reason_key = "REASON";4 Private Static FinalString System_dialog_reason_recent_apps = "Recentapps";5 Private Static FinalString System_dialog_reason_home_key = "HomeKey";6 Private Static FinalString System_dialog_reason_lock = "LOCK";7 Private Static FinalString system_dialog_reason_assist = "ASSIST";8 9 @OverrideTen Public voidOnReceive (Context context, Intent Intent) { OneString action =intent.getaction (); ALOG.I (Log_tag, "onreceive:action:" +action); - if(Action.equals (intent.action_close_system_dialogs)) { - //Android.intent.action.CLOSE_SYSTEM_DIALOGS theString reason =Intent.getstringextra (system_dialog_reason_key); -LOG.I (Log_tag, "Reason:" +reason); - - if(System_dialog_reason_home_key.equals (REASON)) { + //Press the home key briefly -LOG.I (Log_tag, "HomeKey"); + A } at Else if(System_dialog_reason_recent_apps.equals (REASON)) { - //Press and hold the home button or the activity toggle key -LOG.I (Log_tag, "long press home key or activity switch"); - - } - Else if(System_dialog_reason_lock.equals (REASON)) { in //Lock Screen -LOG.I (Log_tag, "lock"); to } + Else if(System_dialog_reason_assist.equals (REASON)) { - //Samsung Long Press the home button theLOG.I (Log_tag, "assist"); * } $ Panax Notoginseng } - } the}
Then start the position in the program, register the broadcast
1 New Homelistener (); 2 Final New Intentfilter (intent.action_close_system_dialogs); 3 this. Registerreceiver (Mhomekeyreceiver, Homefilter);
Android's Listening home button