ReceiverCallNotAllowedException

mContext.registerReceiver()不能在BroadcastReceiver的onReceive()里面调用

可以通过context.getApplicationContext().registerReceiver()来解决

提高context的级别

另外在网上搜索的时候,发现

BroadcastReceiver的onReceive()里面调用bindService()方法也会出现这个Exception

Note: this method can not be called from a BroadcastReceiver component.

A pattern you can use to communicate from a BroadcastReceiver to a Service is to call startService(Intent) with the arguments containing the command to be sent, with the service calling its stopSelf(int) method when done executing that command.

See the API demo App/Service/Service Start Arguments Controller for an illustration of this.

It is okay, however, to use this method from a BroadcastReceiver that has been registered with registerReceiver(BroadcastReceiver, IntentFilter), since the lifetime of this BroadcastReceiver is tied to another object (the one that registered it).
bindService不能在BroadcastReceiver 中调用,你可以在里面调用StartService并把要传递参数放到intent中

Android ReceiverCallNotAllowedException: BroadcastReceiver components are not allowed to register to receive intents的更多相关文章

  1. Android API之android.content.BroadcastReceiver

    android.content.BroadcastReceiver Base class for code that will receive intents sent by sendBroadcas ...

  2. Android中BroadcastReceiver的两种注册方式(静态和动态)详解

    今天我们一起来探讨下安卓中BroadcastReceiver组件以及详细分析下它的两种注册方式. BroadcastReceiver也就是"广播接收者"的意思,顾名思义,它就是用来 ...

  3. Android 广播 BroadcastReceiver

    Android 系统里定义了各种各样的广播,如电池的使用状态,电话的接收和短信的接收,开机启动都会产生一个广播.当然用户也可以自定义自己的广播. 既然说到广播,那么必定有一个广播发送者,以及广播接收器 ...

  4. Android中BroadcastReceiver广播

    BroadCastReceiver 简介 广播接收者( BroadcastReceiver )用于接收广播 Intent ,广播 Intent 的发送是通过调用 Context.sendBroadca ...

  5. java攻城狮之路(Android篇)--BroadcastReceiver&Service

    四大组件:activity 显示. contentProvider 对外暴露自己的数据给其他的应用程序.BroadcastReceiver 广播接收者,必须指定要接收的广播类型.必须明确的指定acti ...

  6. Android广播BroadcastReceiver 二

    BroadcastReceiver: 在Android中,Broadcast是一种广泛运用的在应用程序之间传输信息的机制.而BroadcastReceiver是对发送出来的 Broadcast进行过滤 ...

  7. Android广播BroadcastReceiver 一

    Android 系统里定义了各种各样的广播,如电池的使用状态,电话的接收和短信的接收,开机启动都会产生一个广播.当然用户也可以自定义自己的广播. 既然说到广播,那么必定有一个广播发送者,以及广播接收器 ...

  8. Android之BroadcastReceiver 监听系统广播

    绑定广播有两种方式 一.配置文件绑定,在程序未启动也能监听 二.代码方式绑定,在程序启动后才能监听 1.绑定和取消绑定广播 public class MainActivity extends Acti ...

  9. android中broadcastreceiver的用法-代码中注册

    界面如下:     问题1:点击“解绑广播接收器“后再次点击”解绑广播接收器“后,程序崩溃,log信息如下: 08-04 05:04:35.420: E/AndroidRuntime(5521): F ...

随机推荐

  1. jvm的内存区域简介

    1.内存区域划分 jvm在执行java程序过程中会将管理的内存划分成若干不同的数据区域,他们分别是程序计数器,堆,方法区,虚拟机栈,本地方法栈. 1.1指令计数器 指令计数器是线程私有的,每个线程都有 ...

  2. CSS的position(位置)

    position: 位置,absolute绝对位置,相对于浏览器边界的位置:relative相对位置,相对于它本应该出现的位置.fixed:固定位置,它不会随着滚动. 设置好position之后,就可 ...

  3. 简简单单C#爬虫小计

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...

  4. Aptana Studio 3 官方汉化包汉化

    Babel Language Pack Update Site for Helios This URL is an Eclipse software repository:http://downloa ...

  5. VIM用法

    突然感觉vim像是linux上默认的文本编辑器,所以熟悉下用法吧. 1,set nu  显示行号. 2, /word  搜索文本word,n查找下一个.   :set hlsearch--高亮显示搜索 ...

  6. Log4J logger图片

  7. python 中 json的处理

    python中的json对象,其实就是字典类型. 利用json模块,可以将字符串类型的json串转换为 json对象(字典对象),也可以将json对象(字典对象)转换为字符串对象. 代码如: #cod ...

  8. [置顶] android网络通讯之HttpClient4不指定参数名发送Post

    在HttpClient4之前都是通过List<NameValuePair>键值对的形式来向服务器传递参数 ,在4.0版本中在加入了不指定参数名发送数据的形式,利用StringEntity来 ...

  9. C#高级编程随笔

    1.把类创作的变量叫做对象2.类就是对象的模版3.类定义了每个对象的数据和功能4.接口不能被实例化,抽象类不能被实例化5.抽象基类可以包含非抽象方法,而接口只能包含抽象方法6.一个类可以实现多个接口7 ...

  10. myeclipse8.5如何注册,转自他出

    Step: 1.建立一个任意名称的Java Project 2.在该工程中建立一个名文MyEclipseGen的Java文件(MyEclipseGen.java) 3.运行下面的代码,会在控制台出现& ...