Android radio to listen to the home button, this way is a better way to use
1. Custom Broadcasts
public class Broadcastreceiverex extends broadcastreceiver{string System_reason = "REASON"; String System_home_key = "HomeKey"; String System_home_key_long = "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 (System_reason); if (textutils.equals (reason, System_home_key)) { //press the HOME key constants.ishome = true; Toastutil.showtoast (Context, "Press the home button" + ishome); } else if (textutils.equals (reason, System_home_key_long)) { //long press the HOME key to display the list of recently used Programs}}}}
2. Register for the broadcast
Home key Monitoring Registration Registerreceiver (new Broadcastreceiverex (), New Intentfilter (Intent.action_close_system_dialogs));
3. What you want to do after you press the home button
@Overrideprotected void Onrestart () {Super.onrestart (); if (constants.ishome) {//Toastutil.showtoast (Context, "" + Constants.ishome); Constants.ishome = false;//Press the home button to restart the operation}}
4, determine whether the home button is pressed
/** Listening Home key */public static Boolean ishome = false;
5. de-Registration (I was registered in application, so I'm onlowmemory to dismiss the note)
@Overridepublic void Onlowmemory () {//TODO auto-generated method Stubsuper.onlowmemory (); Unregisterreceiver ( Broadcastreceiverex);}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android listening to the home key via radio