Quickstart-android: The code is not executed at onMessageReceived ()

Created on 28 May 2016  路  6Comments  路  Source: firebase/quickstart-android

This method _onMessageReceived ()_ is not called when the app in the background. only when in the foreground. when I send a push msg from FCM console, it shows a notification as of a hidden implementation in the FCM Library itself that overrides my implemntation.

The documentation is also a bit vague.
public void onMessageReceived (RemoteMessage message)

Also: Google Play Services
Called when a message is received. This is also called when a notification message is received while the app is in the foreground. The notification parameters can be retrieved with getNotification().

Most helpful comment

Hi @aselims thanks for trying FCM, you are not the first person to be confused by this implementation. Note that the FCM implementation is exactly the same is the GCM implementation. The thing to note is that messages from the Firebase console are notification messages not data only messages. If you always want incoming messages to be handled by onMessageReceived then you should always send data only messages.

That said notification messages are useful when sending messages to both Android and iOS, have a look at the table here for a good foreground/background explanation of notification message handling.

All 6 comments

Hi @aselims thanks for trying FCM, you are not the first person to be confused by this implementation. Note that the FCM implementation is exactly the same is the GCM implementation. The thing to note is that messages from the Firebase console are notification messages not data only messages. If you always want incoming messages to be handled by onMessageReceived then you should always send data only messages.

That said notification messages are useful when sending messages to both Android and iOS, have a look at the table here for a good foreground/background explanation of notification message handling.

For further discussion on this topic, see #4. I am going to close this issue as everything is working as intended for now, thanks for the feedback!

If you always want incoming messages to be handled by onMessageReceived then you should always send data only messages.

Can you please confirm, that sending the same message for iOS and Android devices is not possible when on the Android side custom notification needs to be shown.

What I want to achieve, is to show notification action buttons on Android and this requires to handle the "data" part of the message in onMessageReceived(). But for iOS to show the notification (and action buttons), the "notification" part is required, which in turn makes it impossible to show the custom notification on Android devices (as onMessageReceived() is not called when in background)

@mtiidla did you found an answer for your question?

@mtiidla did you found an answer for your question?

@andvalsol It has been a long time and I can't tell if this issue is still relevant today. I also no longer work on a project where I could try this out. However, I know that the solution we took was to send a push notification with different payload to Android and iOS devices.

I wanted to update the service when I receive notification even if app is closed or in background but onReceive method is not call at the same time.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

naveenkumarn27 picture naveenkumarn27  路  4Comments

charlizesmith picture charlizesmith  路  5Comments

rosariopfernandes picture rosariopfernandes  路  6Comments

tekinarslan picture tekinarslan  路  5Comments

Awais914 picture Awais914  路  6Comments