zoukankan      html  css  js  c++  java
  • 跨应用(跨进程)发送广播和接收广播

    跨应用发送和接收广播,与同应用下的情况差不多,只需要添加一个权限,以及配置一下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的几个属性

    <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

  • 相关阅读:
    用python3实现AES/CBC/PKCS5padding算法加解密
    python之逆向某贷款app破解sign参数
    用Python实现RSA签名和验签
    python3 RSA 长字符串分段加密解密
    PyCharm 字体大小颜色常用功能设置
    pycharm2019.3/pycharm2020.2 专业版 安装教程永久激活
    Android 四大组件和Intent
    Linux的查找命令
    Linux(centos)系统各个目录的作用详解
    linux ls文件颜色和底色设置
  • 原文地址:https://www.cnblogs.com/lbangel/p/3919252.html
Copyright © 2011-2022 走看看