Skip to content

🐛 [firebase_messaging] All incoming Firebase notifications are handled as notification type #3696

Closed
@james-airspace

Description

@james-airspace

Bug report

Describe the bug
Firebase Messaging library appears to not handle data messages. Data messages are converted to notification messages as part of the remote message parsing that the library does after receiving the notification from firebase.

Steps to reproduce

Steps to reproduce the behavior:

  1. Add firebase_messaging library to project and configure
  2. Put the app in the background
  3. Send a data notification to the app. I am using this to send the push:
curl --location --request POST 'https://fcm.googleapis.com/fcm/send' \
--header 'Content-Type: application/json' \
--header 'Authorization: key=<REDACTED> \
--data-raw '{
  "registration_ids": ["<REDACTED>"],
  "data": {
    "foobar": "bazbar"
  }
}'

The above data notification is attempted to be delivered to the system tray as a notification message type, but it fails with this error:

NoSuchMethodError: The method 'call' was called on null.
Receiver: null
Tried calling: call(_LinkedHashMap len:1)

If I foreground the app and send the notification again, this is what I get back in the onMessage callback.
{notification: {title: null, body: null}, data: {foobar: bazbar}}

This payload shouldn't have a notification key within the payload. This is why the logs display an error when the app is backgrounded. The system is trying to create a notification with null body/title. Looks like the Firebase Messaging library is adding the notification key, even when the notification key is null in the message received from Firebase. I found what looks to be the culprit.

https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_messaging/android/src/main/java/io/flutter/plugins/firebasemessaging/FirebaseMessagingPlugin.java#L135

Looks like the parseRemoteMessage function appends a notification object to the map, even when remoteMessage.getNotification() is null.

Expected behavior

Data messages sent to the app with the plugin registered are still handled as data messages.

Branch with fix
https://github.com/james-airspace/flutterfire/tree/fix-3696

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions