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
- Intent intent = new intent ("info. zhegui. Er er. interprocess ");
- Sendbroadcast (intent );
Note that you must add the broadcast receiving permission in manifest. xml. This permission is customized by the receiver.
Java code
- <Uses-Permission Android: Name = "info. zhegui. Receiver. Receive"/>
In applications that receive broadcasts:
Java code
- Public class myreceiver extends broadcastreceiver {
- Private final string tag = This. getclass (). getname ();
- @ Override
- Public void onreceive (context content, intent ){
- Log. I (TAG, "intent:" + intent );
- }
- }
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