Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
LinusU opened this issue Jan 4, 2020 · 8 comments
Assignees
Labels
impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) plugin: messaging type: bug Something isn't working

Comments

@LinusU
Copy link
Contributor

LinusU commented Jan 4, 2020

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

@LinusU LinusU added the type: bug Something isn't working label Jan 4, 2020
@iapicca
Copy link

iapicca commented Jan 8, 2020

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

@mklim
Copy link

mklim commented Jan 8, 2020

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

@thesmalleyes
Copy link

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
Copy link

arputharajraja commented May 29, 2020

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
Copy link

Any solutions?

@Moizsohail
Copy link

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

@gregertw
Copy link

gregertw commented Jul 20, 2020

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
Copy link
Member

Salakar commented Nov 5, 2020

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.

@Salakar Salakar closed this as completed Nov 5, 2020
@firebase firebase locked and limited conversation to collaborators Dec 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) plugin: messaging type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants