【发布时间】:2017-07-26 06:45:17
【问题描述】:
我正在使用 this example 将 Firebase 云消息传递与我的应用程序集成。 通过 Firebase 控制台发送消息,目标是 user segment 和 topic(主题是 news)都有效。我的应用程序将显示一个包含该消息的 toast。
我想要的是通知消息,它会自动显示在 Android 通知托盘中,而不是 toast。阅读FCM concept后,我用curl尝试了这个:
curl -H "Content-type: application/json" -H "Authorization:key=AAAA....ahjkdkhajksd" -X POST -d '{ "to": "/topics/news", "notification": { "body":"foo", "title":"bar", "icon":""}}' https://fcm.googleapis.com/fcm/send
它通过Toast 显示,而不是Android 通知托盘。这里可能出了什么问题?
【问题讨论】:
-
发布您的 onMessageReceived 方法,如果您的应用已打开,通知将传递给它,否则直接显示在通知托盘中。
-
您的代码进入“if (remoteMessage.getNotification() != null)”条件并显示数据?
-
在调试时,我发现:
07-27 14:42:12.652 21985-22283/studio.emcorp.monitoringsiswa E/MyFirebaseMessagingService: From: /topics/news07-27 14:42:12.652 21985-22283/studio.emcorp.monitoringsiswa E/MyFirebaseMessagingService: Notification Body: foo是的,已到达该块,我收到了带有 Toast 的消息 -
那么问题出在哪里?如果您能够在 toast 中显示数据,则改为在通知中显示相同的数据。
标签: android firebase firebase-cloud-messaging