Send broadcast and receive broadcast across applications (processes)

Source: Internet
Author: User

Send and receive broadcasts across applications. In the same case as in the same application, you only need to add a permission and configure the Android: process attribute of the receiver.

 

 

In the broadcast sending application:

 

Java code
  1. Intent intent = new intent ("info. zhegui. Er er. interprocess ");
  2. Sendbroadcast (intent );

Note that you must add the broadcast receiving permission in manifest. xml. This permission is customized by the receiver.

Java code
  1. <Uses-Permission Android: Name = "info. zhegui. Receiver. Receive"/>

 

In applications that receive broadcasts:

Java code
  1. Public class myreceiver extends broadcastreceiver {
  2. Private final string tag = This. getclass (). getname ();
  3. @ Override
  4. Public void onreceive (context content, intent ){
  5. Log. I (TAG, "intent:" + intent );
  6. }
  7. }

Add custom permissions to manifest. xml and configure several attributes of the receiver.

 

<permission android:name="info.zhegui.receiver.RECEIVE" />    <application      android:allowBackup="true"      android:icon="@drawable/ic_launcher"      android:label="@string/app_name"      android:theme="@style/AppTheme" >      <receiver          android:name="info.zhegui.receiver.MyReceiver"          android:exported="true"          android:process=":remote" >          <intent-filter>              <action android:name="info.zhegui.receiver.interprocess" />          </intent-filter>      </receiver>  </application>  

 

 

 

Note the following three points:

1. Custom Permissions

2, Android: exported = "true"

3. Android: Process = ": Remote" (This attribute can be skipped sometimes)

 

Dynamic registration is also possible.

 

Reference:

Http://developer.android.com/guide/topics/manifest/receiver-element.html

Http://developer.android.com/training/articles/security-tips.html

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.