Foreground notifications not working for android with expo-firebase-notifications


#1

Hi there, thanks in advance for any help!

I have an ejected expo app, and I’m trying to set up FCM using expo-firebase-notifications.

I have followed the guides for setting up the following modules




Everything is working perfectly for iOS. However, with Android I am only able to read the payload for notifications on a cold start, (using firebase.notifications().getInitialNotification(). I have hooked up onNotificationOpened and onNotification, neither of which receive notifications. I have also set up listeners for onNotificationDisplayed and onMessage just incase.

firebase
      .notifications()
      .getInitialNotification()
      .then(notificationOpen => {
        console.log('getInitialNotification: ', notificationOpen);
        // --> only this one works
      })
      .catch(() => {});

    firebase.notifications().onNotificationOpened(notification => {
      console.log('onNotificationOpened: ', notification);
    });

    firebase.notifications().onNotificationDisplayed(notification => {
      console.log('onNotificationDisplayed: ', notification);
    });

    firebase.notifications().onNotification(notification => {
      console.log('onNotification: ', notification);
    });

    firebase.messaging().onMessage(message => {
      console.log('messaging:message: ', message);
      // Process your message as required
    });

I’ve been combing through the Java source and the only onMessageReceived handler I can find is in EXFirebaseMessagingService.java - when I set a breakpoint here the notification is being caught, but this isn’t making it to the Javascript handler.

I think I must be missing some bit of config - perhaps in AndroidManifest.xml but I’ve been through the docs and I can’t see what I’m missing.

I have tried the following:

Adding the following in addition to the FCM and GCM config that comes from the ejected app. I have also tried removing the FCM and GCM config, and just adding the following.
I have also tried without FCM, GCM, or the following. All of which will work from cold start, but the listener does nothing.

<service android:name="expo.modules.firebase.messaging.EXFirebaseMessagingService">
      <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
      </intent-filter>
    </service>
    <!--Inlcude this for Background Messages-->
    <service android:name="expo.modules.firebase.messaging.FirebaseBackgroundMessagingService" />

I have also tried adding the section required for scheduled notifications incase this has any impact - it doesn’t…

<!-- Scheduled Notifications -->
    <receiver android:name="expo.modules.firebase.notifications.FirebaseNotificationReceiver"/>
    <receiver android:enabled="true" android:exported="true"  android:name="expo.modules.firebase.notifications.FirebaseNotificationsRebootReceiver">
      <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
        <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
        <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
        <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
    </receiver>

Any pointers would be gratefully received - I’ve been going around in circles with this for a couple of days now!

Thanks

Tom


#2

Its broken. Won’t work till EXPO 32. The headless tasks don’t work with ejected expo apps.

For my work around when I send the notification from the server I also send a socket.io emit. This way I can handle what ever the notification was supposed to do.

In reality they should have a big ASS warning sign saying it wont work in ejected app


#3

Ah, righty. Thanks for very much for that - will save me spending any more time digging!


closed #4

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.