我尝试在清单中注册广播接收器,但是没有调用onReceive方法。我做错了什么?
的manifest.xml
<receiver
android:name="zzz.yyy.xxx.ui.storyboard.discussion.DiscussionFragment$MessageCountReceiver"
android:exported="true"
android:enabled="true">
<intent-filter>
<action android:name="zzz.yyy.xxx.ui.storyboard.discussion.GROUPCHAT" />
</intent-filter>
</receiver>
发送广播如下:
Intent intent = new Intent("zzz.yyy.xxx.ui.storyboard.discussion.GROUPCHAT");
intent.putExtra(BundleKeys.notification_post_id_forum,postId);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
在Fragment类中接收广播,如下所示:
@Override
public void onPause() {
clearUnreadCount();
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(messageRefresher);
super.onPause();
}
public class MessageCountReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
String noti_post_id = intent.getStringExtra(BundleKeys.notification_post_id_forum);
int tempCount=PreferencesIMDStar.getIntValue(getActivity(),noti_post_id);
tempCount++;
PreferencesIMDStar.setIntValue(getActivity(),noti_post_id,tempCount);
if (getActivity() != null && noti_post_id.equalsIgnoreCase(post_id)) {
discussionPresenter.fetchCommentReply(post_id, true);
}
}
}