【发布时间】: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