evollu / evollu/react-native-fcm

show_in_forground doesn't work

Open
#181 16 comments 4 reactions 0 assignees View on GitHub
investigating
Dominant language
Java
Stars
1.7k
Forks
661
PR merge metrics
No merged PRs in 30d

Description

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](https://cloud.githubusercontent.com/assets/2935309/19840539/37055cf8-9eb5-11e6-8e3b-e67b58236538.png)
Only in system tray

![ss22](https://cloud.githubusercontent.com/assets/2935309/19840540/3b114e42-9eb5-11e6-92c4-aeeda8d1e43b.png)
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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.