我想从WCF休息服务向Kindle Fire发送推送通知。
我使用的是PushSharp库,但它无法正常工作。如果不使用PushSharp库,你能否提出其他建议?
我使用下面的代码发送关于kindle的通知,它给出错误400,
private void sendNotification(String registrationID)
{
String message = "{data\": {\"NTY\":\"-1\",\"NOTY\": \"2\"}}";
String title="title";
String accessToken = "";
accessToken = UpdateAccessToken();
HttpWebRequest httpWReq =
(HttpWebRequest)WebRequest.Create("https://api.amazon.com/messaging/registrations/" + registrationID + "/messages");
Encoding encoding = new UTF8Encoding();
string postData = "{\"data\":{\"message\":\"" + message + "\",\"title\":\"" + title + "\"},\"consolidationKey\":\"Some Key\",\"expiresAfter\":86400}";
byte[] data = encoding.GetBytes(postData);
httpWReq.ProtocolVersion = HttpVersion.Version11;
httpWReq.Method = "POST";
httpWReq.ContentType = "application/json";//charset=UTF-8";
httpWReq.Headers.Add("X-Amzn-Type-Version",
"com.amazon.device.messaging.ADMMessage@1.0");
httpWReq.Headers.Add("X-Amzn-Accept-Type",
"com.amazon.device.messaging.ADMSendResult@1.0");
httpWReq.Headers.Add(HttpRequestHeader.Authorization,
"Bearer " + accessToken);
httpWReq.ContentLength = data.Length;
Stream stream = httpWReq.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
string s = response.ToString();
StreamReader reader = new StreamReader(response.GetResponseStream());
String jsonresponse = "";
String temp = null;
while ((temp = reader.ReadLine()) != null)
{
jsonresponse += temp;
}
}
答案 0 :(得分:3)
PushSharp依赖Android的 Google Cloud Messaging ,但Kindle不支持。您需要实施 Amazon Device Messaging (ADM)版本(https://developer.amazon.com/public/apis/engage/device-messaging)或利用亚马逊的简单通知服务(SNS)来定位Kindle和其他平台(https://aws.amazon.com/sns/)