当请求不是来自Firebase控制台时,RemoteMessage.GetNotification()会返回null吗?

Ale*_*yov 6 android httprequest xamarin.android firebase firebase-cloud-messaging

我正在测试Firebase云消息传递.

如果我使用Firebase控制台发送消息 - 在我的代码中我将Notification对象设置为值 - 不是问题:

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

        Firebase.Messaging.RemoteMessage.Notification oNotification;

        oNotification = message.GetNotification();
Run Code Online (Sandbox Code Playgroud)

我正在使用http://requestmaker.com/发送通知 - 一切正常 - 它被发送,我收回了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
Run Code Online (Sandbox Code Playgroud)

但是oNotification = message.GetNotification();返回null.问题是 - 为什么?

AL.*_*AL. 7

您似乎在发送data有效负载而不是notification有效负载.使用Firebase控制台时,发送的消息始终被视为notification有效内容消息(如果在"高级选项"中添加了自定义键值对,则两者的组合).请参阅FCM消息类型.

data在使用请求程序时,您可能只发送-only有效负载.在您的代码中,您只处理具有notification有效负载类型的消息:

message.GetNotification();
Run Code Online (Sandbox Code Playgroud)

我并不完全熟悉Android Xamarin,但通常使用FCM ,如果您决定发送-only有效负载,还有一种data通过调用获取有效负载的方法.RemoteMessage.getData()data