Skip to content

Instantly share code, notes, and snippets.

@joeytsai
Created September 29, 2016 18:58
Show Gist options
  • Select an option

  • Save joeytsai/3adaa709661078f02c2eb44f73626b8f to your computer and use it in GitHub Desktop.

Select an option

Save joeytsai/3adaa709661078f02c2eb44f73626b8f to your computer and use it in GitHub Desktop.
Fun with FCM
Today I learned that FCM (formerly GCM) has a fun quirk. The payload of a push notification can contain two elements, "notification" and "data". You can read these payloads in a callback called onMessageReceived().
If the app is in the forgeround, everything works as you'd expect. However, if the app is in the background, and the "notification" element is in the payload, onMessageReceived() is NOT called and Firebase handles the push notification and generates a system notification.
If you want onMessageReceived() to always be called, then you can only have "data" notification. Awesome!
https://firebase.google.com/docs/notifications/android/console-audience#receive_and_handle_notifications
Also, a very frustrating read: https://github.com/firebase/quickstart-android/issues/4
https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
https://firebase.google.com/docs/cloud-messaging/android/receive#sample-receive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment