No custom sound with Android Firebase Notification

后端 未结 6 1594
轮回少年
轮回少年 2021-01-17 10:39

I am using Firebase push notifications in my Android App. I can send correctly notification with custom icon, but I have not managed to play my custom sound. I always get th

6条回答
  •  孤街浪徒
    2021-01-17 11:11

    Maybe this helps : In my case i tried with the above approach and it did not worked, whenever i was checking in the onMessageReceived (for debug purpose) the channel id

    Log.e(TAG, "Message Notification channel id: " + remoteMessage.getNotification().getChannelId()); 
    

    i always got 'null'.

    So reading the documentation from here https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support

    I found out that i was using the wrong key for the channel id in the json.

    Instead of 'channel_id' key try to use 'android_channel_id' key like this

    "notification": {
            "body": "Body of Your Notification",
            "title": "Title of Your Notification",
            "android_channel_id": "channelId",
            "icon": "myIcon"
        }
    

    If i use it like that it works as expected, custom sound (from res/raw) is played

    PS: in my case i set my sound on the channelId when i created it

    Good luck !

提交回复
热议问题