0

I'm trying to display a local notification without a sound using react-native-firebase, is that possible?

I have tried playing around with the AndroidNotification class, but couldn't find a way to do this.

  const notification = new firebase.notifications.Notification()
    .setNotificationId("notificationId")
    .setTitle("Title")
    .setBody("Text")
    .android.setBigText("Big Text")
    .android.setColor("#f04e29")
    .android.setAutoCancel(true)
    .android.setOnlyAlertOnce(true)
    .android.setChannelId("channel")
    .android.setLargeIcon("ic_launcher")
    .android.setSmallIcon("ic_notification");
  firebase.notifications().displayNotification(notification);

I would like for the notification to be displayed without any noise at all.

Edgar Barber
  • 345
  • 3
  • 13

1 Answers1

0

From my own experience, two things have to be taken into account:

  1. No setSound method must be called or no sound properties should be set
  2. When developing for Android API level >=26, the Android Importance passed as third argument of the Channel method has to be set to Low, Min or None. Otherwise the default sound is played anyway. So an example of creating your Channel (e.g. in the componentDidMount of your App.tsx):

    const channel = new firebase.notifications.Android.Channel( "testNotification", "Test Notification", firebase.notifications.Android.Importance.Low ) firebase.notifications().android.createChannel(channel);

And then showing a nonobtrusive notification:

const notification = new firebase.notifications.Notification()
  .setTitle("My notification title")
  .setBody("My notification body");
notification.android.setChannelId("testNotification");
firebase.notifications().displayNotification(notification);
Jenever
  • 500
  • 5
  • 17