前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >跨应用发送和接受广播

跨应用发送和接受广播

作者头像
xiangzhihong
发布2018-01-30 17:11:23
1.8K0
发布2018-01-30 17:11:23
举报
文章被收录于专栏:向治洪

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

发送广播的应用中:

Java代码  

代码语言:java
复制
 Intent intent = new Intent("info.zhegui.receiver.interprocess");  
 sendBroadcast(intent);  

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

Java代码  

代码语言:java
复制
 <uses-permission android:name="info.zhegui.receiver.RECEIVE"/>  

接收广播的应用中:

Java代码  

代码语言: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代码  

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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015-06-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档