How to get gcm.notification.body field in gcm push notification payload

这一生的挚爱 提交于 2019-12-13 04:23:06

问题


I'm making set of scripts in kotlin for testing push notifications in order to refactor notification-related legacy code. I need to send post request to gcm server with such payload that would result in notification that arrives at my phone containing field "gcm.notification.body" and I cant seem to be able to do it. Currently I'm trying to figure out the payload by using Postman. "Closest" I got is "gcm.notification.data" and "fcm.notification.body".

First with this request body:

{  
    "to":  "someDeviceToken",
    "notification":{
        "data":{
            "title": "Title supported",
            "message": "Notification Message",
            "type": "example",
            "id": 345,
            "priority": 1,
            "data": {
                "images": [ 
                    "https://someimage.com/image.png"
                ]
            }
        }
    }
}

Second with this one:

{  
    "to":  "someDeviceToken",
    "data":{
        "fcm.notification.body":{
            "title": "Title supported",
            "message": "Notification Message",
            "type": "example",
            "id": 345,
            "priority": 1,
            "data": {
                "images": [ 
                    "https://someimage.com/image.png"
                ]
            }
        }
    }
}

I can't find anything anywhere. Thank you


回答1:


It's a little hacky but with colleague, we were able to figure out solution to this. Proper payload JSON would be like this:

{   
    "to":  "someDeviceToken",
    "data":{
        "gcm.notification.e": 0,
        "gcm.notification.body":{
            "title": "Title supported",
            "message": "Notification Message",
            "type": "example",
            "id": 345,
            "priority": 1,
            "data": {
                "images": [ 
                    "https://someimage.com/image.png"
                ]
            }
        }
    }
}

"gcm.notification.e": 1 doesn't work - it has to be 0.



来源:https://stackoverflow.com/questions/51058625/how-to-get-gcm-notification-body-field-in-gcm-push-notification-payload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!