Android from ignorance to knowing--no.7

Source: Internet
Author: User

The IP dialer uses a system-provided broadcast event when it listens for outgoing calls. There are times when we need to set up broadcast events to meet certain needs.

Ok, the whole thing today. Define the broadcast event, we use a state monitoring module to send alarm information to a 3G module to achieve this idea.

Define a 3g module to receive a specific broadcast:

<textview        android:layout_width= "wrap_content"        android:layout_height= "Wrap_content"        android: Layout_centerhorizontal= "true"        android:layout_centervertical= "true"        android:text= "I am a 3g module ~ ~ ~"/>

Then set its own definition broadcast event:

<receiver android:name= ". Mybro ">            <intent-filter>                <action android:name=" Com.heng.lh "/>            </intent-filter> </receiver>

the com.heng.lh Here is our custom broadcast event, which is used to receive signals from specific channels.

then let's "spin the silk" for a moment. Suppose you have a broadcast of your own definition that sends a hint to the user.

public void OnReceive (context context, Intent Intent) {toast.maketext (context, "detects a broadcast event", 1). Show ();


The module receiving the broadcast is ready. Then we have to set the module to send the broadcast, the main interface needs a button to send the alarm message to the 3G module:

<button        android:onclick= "click"        android:layout_width= "wrap_content"        android:layout_height= "wrap _content "        android:layout_centerhorizontal=" true "        android:layout_centervertical=" true "        Android:text = "Send Message to 3G module"/>

Let's write this click event, New out an intention, and then set its action, which is what we define in front of " COM.HENG.LH "and finally with Sendbroadcast send out the information.

public void Click (View view) {Intent intent=new Intent (); Intent.setaction ("COM.HENG.LH");//Send alarm message to 3G module Sendbroadcast (intent);}

The 3G module receives a broadcast message, and a simple self-defined broadcast event is created.

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Android from ignorance to knowing--no.7

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.