Android listening to the home key via radio

Source: Internet
Author: User

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

Related Article

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.