广播没有收到[LocalBroadcastManager] Android

时间:2015-02-02 18:48:27

标签: java android broadcastreceiver

你能帮我解决这个问题吗,我已经实现了一个接收器(通过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注册的接收器接收本地广播。

请帮忙, 感谢。

1 个答案:

答案 0 :(得分:2)

  

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

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