向终端节点 AWS SNS 发送通知时看不到消息



我已经设置了一个AWS SNS系统,用于按照本教程向所有订阅主题的终端节点发送通知(我设置了一个Firebase Cloud Messenger而不是GCM(:

https://docs.aws.amazon.com/mobile/sdkforxamarin/developerguide/sns.html

当应用程序运行时,一切都按预期工作。我可以通过 AWS SNS 控制台发送消息,我将在我的终端节点(物理设备和模拟器(上收到通知,但是当应用程序关闭并尝试从 AWS SNS 控制台发送相同的 JSON 数据时,我只会在通知中看到标题。我发送的 JSON 数据是:

{ "default": "Testing", "sqs": "Testing", "GCM": "{ "notification": { "message": "Testing" } }" }

我有一个 PCL Xamarin Forms 项目,其中包含以下代码来处理从 Firebase 收到通知时的通知:

private void HandleMessage(Intent intent)
{
string message = string.Empty;
Bundle extras = intent.Extras;
if (!string.IsNullOrEmpty(extras.GetString("message")))
{
message = extras.GetString("message");
}
else
{
message = extras.GetString("default");
}
AndroidUtils.ShowNotification(this, "Test", message);
}

然后,当我想显示通知时:

public static void ShowNotification(Context context, string contentTitle,
string contentText)
{
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, Constants.CHANNEL_ID);
builder.SetAutoCancel(true);
builder.SetSmallIcon(Resource.Mipmap.icon_round);
builder.SetContentText(contentText);
builder.SetContentTitle(contentTitle);
builder.SetPriority(NotificationCompat.PriorityDefault);
Notification notification = builder.Build();
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
{
NotificationChannel notificationChannel = new NotificationChannel(Constants.CHANNEL_ID, Constants.ANDROID_CHANNEL_NAME, NotificationImportance.Default);
NotificationManager notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager;
notificationManager.CreateNotificationChannel(notificationChannel);
const int notificationID = 0;
notificationManager.Notify(notificationID, notification);
}
else
{
NotificationManager notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager;
const int notificationID = 0;
notificationManager.Notify(notificationID, notification);
} 
}

所以我在这里的主要问题是,当应用程序关闭/关闭并且我从 SNS 发送通知时,我如何获取数据包的消息部分?

FCM 消息有两种类型

通知消息

数据电文

参考 - 如何在 Firebase 中应用在后台运行时处理通知