React-native-firebase: [Push Notification] push icon change to a different icon when it is in background and foreground

Created on 18 Apr 2018  路  4Comments  路  Source: invertase/react-native-firebase

Issue

The problem seems to happen when a send a remote notification from firebase to my application.
When my app is in foreground, the notification icon is the correct one ("没") but when it is in background or when my app is closed, the notification icon is the default one ("the Robot").

I have some screenshot to demonstrate:
The first one is the notification when my app was running in foreground with the correct icon:
whatsapp image 2018-04-17 at 8 06 56 pm
The second is the same but when my app was running in background and with the default icon:
whatsapp image 2018-04-17 at 8 05 40 pm
The third is just to show that I've sent the exactly same notification but the icon are not the same:
whatsapp image 2018-04-17 at 8 07 30 pm

My source code:

     .
     .
     .

const channel = new firebase.notifications.Android.Channel('channelId', 'new-sales', firebase.notifications.Android.Importance.High)
   .setDescription('new sales avaiable')
   .enableVibration(true)
   .setLockScreenVisibility(firebase.notifications.Android.Visibility.Public)

   // Create the channel
firebase.notifications().android.createChannel(channel);

var realNotification = new firebase.notifications.Notification()

firebase.messaging().hasPermission().then(enabled => {
    if (enabled) {
        this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification : Notification) => {
     .
     .
     .
        });
        this.notificationListener = firebase.notifications().onNotification((notification : Notification) => {
            realNotification = new firebase.notifications.Notification()
            .setNotificationId("033")
            .setTitle(notification.title)
            .setBody(notification.body)
            .android.setChannelId('channelId')
            .android.setSmallIcon('icon')
            firebase.notifications().displayNotification(realNotification)
        });
    } 
     .
     .
     .

P.S. Sorry for my bad english, this is my first post here.

Environment

  1. Application Target Platform:
    Android

  2. Development Operating System:
    macOS High Sierra

  3. Build Tools:
    Android studio

  4. React Native version:
    0.54.2

  5. RNFirebase Version:
    4.0.3

  6. Firebase Module:
    Notifications

Notifications Android Question

All 4 comments

Hey, I've just figured out that if i change my It works but it also change my icon. So I would like to know if I can have an app icon different of my notification icon.

  <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/icon"  // I changed this line.
      android:theme="@style/AppTheme">
   .
   .
   .
   .
   .
   .
   <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@mipmap/icon"
        />

@rogBordignon yes, I think you should be able to put 2 separate icons

@rogBordignon as you mentioned yes, you can customise this using meta content in your android manifest, see the docs here: https://rnfirebase.io/docs/v4.0.x/notifications/android#Default-icon-and-color-(Optional) and this can be any icon in your android resources, it doesn't have to be your app icon, we just use that as an example.

Hi guys, here is my meta-data that I added to the Android Manifest file

<meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/background_splash" />

However I could not get the desired result on getting the notification on the app. What could be the possible error?

Was this page helpful?
0 / 5 - 0 ratings