Search code examples
androidandroid-c2dm

Android c2dm No message received


i've implemented the c2dm on my phone application. The c2dm application does receive message a few days ago, but afterawhile it stops receiving any message.

When pushing to the google c2dm link, i got the response "id=0:1325918022124320%6c25a09400000031". with the header ok, is there any wrong here?

I am using the following to send message

   public void SendMessage(string registrationId, string data, string sAuth)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://android.clients.google.com/c2dm/send");
        request.Method = "POST";
        request.KeepAlive = false;

        NameValueCollection postFieldNameValue = new NameValueCollection();
        postFieldNameValue.Add("registration_id", registrationId);
        postFieldNameValue.Add("collapse_key", "1");
        postFieldNameValue.Add("delay_while_idle", "0");
        postFieldNameValue.Add("data.payload", data);
        string postData = ConstructQueryString(postFieldNameValue);
        byte[] byteArray = Encoding.UTF8.GetBytes(postData);

        request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
        request.ContentLength = byteArray.Length;

        request.Headers.Add(HttpRequestHeader.Authorization, "GoogleLogin auth=" + sAuth);

        Stream dataStream = request.GetRequestStream();
        dataStream.Write(byteArray, 0, byteArray.Length);
        dataStream.Close();

        WebResponse response = request.GetResponse();
        HttpStatusCode responseCode = ((HttpWebResponse)response).StatusCode;
        if (responseCode.Equals(HttpStatusCode.Unauthorized) || responseCode.Equals(HttpStatusCode.Forbidden))
        {
            Response.Write("Unauthorized - need new token");
        }
        else if (!responseCode.Equals(HttpStatusCode.OK))
        {
            Response.Write("Response from web service not OK :");
            Response.Write(((HttpWebResponse)response).StatusDescription);
        }

        StreamReader reader = new StreamReader(response.GetResponseStream());
        string responseLine = reader.ReadLine();
        reader.Close();
        Response.Write(responseLine); 

    }

Solution

  • twice check with your google registration key. I think it might changed somehow thats y you dont able to receive any massage. make sure that key on both side server as well client are same.