本文介绍了不止一个的BroadcastReceiver为同一意图与矛盾的doc和实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档,谷歌Analytics(分析)为Android 的它有一个音符他说:

In the documentation for Google Analytics for Android it has a note saying:

请注意:只有一个BroadcastReceiver的类可以根据应用来指定。如果您需要将两个或两个以上BroadcastReceivers从不同的软件开发工具包,您将需要创建自己的BroadcastReceiver类,将接收所有广播和调用相应的BroadcastReceivers每种类型广播的。

虽然有点混乱,似乎没有成为事实在该​​声明中的单个元素。特别是,你可以在应用程序中多个接收器,他们工作得很好。其它地方有间preTED这意味着你不能有一个以上的接收器为特定意图的行动。然而,在包括平板电脑/ 3.2设备上,以及一个G1 / 1.6设备我的测试中我看到所有的广播接收器com.android.vending.INSTALL_REFERRER确实调用。

While somewhat confusing there doesn't appear to be a single element of truth in that statement. In particular you can have multiple receivers in an application and they work just fine. Other places have interpreted this to mean that you can't have more than one receiver for a particular Intent action. However in my testing including on a Tablet/3.2 device as well as a G1/1.6 device I do see that all broadcast receivers for com.android.vending.INSTALL_REFERRER are indeed called.

我实现了一个接收器,将调用别人的基础上一些配置,并更新其使用的PackageManager,而不是从清单中得到的条目,但是这一切似乎完全没有必要的。

I have implemented a receiver that will call others based on some config and was updating it use the PackageManager instead and get entries from the manifest, but this all appears completely unnecessary.

那么,什么是真相?是分析文档完整的瓦罐或有音符背后的​​一些真相?

So what is the truth? Is the analytics doc a complete crock or is there some truth behind the note?

推荐答案

回答我的问题。 Android系统的工作非常顺利地使用多个接收器相同的意图。它会调用所有的人都如预期。

Answering my own question. The Android system works perfectly well with multiple receivers for the same intent. It will call all of them as expected.

Android电子市场/播放存储/ Finsky被故意写成不使用标准的Andr​​oid的做法,故意确保只有第一个被调用。因此,你所要做的复用描述的分析页面上,而不是信任推荐测试工具。

Android Market/Play Store/Finsky has been deliberately written to not use standard Android practise and deliberately ensures that only the first one is called. Consequently you have to do the multiplexing as described on the analytics page, and not trust referral tester tools.

这code在的onReceive方法会让你发现所有的接收器。

This code in the onReceive method will let you find all the receivers.

// clear out classname
intent.setComponent(null);
// do what Market/Store/Finsky should have done in the first place
List<ResolveInfo> l=context.getPackageManager().queryBroadcastReceivers(intent, 0);

然后再照applicationInfo每个ResolveInfo,并使用名称(检查导出并启用后),不叫自己。

Then look in the applicationInfo in each ResolveInfo, and use the name (after checking exported and enabled), and don't call yourself.

我已经更新推荐测试仪,以配合市场/存储行为,使之更容易做安装引荐测试。请参阅https://github.com/rogerbinns/referraltester

I've updated Referral Tester to match the Market/Store behaviour and make it easier to do testing of install referrers. See https://github.com/rogerbinns/referraltester

这篇关于不止一个的BroadcastReceiver为同一意图与矛盾的doc和实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 16:53