【发布时间】:2018-02-21 04:42:59
【问题描述】:
让我直奔主题,Firebase Cloud Messaging 和 Android Oreo 在使用它们的 API 时发生了一些重大变化。
我已经在 PubNub 控制台中输入了我的 Firebase 服务器 Api 密钥,推送通知在 Firebase 控制台上工作得非常好,但是当使用 PubNub 发布通知时,remoteMessage.toString 在 OnMessageReceived 函数中给出 => com.google.firebase.messaging.RemoteMessage@ffe9xxx。
我正在发布类似的内容
JsonObject payload = new JsonObject();
JsonObject androidData = new JsonObject();
androidData.addProperty("contentText","test content");
androidData.addProperty("contentTitle","Title");
JsonObject notification = new JsonObject();
notification.add("notification",androidData);
JsonObject data = new JsonObject();
data.add("data", notification);
payload.add("pn_gcm", data);
在
PubNubObject.publish()
.message(payload)
etc..
知道为什么会这样吗? 提前谢谢你。
接收端的代码
有一个扩展 FirebaseMessagingService 的类,代码为OnMessageReceived 函数:
if (remoteMessage.getNotification() != null) {
//for testing firebase notification
Log.d(TAG, "Message Notification
Body:"+remoteMessage.getNotification().getBody());
} else {
//for anything else, I wanted to see what was coming from the server
//this is where I am getting the message when using PubNub notification
Log.d(TAG, "onMessageReceived: remoteMessage to
str:"+remoteMessage.toString() );
}
【问题讨论】:
-
你的代码在消息接收端是什么样子的?
-
@CraigConover 感谢您的回复,我已经用您要求的代码更新了帖子
-
我相信正在发生的事情是您将
notification键/值嵌入到data键中,您可能只需要使用 API,remoteMessage.getData()而不是remoteMessage.getNotification().如果notification键位于顶层,它可能会起作用。见Android docs here。请让我知道这是否有效。 -
我相信您直接联系了我们的支持。如果是这样,我们解决的任何问题都将作为答案发回此处。
-
问题确实出在remoteMessage.getNotification(),应该是remoteMessage.getData()。感谢您宝贵的时间。
标签: android firebase firebase-cloud-messaging pubnub