FirebasePushNotificationPlugin
FirebasePushNotificationPlugin copied to clipboard
Custom sound not played when app is on foreground
Bug Information
Version Number of Plugin: 2.1.3 Device Tested On: Huawei P8 & OnePlus One Simulator Tested On: / Version of VS: 15.5.2 Version of Xamarin: (Forms) 2.5.0.121934 Versions of other things you are using: Xamarin.Firebase.Common 42.1021.1
Steps to reproduce the Behavior
- Have a sound in "resources/raw/app_sound.wav"
- Send FCM Message with "sound" key set to "app_sound.wav"
- Receive the message when app is foregrounded
Expected Behavior
The sound "app_sound.wav" gets played when receiving a notification on foreground and background.
Actual Behavior
When the app is backgrounded or closed and a notification is received, the app_sound.wav is played correctly along with notification vibrations. When the app is foregrounded and receiving a notification (with the same payload), only the vibration is present, no sound.
When using FirebasePushNotificationManager.SoundUri
and the sound
key is removed from the notification payload, the custom sound is played as expected, but only when the app is foregrounded. When doing it this way, there is no sound nor vibration when receiving a notification when the app is backgrounded.
Code snippet
I tried to add FirebasePushNotificationManager.SoundUri = Uri.Parse("android.resource://com.app.simone/" + Resource.Raw.app_sound);
on Android, but that does not change (see above).
Screenshots
N/A
What Android OS version is the phone running on?
The phones I tested used 6.0 and 6.0.1.
I see you are not using plugin latest version so is hard to tell if is an specific version issue.
I updated to the latest version of the plugin, latest Visual Studio, latest Android support libs and Google Play Services. The problem persists.
How are you sending the payload?
I'm using an API made with Symfony and redjanym's FCM Bundle. Here is the sent JSON:
{
"to":"<FCM_ID>",
"data":{
"action":"rideAccepted",
"silent":false,
"msg":"La course r\u00e9serv\u00e9e a d\u00e9marr\u00e9e. Cliquez pour ouvrir.",
"ride":606
},
"priority":"high",
"content_available":true,
"notification":{
"body":"La course r\u00e9serv\u00e9e a d\u00e9marr\u00e9e. Cliquez pour ouvrir.",
"sound":"app_sound.wav"
}
}
On Android you shouldn't send the notification key if you want the plugin to handle the ui should use data messages instead, how you are sending it now FCM is the one handling the ui. I explain this on Receiving Push Notifications
When sending to Android platform should be:
{
"to":"<FCM_ID>",
"data":{
"action":"rideAccepted",
"silent":false,
"msg":"La course r\u00e9serv\u00e9e a d\u00e9marr\u00e9e. Cliquez pour ouvrir.",
"body":"La course r\u00e9serv\u00e9e a d\u00e9marr\u00e9e. Cliquez pour ouvrir.",
"sound":"app_sound.wav",
"ride":606,
"priority":"high"
}
}
I tried to put everything in the "data" object as you suggested. I still receive the notification data correctly but the sound does not play. Either when the app is in the foreground or backgrounded/closed/killed.
Where do you have the sound file? should be in your Resources/raw folder.
It is, indeed, in Resources/raw
@Leobaillard i tried the same process and i could run the sound. in background mode. check build type. remove the sound add again. i prefered to use mp3 file.
I am having the same issue. Also up to date and using an mp3 file located in resources>raw. I have tried using the name of the file with and without the .mp3
I have tried setting SoundUri and sill cannot get it to work. my mp3 is set to AndroidResource for build type, and is nested in the Resource/Raw folder. I have removed and added the sound file back with a clean and rebuild after both remove and add. Nothing seems to work I always get the default notification sound on the device. Any help please?
Debug log shows
10-08 09:38:46.152 W/Notification(22671): Use of stream types is deprecated for operations other than volume control 10-08 09:38:46.152 W/Notification(22671): See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case 10-08 09:38:46.157 D/Notification(22671): allPendingIntents
Is there any update on this? I also can't get any custom sounds to play with the notifications.
Is there any update on this? I also can't get any custom sounds to play with the notifications.
Alguna novedad con esto? no se si es por fallo de configuración mio o por los continuos cambios de google pero no consigo un sonido personal.