FCM push notification is not working when the app in foreground

We have integrated chat in our product for Android app & Web Portal. If we send the message from portal we need display the push notification on the Android app.

The push notification is getting displayed when application is killed or background/ not visible (i.e. by pressing device home button).

But the push notification is not getting received when the app in foreground/ visible. The below mentioned method which is overridden by extending the com.google.firebase.messaging.FirebaseMessagingService.class

@Override
public void onMessageReceived(@NotNull RemoteMessage remoteMessage) {
}

but it is not getting called, When the android application is in foreground/visible.

Hi!
connected state, you can receive a message through the channel event handler.

But if you want to get a push even when you are online? then you can enable always push in Sendbird dashboard(settings → chat → notifications → Push notifications for multi-device users → check(Send to devices both offline and online)

and add below code in
class MyFirebaseMessagingService extends SendBirdPushHandler {
@Override
protected boolean alwaysReceiveMessage() {
return true;
}
}

1 Like

Thanks for the update

1 Like

What if someone is using their own Firebase Messaging Service that extends FirebaseMessagingService and not SendBirdPushHandler?

Hello @Ezzy_Wachira ,

Could you please elaborate what is the issue you are facing here?

The issue is that when I’m using my own Firebase Service instead of SendbirdPushHandler, I’m not able to set the property for always receive message which is an override function in SendbirdPushHandler to make sure I always receive push notifications for chats after updating chat settings to multidevice on the dashboard. Right now I only receive push notifications only when the app is closed or in the background since I was informed that when app is open, Sendbird ignores the push notification for chat so I do not receive push paypoad in my onMessageReceived of my firebase service class.

Hello @Ezzy_Wachira ,

Could you please share me your app ID.
Maybe the foreground notifications is disabled and I can try to enable it from our end so that you can receive the notifications when the app is open,

Where can I send it since it’s more secret

Hi @rahul , Please let me know where to send you the APP_ID since it’s confidential

I have DM’d you. Please share your app id there.

1 Like