【问题标题】:Can we Only work with one broadcast receiver?我们可以只使用一个广播接收器吗?
【发布时间】:2012-04-28 21:06:31
【问题描述】:

【问题讨论】:

  • 每个过滤器都有一个接收器

标签: android


【解决方案1】:

是的,您可以使用单个 BroadcastReceiver 来捕获所有操作字符串。确保您确实在您的 IntentFilter 中添加了该接收器使用的所有操作字符串以使其工作。

【讨论】:

  • 什么意思?详细说明
【解决方案2】:

一个<application> 可以包含多个<receiver>,每个<receiver> 可以包含多个<intent-filter>。例如:

<application>

    <receiver android:name="ReceiverA">
        <intent-filter>
            <action android:name="android.intent.action.ACTION1"/>
        </intent-filter>
    </receiver>

    <receiver android:name="ReceiverB">
        <intent-filter>
            <action android:name="android.intent.action.ACTION2" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.ACTION3" />
            <data android:scheme="file" />
        </intent-filter>
    </receiver>

</application>

但您只能拥有一个 "com.google.android.apps.analytics.AnalyticsReceiver" - 这就是 IMO 文档的含义。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-29
    • 1970-01-01
    相关资源
    最近更新 更多