6

I am developing an app using Flutter, and I am implementing push notification using FCM with the firebase_messaging Flutter plug in:

https://pub.dartlang.org/packages/firebase_messaging

on the Readme.md of this plugin, it says when an Android device receives data message while the app has been terminated, the message will be lost, but when the device receives a notification message, the message will show up at the app tray whether the app has been terminated or just in the background.

I have implemented this plugin and it is not behaving the way Readme.md describes. Notification message gets lost on my android device when the app has been terminated.

Here is a sample payload I am sending to the device:

var payload = {
  notification: {
    title: `message from somebody`,
    body: `message text here`,
    }
}

What am I possibly doing wrong? Am I missing something in the payload, or is it something else?

dshukertjr
  • 15,244
  • 11
  • 57
  • 94

2 Answers2

4

the firebase_messaging package is not supporting the Data Message receivation when the app is terminated in android and only when app is open or in background.
its saying this about Data Message Receivation When the app is Terminated in android : not supported by plugin, message is lost.
and about the notification , Notification is delivered to system tray. When the user clicks on it to open app onLaunch fires if click_action: FLUTTER_NOTIFICATION_CLICK is set.

take a look at that table in the receiving Messages : https://pub.dartlang.org/packages/firebase_messaging#-readme-tab-

ben
  • 740
  • 7
  • 16
  • So i guess we have to implement a native Android service to handle these background messages (when the app is terminated), right? Or is there something special about native code in combination with Flutter? – HSV_DO Nov 15 '19 at 08:50
  • its a long time i'm not working with that , but almost yes , maybe become solved with some received which writed in java native. – ben Jan 21 '20 at 13:04
  • how can i do that. – b.john Jul 04 '20 at 20:11
1

Have you tried using the Firebase Console to send a message. It might be worth while to send a test message using Firebase Console. This way you will be able to eliminate the possibility of having a mistake in your payload.

Another thing to verify would be implementing onMessage onResume and onLaunch in the app and also including a custom data key value pair of click_action: FLUTTER_NOTIFICATION_CLICK in your message.

Last thing would be to check google-services.json was placed in the right folder android/app and also checking both android/build.gradle, android/app/build.gradle were correctly modified.

I hope I was able to provide little help. Let me know if this works.

ssiddh
  • 480
  • 1
  • 6
  • 18
  • I actually tried sending notification from Firebase Console, and the same happened. Received notification when in background, but not when app is terminated. – dshukertjr Sep 12 '18 at 04:41
  • I tried sending message with click_action key in the data of the payload, but still the same... Since I am getting notifications when the app is in the background, I think my google-services.json is configured correctly. – dshukertjr Sep 12 '18 at 04:47