Screen "Power key Long Press", "Home Key", "home button long Press" in Android
The triggering of these "buttons" will result in a notification of ACTION = = Intent.action_close_system_dialogs
The parameters that distinguish the different events of their three are the reason strings that come with intent, respectively, corresponding to
"Power Key Long Press" (Globalscreen), "Home Key"(HomeKey), "Home key Long Press"(Recentapps)
You said it is so simple, directly on the code.
Package Com.jumpinus.test;import Android.app.activity;import Android.content.broadcastreceiver;import Android.content.context;import Android.content.intent;import Android.content.intentfilter;import Android.os.bundle;public class Mainactivity extends Activity {private Mybroadcastreceiver mybroadcastreceiver;@ overrideprotected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate ( savedinstancestate); mybroadcastreceiver = new Mybroadcastreceiver ();} @Overrideprotected void Onresume () {//TODO auto-generated method Stubsuper.onresume (); Intentfilter intentfilter = new in Tentfilter (); intentfilter.addaction (intent.action_close_system_dialogs); System.out.println ("I ' m coming, Mybroadcastreceiver registered!"); Registerreceiver (Mybroadcastreceiver, intentfilter);} Private class Mybroadcastreceiver extends broadcastreceiver{@Overridepublic void onreceive (context context, Intent Intent) {//your own first reasons = = HomeKey and long press HomeKey exclude, the remaining do the following processing string reason = Intent.getstringeXtra ("Reason"), if (Intent.getaction (). Equals (Intent.action_close_system_dialogs)) {System.out.println (" Intent.action_close_system_dialogs: "+ Intent.getstringextra (" Reason ")); if (Intent.getextras ()!=null && Intent.getextras (). Getboolean ("Myreason")) {mybroadcastreceiver.abortbroadcast ();} else if (reason! = null) {if (Reason.equalsignorecase ("Globalactions")) {//Shielded Power Long Key method: Intent myintent = new Intent ( Intent.action_close_system_dialogs); Myintent.putextra ("Myreason", true); Context.sendorderedbroadcast (MyIntent, NULL); SYSTEM.OUT.PRINTLN ("Power key is long pressed");} else if (reason.equalsignorecase ("HomeKey")) {///////To Mask Home key//Do some of your own actions here, such as re-opening your lock screen program interface, It's not going to go away. System.out.println ("Home key is triggered");} else if (reason.equalsignorecase ("Recentapps")) {//Shielded Home key Long press method System.out.println ("Home key is long pressed");}}}} @Overrideprotected void OnPause () {//TODO auto-generated method Stubsuper.onpause (); System.out.println ("I get out, mybroadcastreceiver off!"); Unregisterreceiver (Mybroadcastreceiver);}}
:
Screen "Power key Long Press", "Home Key", "home button long Press" in Android