Screen "Power key Long Press", "Home Key", "home button long Press" in Android

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.