In Android, Press & quot; power key long & quot;, & quot; Home Key & quot;, and & quot; Home key long press & quot;
In Android, shield "power key long press", "Home Key", and "Home key long press"
The trigger of these "buttons" will generate a notification of Action = Intent. ACTION_CLOSE_SYSTEM_DIALOGS.
The parameters for distinguishing the three different events are corresponding to the reason strings brought by Intent.
"Globalscreen", "homekey", and "Home Key" (recentapps)
It's that simple to say, and you can directly access 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 s Tubsuper. onCreate (savedInstanceState); myBroadCastReceiver = new MyBroadCastReceiver () ;}@ Overrideprotected void onResume () {// TODO Auto-generated method stubsuper. onResume (); IntentFilter intentFilter = new IntentFilter (); 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) {// you should first exclude reasons = homekey and long-pressed homekey, and the rest will 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") {// Method for shielding long power keys: Intent myIntent = new Intent (Intent. ACTION_CLOSE_SYSTEM_DIALOGS); myIntent. putExtra ("myReason", true); context. sendOrderedBroadcast (myIntent, null); System. out. println ("power key long pressed");} else if (reason. equalsIgnoreCase ("homekey") {// Method for shielding the Home Key // here do some operations you want, such as re-opening your screen lock program interface, in this way, the System will not disappear. out. println ("Home Key triggered");} else if (reason. invalid sign OreCase ("recentapps") {// method of shielding Home key long press System. out. println ("Home Key pressed") ;}}}@ Overrideprotected void onPause () {// TODO Auto-generated method stubsuper. onPause (); System. out. println ("I get out, myBroadCastReceiver canceled! "); UnregisterReceiver (myBroadCastReceiver );}}
: