Firebase Cloud Messaging custom sound

Hey !

I am implementing an app that uses notifications with the help of Firebase Native and I’m having a hard time placing my custom sound file in the app. Does anybody know where to place it ? I have tried pretty much everywhere with no success.

Thank you !

1 Like

In android, you should place your file in /platforms/android/res/raw/custom_sound.mp3 and set notification`s sound property value with custom_sound.mp3 like below.

notification: {
          title: 'abc',
          body: 'aaaaaa',
          sound: 'custom_sound.mp3'
        }

In ios, Add files to Resources directory within the Xcode project in /platforms/ios/project-name.xcodeproj.
For more detail specification, You can refer to https://documentation.onesignal.com/v3.0/docs/customize-notification-sounds.

1 Like

any one get success on FCM custom sound effect?

put this line in config.xml

<resource-file src="src/assets/sound/sound.mp3" target="app/src/main/res/raw/sound.mp3" />

Hi, i have problem with playing custom sound in ios,
what i did are set

    const options: PushOptions = {
     android: {
       sound: 'true',
       vibrate: 'true'
     },
       ios: {
           alert: 'true',
           badge: true,
           sound: 'true'
       }
    };

then

        registration_ids : this.tokenList,
        notification:{
           title: "title",
           body: "body",
           sound: "sound"
        },
        data: {
          somethiing:""
        }

in config.xml
<resource-file src="src/assets/sound/sound.wav" target="sound.wav" />

but it only plays the default sound, do u hv any idea why

1 Like

I am using the fcm plugin. but custom sound is not working on android oreo (ios works perfectly). I found that we now need to create a channel in plugin and pass the channel id in the server site. However, I can’t find anywhere in the fcm plugin doc to do the channel. Anyone here know how to do custom sound on android oreo? Thanks

did you got the answer??

sorry for the late response

try this before initialising push plugin
var channelId = “emergency”;
this.push.createChannel({
id: channelId,
description: “Emergency Channel”,
importance: 4,
sound: “police_siren”,
}).then(() => console.log(‘Channel created’));

then, my push payload
let pushData = {
registration_ids : ,
data: {
notId: null, // notId on Android needed to be an int and not a string
title: “”,
body: “”,
soundname: “police_siren”,
android_channel_id: “emergency”,
}
}

Hope this will help anyone who still figuring out how.

my ios payload

    let pushData = {
      registration_ids : [ ],
      notification:{
         sound: "police_siren.mp3",
         title: "",
         body: "",
      },
      data: {
        param1:"",
        param2:""
      }
    }

in config.xml

    <resource-file src="src/assets/sound/police_siren.wav" target="police_siren.wav" />
    <resource-file src="src/assets/sound/police_siren.caf" target="police_siren.caf" />
    <resource-file src="src/assets/sound/police_siren.mp3" target="police_siren.mp3" />

not sure if .wav and .caf is really needed