使用cURL https://fcm.googleapis.com/fcm/send时,Firebase推送通知无法播放声音

时间:2017-12-11 07:17:02

标签: android firebase curl firebase-cloud-messaging android-push-notification

当我使用Firebase控制台时,通过激活" Sound"根据"高级选项"正如最佳答案所解释的那样,Mouad Abdelghafour AitAli在Firebase Push notification is not playing sound when app is in background的接受答案中写道。当我使用cURL向端点https://fcm.googleapis.com/fcm/send发出请求时,我收到通知,唯一的问题是通知不播放声音。这是我从命令提示符发送通知的方式:

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

请注意我如何使用\"sound\":\"default\",但通知仍未播放声音。它就像我提到的Firebase控制台一样工作,所以我试图理解为什么它在命令行中使用cURL不起作用。谢谢。

1 个答案:

答案 0 :(得分:3)

我将参数\"sound\":\"default\"放在错误的位置。我通过使用以下代码修复了它,并且我收到了通知,其中播放了此通知的默认声音:

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