FirebasePushNotificationPlugin icon indicating copy to clipboard operation
FirebasePushNotificationPlugin copied to clipboard

Custom sound not played when app is on foreground

Open Leobaillard opened this issue 6 years ago • 17 comments

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

Leobaillard avatar Mar 20 '18 15:03 Leobaillard

What Android OS version is the phone running on?

rdelrosario avatar Mar 21 '18 05:03 rdelrosario

The phones I tested used 6.0 and 6.0.1.

Leobaillard avatar Mar 21 '18 07:03 Leobaillard

I see you are not using plugin latest version so is hard to tell if is an specific version issue.

rdelrosario avatar Mar 23 '18 11:03 rdelrosario

I updated to the latest version of the plugin, latest Visual Studio, latest Android support libs and Google Play Services. The problem persists.

Leobaillard avatar Mar 26 '18 14:03 Leobaillard

How are you sending the payload?

rdelrosario avatar Mar 26 '18 19:03 rdelrosario

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"
   }
}

Leobaillard avatar Mar 27 '18 08:03 Leobaillard

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"
   }

}

rdelrosario avatar Mar 27 '18 15:03 rdelrosario

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.

Leobaillard avatar Mar 28 '18 09:03 Leobaillard

Where do you have the sound file? should be in your Resources/raw folder.

rdelrosario avatar Mar 28 '18 13:03 rdelrosario

It is, indeed, in Resources/raw image

Leobaillard avatar Mar 28 '18 13:03 Leobaillard

@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.

rtarta avatar Jun 07 '18 00:06 rtarta

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

larryolocke avatar Jun 07 '18 22:06 larryolocke

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?

larryolocke avatar Oct 08 '18 14:10 larryolocke

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

larryolocke avatar Oct 08 '18 14:10 larryolocke

Is there any update on this? I also can't get any custom sounds to play with the notifications.

seanmt13 avatar Jan 31 '20 22:01 seanmt13

Is there any update on this? I also can't get any custom sounds to play with the notifications.

AyhamNasser avatar Jun 13 '20 13:06 AyhamNasser

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.

R0BER avatar Sep 02 '20 08:09 R0BER