跨应用(跨进程)发送广播和接收广播

跨应用发送和接收广播,与同应用下的情况差不多,只需要添加一个权限,以及配置一下receiver的android:process属性即可

 

 

发送广播的应用中:

 

Intent intent = new Intent("info.zhegui.receiver.interprocess");
sendBroadcast(intent);

 注意要在manifest.xml添加接收广播的权限,这个权限是receiver自定义的

 <uses-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的几个属性

    <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" (有时候可以不要该属性)

 

动态注册也是可能的。

 

参考文档:

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

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值