跨应用(跨进程)发送广播和接收广播
2017-04-18 23:06
253 查看
跨应用发送和接收广播,与同应用下的情况差不多,只需要添加一个权限,以及配置一下receiver的android:process属性即可
发送广播的应用中:
注意要在manifest.xml添加接收广播的权限,这个权限是receiver自定义的
<permission android:name="info.zhegui.receiver.RECEIVE" />
接收广播的应用中:
在manifest.xml中添加自定义权限,以及配置receiver的几个属性
<uses-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>
需要注意的三个地方:
1,自定义权限
2,android:exported="true"
3,android:process=":remote" (有时候可以不要该属性)
动态注册也是可能的。
发送广播的应用中:
Intent intent = new Intent("info.zhegui.receiver.interprocess"); sendBroadcast(intent);
注意要在manifest.xml添加接收广播的权限,这个权限是receiver自定义的
<permission android:name="info.zhegui.receiver.RECEIVE" />
接收广播的应用中:
public class MyReceiver extends BroadcastReceiver { private final String TAG = this.getClass().getName(); @Override public void onReceive(Context content, Intent intent) { Log.i(TAG, "intent:" + intent); } }
在manifest.xml中添加自定义权限,以及配置receiver的几个属性
<uses-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>
需要注意的三个地方:
1,自定义权限
2,android:exported="true"
3,android:process=":remote" (有时候可以不要该属性)
动态注册也是可能的。
相关文章推荐
- 跨应用(跨进程)发送广播和接收广播
- 跨应用(跨进程)发送广播和接收广播
- 跨应用发送和接收广播
- android如何在底层发送一个广播应用层接收
- Android广播的发送与接收一例
- 接收和发送广播
- android之接收和发送广播的开机可自动运行程序
- 接受和发送广播------开机启动和接收短信
- 进程间传递消息(发送和接收系统消息)
- 从一个A应用发广播,在另一个应用B的广播接收者的onReceive()方法中接收此广播并启动这个应用里的activity
- Can I Use this Intent? Android中不要发送没有接收应用的Intent.
- 接收和发送广播
- 如何发送和接收应用层数据包?
- 通过消息跨进程发送与接收 TCopyDataStruct 数据 - 回复 "skymesh"
- FCL小应用系列-----------如何利用APM实现HttpWebRequest异步发送接收
- android广播发送与接收演示DEMO
- C#UDP的多路广播组的发送和接收
- C#UDP的多路广播组的发送和接收
- 广播的发送和接收
- 简单的广播发送与接收