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:
1) put a file notif.mp3
in res/raw
2) 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:
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...
which sender message config are you using?
what about custom sound at iOS?
@dominicsavb
const notification = new firebase.notifications.Notification()
.setNotificationId('123123')
.setTitle('My notification title')
.setBody('My notification body')
.setData({
key1: 'value1',
key2: 'value2',
})
.android.setChannelId(channel.channelId)
.android.setSmallIcon('ic_launcher')
.setSound('alarm.wav')
.ios.setBadge(2);
firebase.notifications().andr.displayNotification(notification);
this worked for me
I am not able to set custom sound, if i set all i can hear is the default one
I added the .mp3
files to res/raw
folder in android
const channel = new firebase.notifications.Android.Channel('xyz-channel',
'Test Channel', firebase.notifications.Android.Importance.Max)
.setSound('hollow.mp3')
.setDescription('WFX Channel');
firebase.notifications().android.createChannel(channel);
// Create notification
const notification = new firebase.notifications.Notification()
.setNotificationId('notificationId')
.setTitle('My notification title')
.setBody('My notification body')
.setSound(channel.sound)
.android.setChannelId('xyz-channel');
firebase.notifications().displayNotification(notification)
wrote the above code
and using
"react-native": "0.59.9",
"react-native-firebase": "^5.5.4"
and am running on Android 9 Pie
did i miss anything or did i do something wrong ?
I normally don't like commenting on closed issues but I remembered seeing this, and I just read the release notes for the most recent firebase messaging android sdk release https://firebase.google.com/support/release-notes/android#version_2000
They added support for a number of notifications things, perhaps these two things mix in together productively
Hi, where exactly I should put res/raw directory in android?
with
it's not working...
Please help me out with this one
with
it's not working...
Please help me out with this one
check the attachment, you can find the res/raw directory here
with
it's not working...
Please help me out with this onecheck the attachment, you can find the res/raw directory here
res/raw directory is corrent i check it 4 times.....
defalut sound is also not working..
i am using firebse 5
don't forget put meta chanel id in AndroidManifest.sml
it work for me! :D
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id" />
and put string in string.xml
<string name="default_notification_channel_id">your-chanel-id</string>
Most helpful comment
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);