Android's Listening home button

Source: Internet
Author: User

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

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.