question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

show_in_forground doesn't work

See original GitHub issue

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?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
avishayilcommented, Jan 23, 2017

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

0reactions
anurak-kgcommented, Mar 21, 2018

same problem but cause from my phone notification setting

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found