Android device not receiving notification message when the app is terminated using Flutter and FCM

2,631

Solution 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.

Solution 2

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-

Share:
2,631
dshukertjr
Author by

dshukertjr

LinkedIn: https://www.linkedin.com/in/dshukertjr/ Flutter, Next.js, Supabase and more!

Updated on December 06, 2022

Comments

  • dshukertjr
    dshukertjr over 1 year

    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
    dshukertjr over 5 years
    I actually tried sending notification from Firebase Console, and the same happened. Received notification when in background, but not when app is terminated.
  • dshukertjr
    dshukertjr over 5 years
    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.
  • HSV_DO
    HSV_DO over 4 years
    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?
  • benyamin
    benyamin over 4 years
    its a long time i'm not working with that , but almost yes , maybe become solved with some received which writed in java native.
  • b.john
    b.john almost 4 years
    how can i do that.