Android from ignorance to knowing--no.7

Source: Internet
Author: User

The previous IP dialer uses the system-provided broadcast events when listening for outgoing calls, and sometimes we need to set up broadcast events to meet specific needs. Ok, the whole day. Custom broadcast events, we use a condition 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 custom broadcast event:

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

the com.heng.lh here is our own defined broadcast event, which is used to receive signals from a particular channel.

then let us "spin" a bit, if there is a custom broadcast sent to the user a hint.

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


The module that receives the broadcast is ready, then it is necessary to set the module to send the broadcast, the main interface needs a button to 3G module sends alarm information:

<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 intent, and then set its action, which is the custom " 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);}

This way the 3G module receives a broadcast message, and a simple custom broadcast event is created.

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.