跨应用发送和接收广播,与同应用下的情况差不多,只需要添加一个权限,以及配置一下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) {
- "intent:" + intent);
- }
- }
在manifest.xml中添加自定义权限,以及配置receiver的几个属性
- <permission android:name="info.zhegui.receiver.RECEIVE" />
- <application
- "true"
- "@drawable/ic_launcher"
- "@string/app_name"
- "@style/AppTheme" >
- <receiver
- "info.zhegui.receiver.MyReceiver"
- "true"
- "info.zhegui.receiver.RECEIVE"
- ":remote" >
- <intent-filter>
- "info.zhegui.receiver.interprocess" />
- </intent-filter>
- </receiver>
- </application>
需要注意的三个地方:
1,自定义权限
android:exported="true"
3,android:process=":remote" (有时候可以不要该属性)
标签:info,应用,发送,广播,intent,zhegui,receiver,权限 From: https://blog.51cto.com/u_13657808/5891914