【问题标题】:how send Push Notification to Kindle Fire from WCF rest service如何从 WCF 休息服务向 Kindle Fire 发送推送通知
【发布时间】:2014-03-03 10:29:24
【问题描述】:

我想从 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;
        }

    }

【问题讨论】:

    标签: push-notification amazon wcf-rest kindle-fire


    【解决方案1】:

    PushSharp 依赖于适用于 Android 的 Google Cloud Messaging,而 Kindle 不支持该功能。您需要实施 Amazon Device Messaging (ADM) 版本 (https://developer.amazon.com/public/apis/engage/device-messaging) 或利用 Amazon 的 Simple Notification Service (SNS) 来定位 Kindle 和其他平台(https://aws.amazon.com/sns/)

    【讨论】:

    • 谢谢,它的使用完整你能给我它的实现代码示例吗?
    • 我读了它,但我不明白我是如何使用它的,我尝试了一些东西但它不起作用。我也邮寄给亚马逊支持团队,但他们不回复。如果可能的话,请给我代码示例。
    猜你喜欢
    • 2012-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-07
    • 1970-01-01
    • 1970-01-01
    • 2016-05-06
    • 1970-01-01
    相关资源
    最近更新 更多