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 sends 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?
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.