react-native-push-notification: On 6.0.0 foreground notification no longer appears on Android

Bug

I have the “notification_foreground” option in AndroidManifest.xml set to “true”, as I would like foreground notifications to appear.

In v5.1.1 of this package the notification appears as expected while the app is in the foreground.

When I update to 6.0.0 the notification no longer appears. Notifications continue to appear while the app is in the background ok.

When I roll back to 5.1.1 (with no other changes) the foreground notifications appear again.

Has something changed in 6.0.0 which would affect this behaviour?

Thanks

Environment info

react-native info output:

 // paste it here

Library version: 6.0.0

Steps To Reproduce

  1. Install 6.0.0 of this library
  2. Set “notification_foreground” to true in AndroidManifest.xml
  3. Run the app on Android
  4. Trigger a remote notification while the app is open in the foreground
  5. Don’t see the notification appear
  6. Roll back to 5.1.1 and repeat the steps
  7. See the notification appear while the app is open in the foreground …

Describe what you expected to happen:

Foreground notification behaviour doesn’t change between version 5.1.1 and 6.0.0.

Reproducible sample code

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 37

Commits related to this issue

Most upvoted comments

Hey I’m using version 7.0.0 and I’m experiencing same problem. I’ve created my channel:

PushNotification.createChannel(
      {
        channelId: INTERNAL_NOTIFICATIONS_CHANNEL, // (required)
        channelName: '..., // (required)
        channelDescription: '...', // (optional) default: undefined.
        soundName: 'default', // (optional) See `soundName` parameter of `localNotification` function
        importance: 4, // (optional) default: 4. Int value of the Android notification importance
        vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
      },
      (created) => console.log({created}), // (optional) callback returns whether the channel was created, false means it already existed.
    );

And I’m reacting to notification like this:

  PushNotification.localNotification({
          id: messageId,
          title: notification.title, // (optional)
          message: notification.body, // (required)
          userInfo: data,
          channelId: INTERNAL_NOTIFICATIONS_CHANNEL,
        });

It works when application is in background but not when it’s in foreground. Do you know what could I be doing wrong?

I just released the version 6.1.0. In your case you can create a channel and define it as default channel for FCM notifications in AndroidManifest, the version 6.1.0 allow this also for foreground notifications. Then you don’t need to specify the channel id in your backend. This should keep the compatibility with old versions.

Has anyone found an actual solution to this? Have followed @Dallas62’s instructions, but still no notifications while app is in the foreground.

State of the repository This repository is not actively maintained. The main reason is time. The second one is probably the complexity of notifications on both iOS and Android. Since this project probably need a huge refactor to fix some issue or to implement new features. I think you should probably consider these alternatives: Notifee free since september or react-native-notifications.

Same issue, everything works fine, besides the fact that I can’t trigger onNotification if android app is in foreground, the rest works without issues

After digging for few hours I was finally able to trigger onNotification handler for Android if app is in foreground: add to AndroidManifest.xml

<manifest>
   ...
    <application>
     ...
      <service
          android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
          android:exported="false" >
          <intent-filter>
              <action android:name="com.google.firebase.MESSAGING_EVENT" />
          </intent-filter>
      </service> 

      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground"
          android:value="true"/>
    </application>
</manifest>

For all the “+1”. First of all, this is not message which help to debug this case. Secondly, you probably copy and paste the AndroidManifest which include a line to hide notification in foreground. Regards,