Blank notification appears without any code call

て烟熏妆下的殇ゞ 提交于 2019-12-11 15:22:19

问题


i experience pretty weird thing in my android app. In some unknown for me cases sometimes blank notification apperas in notification bar, without any title, body and with default gray color. The only filled thing is icon, which is my default application icon(from manifest).

There is only one place in project when i create notification manually - intent service that sends data via rest api. Notification have his own icon (different than default), color, text, progressbar and works fine when service is running. I have not configured any Cloud Messaging or push notification in this project.

I spent a lot of time and i have no idea why blank notification described above appears. I will be grateful for any hint how to prevent it.


回答1:


Yes, I am also facing this issue, when the app is closed that time notification will appear like this. I am resolved this issue in server side.

There are two types of messages in FCM (Firebase Cloud Messaging):

  1. Display Messages: These messages trigger the onMessageReceived() callback only when your app is in foreground

  2. Data Messages: Theses messages trigger the onMessageReceived() callback even if your app is in foreground/background/killed

Firebase team have not developed a UI to send data-messages to your devices, yet.

refer this link to achieve

https://fcm.googleapis.com/fcm/send

And the following headers:

Key: Content-Type, Value: application/json

Key: Authorization, Value: key=<your-server-key>

Body using topics:

{
    "to": "/topics/my_topic",
    "data": {
        "my_custom_key" : "my_custom_value",
        "other_key" : true
     }
}

Or to send it to specific devices:

{
    "data": {
        "my_custom_key" : "my_custom_value",
        "other_key" : true
     },
    "registration_ids": ["{device-token}","{device2-token}","{device3-token}"]
}

NOTE: Be sure you're not adding JSON key notification

NOTE: To get your server key, you can find it in the firebase console: Your project -> settings -> Project settings -> Cloud messaging -> Server Key



来源:https://stackoverflow.com/questions/46471879/blank-notification-appears-without-any-code-call

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