-
Notifications
You must be signed in to change notification settings - Fork 4k
Unable to use onBackgroundMessage in Firebase Cloud Messaging #2387
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
Comments
Hi @dvdlg |
my flutter doctor:
my flutter run --verbose
|
my android project is in kotlin, need documentation to setup in kotlin for handle background messages |
Anyone knows how to solve it? I'm strugling with it over 2 weeks |
@dvdlg I'm having the same problem. Do you get notification if the app is closed? |
@Errechydy , as you can see in my |
@TahaTesser, @Ehesp, Is it such a complex question? It should be basic... |
@dvdlg yes but do you get that notification on your phone, like does your phone ring and display notification title and body if the app is terminated? |
@Errechydy no |
@dvdlg Why is that? i mean getting notification when the app is terminated should be the main focus of those who are behind this plugin. if the user is using the app then the getting a notification is not that important |
I don't know. As you can see, I am confused as well about how to use it. I thought that once I'm able to trigger onBackgroundMessage I could do what I want, but the only thing that works is to print to the console. |
@dvdlg I'm not sure if i get what you're saying, when you terminate your app do you get notifications? like does your phone ring. |
@Errechydy, sorry for misleading you. My phone does ring even if the app is totaly terminated, only in the case that the notification was sent with body and title. in that case onResume and onLaunch are triggered once I tap the notification. but not if I resume to the app by taping the app itself. could it be that you don't send the message correctly? try to send it from a different app or from a different phone, or from firebase dashboard |
@Errechydy, wew you able to trigger the onBackgroundMessage callback? and if you did, were you able to do there anything that is not printing to the console? |
@dvdlg seems like my problem was the phone manufacture, when the app is terminated they don't allow it's notifications. they whitelist only big apps like Whatsapp or Facebook ...
|
hi guys |
@mostafa5731 , I opened a clean project for the sake of this example. You can see the code that I published, it has no other libs. Can you provide a working code example? |
see this |
see this |
@mostafa5731 , thank you very much for your answer, but unfortunately, it didn't work. When I tried to follow the steps in the link that you sent I got:
moreover, this solution doesn't seem to answer my question. I want to display to the user how many messages he has got so far. For this I need to somehow change the app's state (change a global variable or the disk memory or anything), but it seems that background code cannot handle such thing. |
I have this issue as well. An example of how to get data back from the background isolate to the main app's isolate would be very helpful. The current documentation of |
Has anyone successfully handle on backgroud notification with OnBackgroundMessage? |
|
@dvdlg Hi, i had found a solution for this issue yesterday... You should know that backgroundMessage Handler Method handle only Data message, this mean your message should not the message that your sending should have this structure : { |
Take a look at my stackoverflow post https://stackoverflow.com/questions/61827613/firebase-messaging-onbackgroundmessage-not-handling-notification-when-app-is-on |
In my case the operation is totally inconsistent. Sometimes it works and sometimes I just get the message "Service took too long to process intent: com.google.android.c2dm.intent.RECEIVE App may get closed". |
Oh really ? For me it's working every time, maybe your're missing something in your AndroidManifest.xml |
I have found the solution integrating this branch #1917 |
@Fbrusca, the solution that you suggested is already part of my code. So if it works for you, it means that there is something else that you do that I missed. Let me explain again what I'm trying to do, I want to present to the user a list of all past messages. For start I am trying to show only the number of messages. @Yirmerah, about the Data messages vs Notifications, you can see in the code that I posted that I already took care of it and tried both options. For now, nobody has yet solved my problem. It seems that onBackgroundMessage is a useless tool. If you think that I am wrong, please provide a way to present a list of all messages the user has ever got. |
Finally I got something working! I ended up using a named ReceivePort. Here is what I did in main.dart:
Not sure if this violates Flutter or/and the isolate pattern and I would be happy to get input on this! |
@dvdlg I met the same problem, plugins did not work with background message handler, solved by adding plugin registration in Application.kt /Application.java
Application.kt import io.flutter.app.FlutterApplication class Application : FlutterApplication(), PluginRegistrantCallback {
}` |
how do i check its working ? i was using shared preference increment counter when get notification while app is closed but its not working |
not working for me , can you share sample project ? |
Your code it's working fully when my app is in background mode but, when terminated it's not working for access and update top-level variables. |
Finally. I found solution in here. |
I was troubleshooting a user issue when I realized that it actually was this same SendPort issue. I added logging to
|
@dvdlg
|
@Fbrusca Thank you. but I hope full code with import. |
What is https://qastack.jp/programming/59446933/pluginregistry-cannot-be-converted-to-flutterengine |
Not receive |
@oskara not work. you don't use onBackgroundMessage? |
|
I solved this issue |
Check this out. My problem was because i didn't register in Application.java plugins, which should run in background. |
I am also facing this issue..i have changed global variable value in background method and when app resumes i again change global variable value. But it's restore the value that assign into background method |
@oskara this is working when app is minimized but when app is terminated that time it is not working and giving this errorI/flutter ( 2017): Unable to handle incoming background message.
|
THIS WORKED FOR ME.....BEEN BATTLING THIS FOR DAYS NOW...THANKS YOU ARE MVP |
Updating I still have this at the app boot, but otherwise everything works fine:
|
Estou utilizando um arquivo separado e inicializando ele na página home mas meu BackgroundMessage não funciona, como você implementou isto @louis030195 ? @OverRide
|
I am trying to implement an app with notifications. I followed the official instructions of firebase_messaging (https://pub.dev/packages/firebase_messaging), and everything worked as promissed, but there is something I don't understand. I was able to trigger onMessage, onLaunch and onResume and make the UI respond properly (showing the user the recieved message). But when onBackgroundMessage is triggered, I can only print the message to the debugging console. I looked all over the internet, but it seems like that's how all discussions end. What can I do inside onBackgroundMessage? I failed to find any way to show to the user that the message had been recieved. I tried to navigate using a global navigator key but navigatorKey.currentState is null while running in background. I tried to update a provider, but it was also null. I even tried to update a global variable but it was the old value again when the app resumed to foreground. Could anyone please publish code example in which onBackgroundMessage has any impact on the user? (not only printing to the console).
The reason that I really want to use onBackgroundMessage is because when I get the notification while running in background, onResume and onLaunch are triggered only if I click the notification. If I click the app icon, the notification stays and nothing is triggered. I have no way to tell the user about the notification. If someone finds a way to read notifications that the user didn't click yet, that would help even more.
This is my code. When pressing button 1, a notification is sent after a delay of 5 seconds (to let the user time to put the app in background). When pressing button 2, a data message is sent.
Uppon recieving the message the three counters are incremented. But in some cases nothing happens.
expected result
In all scenarios all three counters should increment.
Actual result
In case the app was running in background while the message was sent, after resuming to the app nothing happend (both with buttom 1 and 2).
The text was updated successfully, but these errors were encountered: