react-native-fcm: show_in_forground doesn't work

I’m using RN 35.0 and Android 6.0. Below is my code.

  componentDidMount() {
    this.notificationUnsubscribe = FCM.on('notification', (notif) => {
      // there are two parts of notif. notif.notification contains the notification payload, notif.data contains data payload
      if(notif.local_notification){
        //this is a local notification
      }
      if(notif.opened_from_tray){
        //app is open/resumed because user clicked banner
      }

      console.log(notif)

      // FCM.getBadgeNumber().then(number =>
      //   FCM.setBadgeNumber(number + 1)
      // )

      if (!notif.local_notification) {
        FCM.presentLocalNotification({
          title: "My Notification Title",                     // as FCM payload
          body: notif.body,                                   // as FCM payload (required)
          sound: "default",                                   // as FCM payload
          priority: "high",                                   // as FCM payload
          click_action: "ACTION",                             // as FCM payload
          large_icon: "ic_launcher",                           // Android only
          icon: "ic_notification",                            // as FCM payload
          color: "red",                                       // Android only
          vibrate: 300,                                       // Android only default: 300, no vibration if you pass null
          lights: true,                                       // Android only, LED blinking (default false)
          show_in_foreground: true,                           // notification when app is in foreground (local & remote)
        })
      }
    })

1. App is killed, Device is locked Notification appears in a banner

2. App is killed, Device is unlocked Notification appears in the system tray

3. App is in background Notification appears in the system tray

4. App is in foreground Notification comes in but calling FCM.presentLocalNotification({}) doesn’t show any UI (I expected to see a banner or modal coming from bottom or top)

Q1. How come notification only appears in system tray silently?

ss11 Only in system tray

ss22 Banner comes down

Q2. How do I show a banner while the user is using the app (foreground)? I thought calling FCM.presentLocalNotification({}) will show a UI (either modal or banner) inside an app to notify the user. I saw your answers in F&Q:

Use show_in_foreground attribute to tell app to show banner even if the app is in foreground. Warning: foreground banner won’t show in android for remote notification due to limitation of FCM SDK. However you can create a local notification yourself. A pull is welcome to fix this.

When you say you can create a local notification yourself. what do you mean?

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 4
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Still doesn’t work for me here. Local notification not showing when app is on foreground.