使用 Amazon SNS 在 Android GCM 中仅接收默认消息
Posted
技术标签:
【中文标题】使用 Amazon SNS 在 Android GCM 中仅接收默认消息【英文标题】:Receiving only default message in Android GCM using Amazon SNS 【发布时间】:2016-11-15 14:05:58 【问题描述】:我正在服务器上实现通知服务,将通知推送到 android 和 Iphone。
我目前遇到的问题是我正在测试的 Android 设备只收到默认消息。
我的代码如下:-
主程序
string smsMessageString = "\"default\": \"This is the default message which must be present when publishing a message to a topic. The default message will only be " +
" used if a message is not present for one of the notification platforms.\"," +
"\"APNS\": \"aps\": \"alert\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"," +
"\"GCM\": \"data\": \"message\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"," +
"\"ADM\": \"data\": \"message\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"";
var smsMessage = new SmsMessageObj
smsMessageSubject = "Test Message",
smsMessageBody = smsMessageString
;
snsClient.SendPush(endpointArn, smsMessage);
SendPush 如下:-
public void SendPush(string endpointArn, SmsMessageObj msg)
if (string.IsNullOrEmpty(endpointArn))
throw new Exception("Endpoint ARN was null");
var pushMsg = new PublishRequest
Message = msg.smsMessageBody,
MessageStructure = "json",
Subject = msg.smsMessageSubject,
TargetArn = endpointArn
;
_client.Publish(pushMsg);
我是否需要添加更多内容才能获得“正确”的 Android 通知?
我需要 app.config 中的任何内容吗?
感谢您的帮助和时间
【问题讨论】:
【参考方案1】:我已经解决了这个问题。我需要做的就是将 Json 字符串化。也许它会在未来帮助别人。所以我所做的是:-
var apns_Json = "\"aps\": \"alert\": \"Check out these awesome deals_Apple!\",\"url\": \"www.amazon.com\"";
var gcm_Json = "\"data\": \"message\": \"Check out these awesome deals_Google!\",\"url\": \"www.amazon.com\"";
var adm_Json = "\"data\": \"message\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"";
string smsMessageString = "\"default\": \"This is the default message which must be present when publishing a message to a topic. The default message will only be " +
" used if a message is not present for one of the notification platforms.\"," +
"\"APNS\": " + JsonConvert.ToString(apns_Json) + "," +
"\"GCM\": " + JsonConvert.ToString(gcm_Json) + "," +
"\"ADM\": " + JsonConvert.ToString(adm_Json) + "";
【讨论】:
以上是关于使用 Amazon SNS 在 Android GCM 中仅接收默认消息的主要内容,如果未能解决你的问题,请参考以下文章