Android broadcast broadcast message code implementation

Source: Internet
Author: User

I'm using fragment, send write in a class, receive write in the inner class of another class. The code dynamically implements the registration.

Code:

Myreceiver =NewZcd.netanything.MyCar.myReceiver (); Intentfilter Filter=NewIntentfilter (); //add an action to the filterFilter.addaction ("Zcd.netanything"); //Register a broadcastgetactivity (). Registerreceiver (myreceiver, filter); //BroadcastIntent intent=NewIntent (); Intent.putextra ("Wifiurl", Wifiurl.gettext (). toString ()); Intent.putextra ("Wificom", Wificom.gettext (). toString ()); Intent.putextra ("Wificamera", Wificamera.gettext (). toString ()); Intent.setaction ("Zcd.netanything"); Getactivity (). Sendbroadcast (Intent); 

Blog Source: http://www.cnblogs.com/xiaobo-Linux/wavelet Linux qq463431476 (Zhao Archive)

Inner class:

    //internal class broadcast receive        Public Static  classMyreceiverextendsBroadcastreceiver {@Override Public voidOnReceive (Context context, Intent Intent) {//TODO auto-generated Method StubWifiurl = Intent.getstringextra ("Wifiurl"); Wificom= Intent.getstringextra ("wificom"); Wificamera= Intent.getstringextra ("Wificamera"); Toast.maketext (Context,"Broadcast has been received", Toast.length_short). Show (); }          }

That's all you can do.

Android broadcast broadcast message code implementation

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.