【问题标题】:Broadcast is not getting received[LocalBroadcastManager] Android未收到广播[LocalBroadcastManager] Android
【发布时间】:2015-02-02 18:48:26
【问题描述】:

你能帮我解决这个问题吗,我已经实现了一个接收器(通过 XML 注册),它侦听特定的本地广播,然后启动一个服务以进行进一步处理,但不知何故该接收器没有接收任何广播。

虽然通过代码在本地注册的另一个接收器能够接收广播,但你能帮我解决这个问题吗?下面是我的代码。

// Sending broadcast
Intent intent = new Intent(Constants.ACTION_PROFILE_UPDATED);
LocalBroadcastManager.getInstance(POC.getAppContext()).sendBroadcast(intent);

// Receiver
public class LocalReceiver extends BroadcastReceiver {

    private final String TAG = LocalReceiver.class.getSimpleName();

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(TAG, "received"); // its not received
        if(intent.getAction() != null){
            String action = intent.getAction();
            Log.i(TAG, "action = " + action);

            if(action.equals(Constants.ACTION_PROFILE_UPDATED)){


// IN manifest
        <receiver
            android:name=".LocalReceiver"
            android:enabled="true"
            android:exported="false" >
            <intent-filter>
                <action android:name="local.action.profile.updated" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

这个该死的代码不起作用,在开发者指南中没有说不会接收本地广播,通过通过 xml 注册的接收器。

请帮忙, 谢谢。

【问题讨论】:

  • 你注册你的接收器了吗?

标签: java android broadcastreceiver


【解决方案1】:

我已经实现了一个接收器(通过 XML 注册),它监听特定的本地广播

这是不可能的。 LocalBroadcastManager 不适用于清单注册的接收器,仅适用于通过 registerReceiver() 注册的接收器,在 LocalBroadcastManager 实例本身上调用。

【讨论】:

    猜你喜欢
    • 2016-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多