BroadcatReceiver的manifest.xml中宣称没有收到LocalBroadcastManager意图 [英] BroadcatReceiver declared in manifest.xml not receiving LocalBroadcastManager intents

查看:309
本文介绍了BroadcatReceiver的manifest.xml中宣称没有收到LocalBroadcastManager意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然可以通过code,因此接收通过LocalBroadcastManager.Ex公布的意图来声明一个'本地'的BroadcastReceiver

  LocalBroadcastManager.getInstance(本).registerReceiver(新FooReceiver(),新的IntentFilter(foo_intent_filter));

我不知道是否有可能通过的清单的.xml(清洁剂)。

宣布这样的接收器

当我使用'清单的方式',接收器的不是'接收'的意图。

 <接收
        机器人:名字=FooReceiver
        机器人:启用=真
        机器人:出口=假>
        &所述;意图滤光器>
            <作用机器人:名字=foo_intent_filter/>
        &所述; /意图滤光器>
  < /接收器>

我缺少的东西吗?或code-方式是唯一可行的解​​决方案。

感谢


解决方案

  

我不知道是否有可能通过的manifest.xml(清洁剂)。

宣布这样的接收器

首先,这是不可能的。

二,在清单登记有一点做与它是干净。这是为了让Android的实例在其自己的接收器,让你可以在你的进程没有运行响应广播。而且,在你举具体的例子,它是允许系统上的任何应用程序向您发送广播。这些都不是相关的 LocalBroadcastManager

While it is possible to declare a 'Local' BroadcastReceiver via code so it receives intents published via a LocalBroadcastManager.Ex

LocalBroadcastManager.getInstance(this).registerReceiver(new FooReceiver(), new IntentFilter("foo_intent_filter"));

I wonder if it is possible to declare such receiver via the manifest.xml (cleaner) .

When I use the 'manifest way', the receiver is not 'receiving' the intents.

  <receiver
        android:name="FooReceiver"
        android:enabled="true"
        android:exported="false" >
        <intent-filter>
            <action android:name="foo_intent_filter" />
        </intent-filter>
  </receiver>

Am I missing something? or the code-way is the only viable solution.

Thanks

解决方案

I wonder if it is possible to declare such receiver via the manifest.xml (cleaner) .

First, that is not possible.

Second, registering in the manifest has little to do with it being "cleaner". It is to allow Android to instantiate the receiver on its own, so that you can respond to broadcasts when your process is not running. And, in the specific example that you cite, it is to allow any app on the system to send you a broadcast. Neither of those are relevant for LocalBroadcastManager.

这篇关于BroadcatReceiver的manifest.xml中宣称没有收到LocalBroadcastManager意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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