Can't specify a custom notification sound
Hi, Thanks for this module
I'm trying to set a custom notification sound to my app. I have an mp3 file that I'm trying to use as the sound.
I tried adding the mp3 file to the xCode project, and then passing the reference to the "setSound" method as a string
.setSound('notifSound.mp3')
I also tried passing a "require" function to the method
.setSound(require('notifSound.mp3'))
but it didn't workout and the default notification sound was played.
I tried to look for a guide in the documentation, but little was said about custom notifications sound. Any idea on how to make this work?
Good evening,
I have the same problem too. Any solution?
Thank you
react: ^16.4.1 react-native: ^0.56.0 react-native-firebase: ^4.3.7
I have the same problem, can't specify a custom sound, when I try to set it, the notification plays the default sound and then no notification is shown, in the other hand, when I don't try to set a custom sound the notification shows up correctly but playing the default sound. Is there any solution for this? Or maybe downgrading to a previous version? Thank you.
react: 16.3.1 react-native: 0.55.1 react-native-firebase: ^4.3.8
Hi, @Darking360 and @Jonnyboy85
I managed to set a custom sound by adding the mp3 file to the Xcode project.
That is by dragging the file and dropping it on the project's Folder in the Project Navigator. You then pass the file's name as a string to the setSound method like this:
notification = new firebase.notifications.Notification().setSound('glass.mp3')
Hi @ahmedXabdeen,
I'm testing notifications with Android Oreo. To make setSound work on the notification, you must first create the channel.
const channel = new firebase.notifications.Android.Channel(name, Desc, firebase.notifications.Android.Importance.High) .setDescription(ChannelName) .setSound(glass.mp3) <--- ... firebase.notifications().android.createChannel(channel);
And then:
const notification = new firebase.notifications.Notification() .setNotificationId(id) .setTitle(title) .setSound(channel.sound); <---
notification .android.setChannelId(channel.channelId) <--- firebase.notifications().displayNotification(notification);
This works.
You can set up multiple channels with different sounds and use them as you like, replacing the method with the following method:
firebase.notifications (). android.createChannel (channel);
with this:
firebase.notifications (). android.createChannels (channelsArray);
Thank you so much for this feedback! @Jonnyboy85
@Jonnyboy85 I try this, but not work to me
const channel = new firebase.notifications.Android.Channel('vtr_channel', 'vtrChannel', firebase.notifications.Android.Importance.High)
.setDescription('vtrChannel')
.setSound(sound);
firebase.notifications().android.createChannel(channel);
const notification = new firebase.notifications.Notification()
.setNotificationId(notificationId)
.setTitle(title)
.setBody(body)
.setData(data)
.setSound(channel.sound);
notification
.android.setChannelId(channel.channelId)
.android.setSmallIcon('notification')
.android.setColor('red');
firebase.notifications().displayNotification(notification);
Hi @patrickalbani,
is the sound located under the res / raw folder?
@Jonnyboy85 yes. In older versions worked as expected
Hi @patrickalbani,
what version do you have of react-native? I had problems with Android O in versions before 0.56.0.
If you need to upgrade react-native to version ^0.56, I remind you that you need to upgrade babel to version ^7.0.0-beta.47.
@Jonnyboy85 you save my day, upgrade to 0.56 and worked. Thank you so much
i have upgraded to 0.57 and i can't specify a custom sound, just the default sound. Have someone a working example? How should i use the filename in the .sound() method?
what i done:
- put a file
notif.mp3inres/raw - use the sound method to specify the sound
async onNotificacion(fcmNotification: FCMNotification) {
const notification = new firebase.notifications.Notification()
.setNotificationId(fcmNotification.data.notificacionId)
.setTitle(fcmNotification.title)
.setBody(fcmNotification.body)
.setData(fcmNotification.data)
.setSound('notif.mp3') // 'notif' 'notif.mp3' or how? it works with 'default'
.android.setChannelId(FIREBASE.ANDROID_CHANNEL)
.android.setColor(Colors.appColor)
.android.setAutoCancel(true)
.android.setSmallIcon('ic_stat_notf');
firebase.notifications().displayNotification(notification);
}
Hi @dengue8830 ,
did you include setSound also in the channel?
const channel = new firebase.notifications.Android.Channel('vtr_channel', 'vtrChannel', firebase.notifications.Android.Importance.High) .setDescription('vtrChannel') .setSound('notif.mp3');
@Jonnyboy85 i have to try again to be sure, i tried in too many combinations and im not sure right now... i will try. But im using android 5 and 6, channel is mandatory even in that versions?
Hi @dengue8830 ,
as written in the guide below the creation of the channels starts from Android 8.0 (API level 26): https://developer.android.com/training/notify-user/channels
The steps you need to follow are therefore:
- channel creation (with setSound)
- creation of the notification (with channel id and setSound)
If you want to create notifications with different sounds, create more channels and associate the id in the notification.
I hope I have been helpful.
ios scheduleNotification with customSound not work in foreground (it work with default sound). Only work in background. Anyone can help pls?
Hello 👋, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.
when i send notifications from the firebase panel sounds works, so the problem could be in sender message config. I didn't found a working example with the latest version of this lib and enabled sound
Hello 👋, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.
Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.
I already set two channels with different sound file... but why it wont work as expected...