Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom sound not played when app is on foreground #123

Open
Leobaillard opened this issue Mar 20, 2018 · 17 comments
Open

Custom sound not played when app is on foreground #123

Leobaillard opened this issue Mar 20, 2018 · 17 comments

Comments

@Leobaillard
Copy link

Leobaillard commented Mar 20, 2018

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

@rdelrosario
Copy link
Member

What Android OS version is the phone running on?

@Leobaillard
Copy link
Author

The phones I tested used 6.0 and 6.0.1.

@rdelrosario
Copy link
Member

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

@Leobaillard
Copy link
Author

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

@rdelrosario
Copy link
Member

How are you sending the payload?

@Leobaillard
Copy link
Author

Leobaillard commented Mar 27, 2018

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

@rdelrosario
Copy link
Member

rdelrosario commented Mar 27, 2018

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

}

@Leobaillard
Copy link
Author

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.

@rdelrosario
Copy link
Member

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

@Leobaillard
Copy link
Author

It is, indeed, in Resources/raw
image

@rtarta
Copy link

rtarta commented Jun 7, 2018

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

@larryolocke
Copy link

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
Copy link

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
Copy link

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

@seanmt13
Copy link

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

1 similar comment
@AyhamNasser
Copy link

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

@R0BER
Copy link

R0BER commented Sep 2, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants