Jai*_*oya 1 android curl firebase firebase-cloud-messaging android-push-notification
当我使用 Firebase 控制台时,通过激活“高级选项”下的“声音”,一切都很完美,正如最佳答案 Mouad Abdelghafour AitAli 在Firebase Push notification is not Playing sound while app is in back 的接受答案中所解释的那样。当我使用 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"}]}
Run Code Online (Sandbox Code Playgroud)
请注意我如何使用\"sound\":\"default\",但通知仍然没有播放声音。正如我提到的,它可以在 Firebase 控制台上运行,所以我试图理解为什么它不能从命令行使用 cURL 运行。谢谢。
我的参数放\"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"}]}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2328 次 |
| 最近记录: |