RemoteMessage.GetNotification() returns null when request is not from Firebase Console?

醉酒当歌 提交于 2019-12-10 13:12:56

问题


I am testing Firebase Cloud Messaging.

If I use a Firebase Console to send a message - in my code I Notification object with values set - not a problem:

public override void OnMessageReceived(RemoteMessage message)
    {
        base.OnMessageReceived(message);

        Firebase.Messaging.RemoteMessage.Notification oNotification;

        oNotification = message.GetNotification();

I am using http://requestmaker.com/ to send a notification - and all works fine - it gets sent and I get back the messageID.

POST /fcm/send HTTP/1.1
Host: fcm.googleapis.com
Accept: */*
Authorization: key=not-a-real-key0omClYhniZaIAercMVzeFHEG508USi8lud9pxC-SzxAAbR2mflAfVNsfrbrsPJxoFYTr15ytRn9aqWSQXm5x00AOwu2Wl6mWwTcm9l6G
Content-Length: 188
Content-Type: application/x-www-form-urlencoded

But the oNotification = message.GetNotification(); returns null. The questions is - why?


回答1:


It seems that you were sending a data payload instead of a notification payload. When using the Firebase Console, the message sent is always treated as a notification payload message (or a combination of both if you added custom key-value pairs in the Advance Options). See FCM Message Types.

It's possible that you were only sending data-only payloads when using the requestmaker. In your code, you're only handling messages with notification payload types:

message.GetNotification();

I'm not fully familiar with Android Xamarin, but usually with FCM, there is also a way to get the data payloads by calling RemoteMessage.getData(), should you decide to send data-only payloads.



来源:https://stackoverflow.com/questions/41947934/remotemessage-getnotification-returns-null-when-request-is-not-from-firebase-c

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