Skip to content

[firebase_messaging] Background messages not delivered in versions newer than 6.0.3 #1763

Closed
@LinusU

Description

@LinusU

Describe the bug
When upgrading from version 6.0.3 of firebase_messaging our onBackgroundMessage handler is no longer called. Instead the following error is printed to the Android log:

I/flutter (20210): Unable to handle incoming background message.
I/flutter (20210): NoSuchMethodError: The method 'call' was called on null.
I/flutter (20210): Receiver: null
I/flutter (20210): Tried calling: call(_LinkedHashMap len:1)

This occurs even if my handler is just a simple print statement, thus the null.call(...) doesn't happen in my handler.

Here is where the error is logged from:

https://github.com/FirebaseExtended/flutterfire/blob/547674c8b550a0b14ff442a3bd6a2663c6dc7680/packages/firebase_messaging/lib/firebase_messaging.dart#L37-L43

To Reproduce
Steps to reproduce the behavior:

  1. Add firebase_messaging version 6.0.3
  2. Add a background handler that prints something to the log
  3. See that the message is received
  4. Upgrade to the latest firebase_messaging version
  5. See that the message is no longer received

Expected behavior
The message should be received with both versions.

Additional context
n/a

Activity

iapicca

iapicca commented on Jan 8, 2020

@iapicca

Hi @LinusU
can you please provide your flutter doctor -v,
your pubspec.yaml
and your flutter run --verbose?
Thank you

mklim

mklim commented on Jan 8, 2020

@mklim

From a discussion in our team chat: this is likely caused by a bug in how we added Android v2 embedding support. See also flutter/flutter#47406, which is showing similar symptoms when running in the background because of a change in the v2 embedding.

/cc @bparrishMines

self-assigned this
on Jan 13, 2020
added
impact: crowdAffects many people, though not necessarily a specific customer with an assigned label. (P2)
and removed
blocked: customer-responseWaiting for customer response, e.g. more information was requested.
on Feb 7, 2020
thesmalleyes

thesmalleyes commented on Mar 20, 2020

@thesmalleyes

Hi @mklim any update for this issue? cause i can't see notification in background untill now.
@LinusU do you have a solution? i need your help for this issue

arputharajraja

arputharajraja commented on May 29, 2020

@arputharajraja

I am also faced this issue after upgrade .. Please register the plugin like below in Application class for android. Now it's working for me

import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService

class Application : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this)
}
override fun registerWith(registry: PluginRegistry) {io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin")); io.flutter.plugins.pathprovider.PathProviderPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.pathprovider.PathProviderPlugin")); com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.registerWith(registry?.registrarFor("com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin"));
}
}

Moizsohail

Moizsohail commented on Jun 30, 2020

@Moizsohail

Any solutions?

Moizsohail

Moizsohail commented on Jun 30, 2020

@Moizsohail

Also can you please expound on the background handler? How are you logging a backgrounded application?

gregertw

gregertw commented on Jul 20, 2020

@gregertw

Note that the comments in this thread shows two different things, one is a user error, the other is a bug:

  1. The documentation documents that you need to include click_action=FLUTTER_NOTIFICATION_CLICK in the message, also elsewhere (not able to find it now), it is documented that only data messages can be sent to backgrounded applications. If you thus use curl as described to send a message, but REMOVES the notification part of the message (i.e. DATA='{"data": {"click_action": "FLUTTER_NOTIFICATION_CLICK", "id": "1", "status": "done"}, "to": "<token>"}'), you will be able to send a message that is received, however...
  2. Issue 2 is a bug (a similar issues with alarms is referred above) where the the LinkedMap of callbacks is not initialised. This issue title refers to >6.0.3 as the breaking point, however, I see the same error message with firebase_messaging=6.0.2

(edited) => after some more testing, I can confirm that I only see the bug when the message is formatted as in item 1 above. The reason is that with the absence of a notification item in the message, the message will be attempted sent to the background handler. However, WITH the notification item present, the default android message handler will present a regular android tray notification. When the user selects the notification, your app will be resume and the onResume function called as expected. This is probably what most app developers want as you can then react to the message with UI updates as well. However, if you want to silently trigger a background action without any user interaction, you are still hit by this bug.

Salakar

Salakar commented on Nov 5, 2020

@Salakar
Member

Hey all 👋

As part of our roadmap (#2582) we've just shipped a complete rework of the firebase_messaging plugin that aims to solve this and many other issues.

If you can, please try out the dev release (see the migration guide for upgrading and for changes) and if you have any feedback then join in the discussion here.

Given the scope of the rework I'm going to go ahead and close this issue in favor of trying out the latest plugin.

Thanks everyone.

locked and limited conversation to collaborators on Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

impact: crowdAffects many people, though not necessarily a specific customer with an assigned label. (P2)plugin: messagingtype: bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @LinusU@kirstywilliams@kroikie@mklim@Salakar

      Issue actions

        [firebase_messaging] Background messages not delivered in versions newer than 6.0.3 · Issue #1763 · firebase/flutterfire