3

I have configured remote notifications, and everything is working as expected. Now I want to set a custom sound to my remote notifications. I have tried many ways but these are not working. I am using react-native-push-notification and react-native-firebase.

I have placed a custom sound file in android/app/src/main/res/raw/sound.mp3.

I have also tried soundName:"sound.mp3" I appreciate any help in this regard. Thanks. :) Below is the sample Code:

PushNotification.configure({
      onRegister: async function(token) {

      },
      onNotification: function(notification) {
        console.log(notification);
      },
      senderID: 'xxxx',
      permissions: {
        alert: true,
        badge: true,
        sound: true,
      },
      playSound: true,
      soundName: 'sound.mp3',
      popInitialNotification: true,
      requestPermissions: true,
    });
  }````
Aleem
  • 93
  • 2
  • 14

1 Answers1

0

For android you must provide a channel id with channelId: "your-channel-id", if the channel doesn't exist the notification might not be triggered.

NOTE: Without channel, notifications might not work

  PushNotification.createChannel(
    {
      channelId: "channel-id", // (required)
      channelName: "My channel", // (required)
      soundName: "sound.mp3",
      importance: 4,
      vibrate: true,
    },
    (created) => console.log(`createChannel returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
  );

In the soundName option you put your custom sound name for this channel (for default sound, use 'default'), and use the channel Id when sending a notification