quickstart-android icon indicating copy to clipboard operation
quickstart-android copied to clipboard

The code is not executed at onMessageReceived ()

Open aselims opened this issue 10 years ago • 6 comments

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().

aselims avatar May 28 '16 12:05 aselims

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.

kroikie avatar May 28 '16 13:05 kroikie

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!

samtstern avatar May 31 '16 19:05 samtstern

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 avatar Aug 31 '16 09:08 mtiidla

@mtiidla did you found an answer for your question?

andvalsol avatar Aug 29 '19 00:08 andvalsol

@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.

mtiidla avatar Aug 29 '19 17:08 mtiidla

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.

appwelt-new avatar Aug 11 '20 09:08 appwelt-new