想有一个广播接收器没有过滤 [英] Trying to have a Broadcast Receiver with No filter

查看:106
本文介绍了想有一个广播接收器没有过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IntentFilter intentFilter = new IntentFilter("test");
registerReceiver(mReceiver, intentFilter);

我想有一个像 registerReceiver无过滤器(mReceiver,空),但我的应用程序崩溃的那一个结果。我可以有新IntentFiler()作为一个空文件管理器?

I would like to have no filter like registerReceiver(mReceiver, null) but my app crashes as a result of that. Can I have new IntentFiler() as an empty filer?

推荐答案

由于该广播接收器返回时没有通过的标准不匹配从 >的IntentFilter ,这是不可能的API来完成你希望完成(这我假设发送的任何及所有广播到 mReceiver )。

Because the BroadcastReceiver returns null when there is no match via the criteria from the IntentFilter, it is not possible with the API to accomplish what you hope to accomplish (which I'm assuming is sending any and all Broadcasts to mReceiver).

您当然可以指定一个空的的IntentFilter ,但这将是pretty没用,因为注册接收器不会导致它捕捉任何广播(除非它们是直接定位到接收器,如由MisterSquonk评价提及)。否则,您必须确切地知道你想与你的广播接收器捕捉,然后在指定的IntentFilter的标准将广播。

You can certainly specify an empty IntentFilter, but this will be pretty useless as registering the receiver won't cause it to catch any broadcasts (unless they are directly targeted to the receiver, as mentioned by MisterSquonk in the comments). Otherwise you must know exactly which broadcasts you want to catch with your BroadcastReceiver, then specify the criteria in the IntentFilter.

这篇关于想有一个广播接收器没有过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆