【问题标题】:Firebase Push notification is not playing sound when using cURL https://fcm.googleapis.com/fcm/send使用 cURL https://fcm.googleapis.com/fcm/send 时,Firebase 推送通知未播放声音
【发布时间】:2017-12-11 15:42:23
【问题描述】:

当我使用 Firebase 控制台时,通过激活“高级选项”下的“声音”,一切都很完美,正如 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。谢谢。

【问题讨论】:

  • @Nilu 我的AndroidManifest.xml 中已经有&lt;uses-permission android:name="android.permission.VIBRATE" /&gt;。从 Firebase 控制台发送推送通知时,我已经从 Firebase 控制台启用了声音选项,但正如我在问题中提到的那样,这是可行的,但是当我使用 cURL 从命令提示符发送通知时,声音不会播放。我在我的有效载荷中使用声音键。我已经完成了您分享的链接 (stackoverflow.com/questions/46586215/…) 中的建议。

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


【解决方案1】:

我把参数\"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"}]}

【讨论】:

    猜你喜欢
    • 2018-11-18
    • 2021-02-21
    • 2022-07-12
    • 2018-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-23
    相关资源
    最近更新 更多