문제

I want to send push notifications to Kindle Fire from WCF rest service.

I used PushSharp library, but it is not working properly. Can you please suggest any other way without using PushSharp library?

I am using below code to send notification on kindle it is give error 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;
        }

    }
도움이 되었습니까?

해결책

PushSharp relies on Google Cloud Messaging for Android, which is not supported on Kindle. You would need to either implement an Amazon Device Messaging (ADM) version (https://developer.amazon.com/public/apis/engage/device-messaging) or take advantage of Amazon's Simple Notification Service (SNS) to target Kindle and other platforms (https://aws.amazon.com/sns/)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top