当应用程序处于前台时,来自 FCM 的广播数据未进入广播接收器



我在应用中使用了Firebase推送通知,如果应用在前台,则我在收到消息时向另一个活动广播意图。但是我没有在定向活动中编写的广播接收器中得到意图。

发送意图就像

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
if (isAppIsInBackground(this)){ 
int dbcount = Integer.parseInt(dbHelper.getPushCount());
int i = count;
int current = dbcount +4;
dbHelper.updatePushCount(Integer.toString(current));
} else {
Intent intent = new Intent(this, NavigationHome.class);
intent.setAction("new.pushMessage");
intent.putExtra("count", count.toString());
sendBroadcast(intent);
}
}

和接收者在我想要获得意图的活动中是

public class NavigationHome extends BaseActivity
implements NavigationView.OnNavigationItemSelectedListener {
int count=0;
Context context;
private BroadcastReceiver LandingBr = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.e("received",""+1);
NavigationHome.this.update();
}
};
@Override
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation_home);
dbhelper = new DBHelper(this);

...................

update(( 函数没有被调用,我怎样才能在活动中获取意图?

创建在活动中扩展 BroadcastReceiver 的 MyReceiver 类。

class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// do your stuff here
}
}

并且比在特定活动的onCreate((中注册您的BroadcastReceiver。 为此使用以下代码。

MyReceiver myReceiver =new MyReceiver();
IntentFilter intentFilter= new IntentFilter(Constants.ACTION);
registerReceiver(myReceiver,intentFilter);

相关内容

  • 没有找到相关文章

最新更新