跨应用发送和接收广播
2013-07-30 18:40
169 查看
跨应用发送和接收广播,与同应用下的情况差不多,只需要添加一个权限,以及配置一下receiver的android:process属性即可
发送广播的应用中:
Java代码
Intent intent = new Intent("info.zhegui.receiver.interprocess");
sendBroadcast(intent);
注意要在manifest.xml添加接收广播的权限,这个权限是receiver自定义的
Java代码
<uses-permission android:name="info.zhegui.receiver.RECEIVE"/>
接收广播的应用中:
Java代码
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的几个属性
Java代码
<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:permission="info.zhegui.receiver.RECEIVE"
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" (有时候可以不要该属性)
参考文档:
http://developer.android.com/guide/topics/manifest/receiver-element.html http://developer.android.com/training/articles/security-tips.html
发送广播的应用中:
Java代码
Intent intent = new Intent("info.zhegui.receiver.interprocess");
sendBroadcast(intent);
注意要在manifest.xml添加接收广播的权限,这个权限是receiver自定义的
Java代码
<uses-permission android:name="info.zhegui.receiver.RECEIVE"/>
接收广播的应用中:
Java代码
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的几个属性
Java代码
<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:permission="info.zhegui.receiver.RECEIVE"
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" (有时候可以不要该属性)
参考文档:
http://developer.android.com/guide/topics/manifest/receiver-element.html http://developer.android.com/training/articles/security-tips.html
相关文章推荐
- 跨应用(跨进程)发送广播和接收广播
- android如何在底层发送一个广播应用层接收
- 跨应用(跨进程)发送广播和接收广播
- 跨应用(跨进程)发送广播和接收广播
- 优化第三方应用被kill后接收广播自启
- 应用内发送广播工具——LocalBroadcastManage
- Activity利用广播接收服务发送的数据
- Broadcast 广播 的接收 和发送 -- Android 学习之路
- 剖析ActivityManagerService源码,了解广播接收和发送机制(二)
- Udp广播的发送和接收(iOS + AsyncUdpSocket)下篇
- 关于调试程序接收通过adb发送带有参数的广播问题
- Android Activity接收Service发送的广播
- Android 有时接收不到自己发送的广播消息
- 跨应用发送和接受广播
- android安全问题(七) 抢先接收广播 - 内因篇之广播发送流程
- Android 发送和接收定制广播
- Linux系统下UDP发送和接收广播消息小例子
- Android app接收来自adb发送的广播的实例学习
- iphone发送udp广播并接收数据
- C#UDP的多路广播组的发送和接收