出现空白通知,没有任何代码调用 [英] Blank notification appears without any code call

查看:200
本文介绍了出现空白通知,没有任何代码调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的android应用程序中遇到了很奇怪的事情.在我不知道的情况下,有时通知栏中的通知属性为空白,没有任何标题,正文和默认灰色.唯一填充的是图标,这是我的默认应用程序图标(来自清单).

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).

当我手动创建通知时,项目中只有一个地方-通过rest api发送数据的意图服务.通知具有自己的图标(与默认图标不同),颜色,文本,进度栏,并且在服务运行时工作正常.我尚未在该项目中配置任何Cloud Messaging或推送通知.

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.

推荐答案

是的,我也面临这个问题,当应用程序关闭时,时间通知将像这样出现.我已经在服务器端解决了这个问题.

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.

FCM(Firebase云消息传递)中有两种消息类型:

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

  1. 显示消息:仅当您的应用程序位于前台时,这些消息才触发onMessageReceived()回调

数据消息:即使您的应用程序处于前台/后台/已终止状态,这些消息也会触发onMessageReceived()回调

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

Firebase团队尚未开发出可将data-messages发送到您的设备的UI.

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

引用此链接即可实现

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

以及以下标题:

键: Content-Type值: application/json

键: Authorization值: key=<your-server-key>

使用主题的正文:

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

或将其发送到特定设备:

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

注意:请确保您没有添加JSON密钥通知

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

注意::要获取服务器密钥,可以在firebase控制台中找到它:项目->设置->项目设置->云消息传递->服务器密钥

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

这篇关于出现空白通知,没有任何代码调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆