跨应用(跨进程)发送广播和接收广播
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();@Overridepublic 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: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