跨应用发送和接受广播

简介: 跨应用发送和接收广播,与同应用下的情况差不多,只需要添加一个权限,以及配置一下receiver的android:process属性即可     发送广播的应用中:   Java代码   Intent intent = new Intent("info.zhegui.receiver.interprocess");   sendB

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

 

 

发送广播的应用中:

 

Java代码   收藏代码
  1. Intent intent = new Intent("info.zhegui.receiver.interprocess");  
  2. sendBroadcast(intent);  

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

Java代码   收藏代码
  1. <uses-permission android:name="info.zhegui.receiver.RECEIVE"/>  

 

接收广播的应用中:

Java代码   收藏代码
  1. public class MyReceiver extends BroadcastReceiver {  
  2.     private final String TAG = this.getClass().getName();  
  3.   
  4.     @Override  
  5.     public void onReceive(Context content, Intent intent) {  
  6.         Log.i(TAG, "intent:" + intent);  
  7.     }  
  8.   
  9. }  

 在manifest.xml中添加自定义权限,以及配置receiver的几个属性

Java代码   收藏代码
  1. <permission android:name="info.zhegui.receiver.RECEIVE" />  
  2.   
  3. <application  
  4.     android:allowBackup="true"  
  5.     android:icon="@drawable/ic_launcher"  
  6.     android:label="@string/app_name"  
  7.     android:theme="@style/AppTheme" >  
  8.     <receiver  
  9.         android:name="info.zhegui.receiver.MyReceiver"  
  10.         android:exported="true"  
  11.         android:permission="info.zhegui.receiver.RECEIVE"  
  12.         android:process=":remote" >  
  13.         <intent-filter>  
  14.             <action android:name="info.zhegui.receiver.interprocess" />  
  15.         </intent-filter>  
  16.     </receiver>  
  17. </application>  

 

 

需要注意的三个地方:

1,自定义权限

2,android:exported="true"

3,android:process=":remote" (有时候可以不要该属性)

目录
打赏
0
0
0
0
498
分享
相关文章
根据请求中接收到的主动协商头字段,目标资源没有用户代理可以接受的当前表示
今天使用ssm框架搭建了一个项目,测试一个插入的接口结果返回406,但是数据库插入成功了,报错406是因为返回的结果接口无法解析。
891 0
socket通信处于网络协议那一层和两种接收发送消息方式
socket通信处于网络协议那一层和两种接收发送消息方式
129 2
Broadcast的注册、发送和接收过程
Broadcast的注册、发送和接收过程
72 0
《移动互联网技术》第八章 消息与服务:掌握不同类型广播监听方式,以及创建通知的方法
《移动互联网技术》第八章 消息与服务:掌握不同类型广播监听方式,以及创建通知的方法
79 0
【计算机网络】数据链路层 : 后退 N 帧协议 GBN ( 滑动窗口 | 发送窗口长度 | “发送方“ 累计确认、超时机制 | “接收方“ 按序接收、确认帧发送机制 | 计算示例 )★(二)
【计算机网络】数据链路层 : 后退 N 帧协议 GBN ( 滑动窗口 | 发送窗口长度 | “发送方“ 累计确认、超时机制 | “接收方“ 按序接收、确认帧发送机制 | 计算示例 )★(二)
805 0