1

When I use the Firebase console, everything is perfect by activating "Sound" under the "Advanced options" as explained by the best answer Mouad Abdelghafour AitAli wrote in the accepted answer at Firebase Push notification is not playing sound when app is in background. When I use cURL making the request to the endpoint https://fcm.googleapis.com/fcm/send, I receive the notification and the only problem is that the notification does not play the sound. This is how I am sending the notification from the command prompt:

C:\curl>curl -k -X POST --header "Authorization: key=<My authorization key>" --header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"to\":\"<Token of device that receives the notification>\",\"notification\":{\"body\":\"Yellow\"},\"priority\":10,\"sound\":\"default\"}"
{"multicast_id":4910170660116070247,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1512975815064180%efad4c69efad4c69"}]}

Notice how I am using \"sound\":\"default\", but the notification is still not playing the sound. It works from the Firebase console as I mentioned, so I am trying to understand why it does not work using cURL from the command line. Thank you.

Jaime Montoya
  • 6,915
  • 14
  • 67
  • 103
  • https://stackoverflow.com/a/46586285/7666442 – AskNilesh Dec 11 '17 at 07:19
  • @Nilu I already have `` in my `AndroidManifest.xml`. I already enabled the sound option from the Firebase console when sending push notifications from the Firebase console but as I mentioned in my question, that works, but when I send the notification from the command prompt using cURL, the sound does not play. I am using the sound key in my the payload. I have already done what is suggested in the link you shared (https://stackoverflow.com/questions/46586215/android-notification-not-getting-sound-and-vibration/46586285#46586285). – Jaime Montoya Dec 11 '17 at 07:25

1 Answers1

5

I had the parameter \"sound\":\"default\" in the wrong place. I fixed it by using this the following code, and I received the notification with the default sound playing for this notification:

C:\curl>curl -k -X POST --header "Authorization: key=<My authorization key>" --header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"to\":\"<My device token>\",\"notification\":{\"body\":\"Yellow\",\"sound\":\"default\"},\"priority\":10}"
{"multicast_id":6830402283642572741,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1512977917758257%efad4c69efad4c69"}]}
Jaime Montoya
  • 6,915
  • 14
  • 67
  • 103