Flutter app when receiving firebase push notifications in foreground shows the error: "Reading a NULL string not supported here."

Viewed 259

I have integrated Firebase Cloud Messaging(FCM) in my flutter app. Notification is working fine in both background and terminated state. But when handling foreground messages, the error showing E/Parcel (27639): Reading a NULL string not supported here.

The following is the code.

  FirebaseMessaging.onMessage.listen((RemoteMessage message) {
    final notification = message.notification;
    print(notification?.body);
  });

Note: The issue only happens when accessing notification.body, otherwise no problem.

1 Answers

When you are receiving a notification when you are in foreground. you need to add below in you androidManifest.xml after the end of activity tagand before end of application tag:

<!-- [START firebase_service] -->
    <service
        android:name="com.google.firebase.messaging.FirebaseMessagingService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
<!-- [END firebase_service] -->

after this run/build your project again. know you will get your body text.

Related