0

I upgraded from GCM to FCM and now I'm testing the experience of upgrading users

I have the following steps

  1. install the app version that supports GCM
  2. Upgrade to a new version that supports FCM
  3. Send push message on Firebase console

The problem is that I see the message received on the notification area in the device, but it doesn't invoke the code CloudMessagingListenerService extends FirebaseMessagingService I have a debug log at the beginning of CloudMessagingListenerService#onMessageReceived

After I go to the app info and select force stop and reopen the app my code inside CloudMessagingListenerService#onMessageReceived is called properly.

Any idea what causes this and what can be done to avoid the force kill (my users won't do it voluntarily)

in both scenarios the app is in the background

Update:

The problem is w/ receiving messages from the Firebase console.

I added logs in CloudMessagingListenerService#onCreate and CloudMessagingListenerService#onDestroy and I can see that they are called w/ a 100ms time diff between them - while CloudMessagingListenerService#onMessageReceived isn't called so it seems FirebaseMessagingService decides to handle the notification but not the data portion

Regarding messages sent from the server: this is the json I send from the server - the data part is propagated correctly to my code, but the notification is ignored, when I check what is the content of remoteMessage.getNotification() I get null

{ "to": "my token", "collapse_key": "my app", "notification": { "title": "server title", "body": "server text" }, "data": { "tag": "debug", "action": "custom-push", ... } }

Noa Drach
  • 2,381
  • 3
  • 26
  • 44
  • Can you share your FCM message body? The one you construct in the server... – HedeH Aug 05 '18 at 12:35
  • Possible duplicate of [Android app not receiving Firebase Notification when app is stopped from multi-task tray](https://stackoverflow.com/q/39504805/4625829) – AL. Aug 05 '18 at 12:43
  • @HedeH I'm not posting my server json b/c it is handled ok - as updated above the problem is w/ messages generated in the _Firebase console_ – Noa Drach Aug 06 '18 at 11:08

1 Answers1

0

Firebase Console sends the message in the notification key, which means it is only delivered to the onMessageReceived() if the app is running in foreground/open. If the app is running in the background the notification will show up on the notification drawer directly.
To receive the payload in onMessageReceived() of your class extending FirebaseMessagingService make sure the the notification content is passed in the data key of your request to the made to the FCM server. This will ensure that the payload is delivered to the onMessageReceived() irrespective of whether the app is in foreground/background.

Umang
  • 966
  • 2
  • 7
  • 17