【发布时间】:2018-11-30 13:58:41
【问题描述】:
我已经设置了一个 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 发送通知时,我如何获取数据包的消息部分?
【问题讨论】:
标签: android amazon-web-services xamarin.forms push-notification amazon-sns