Android c2dm未收到任何消息
我已经在我的手机应用程序上实现了c2dm。c2dm应用程序几天前确实接收到消息,但过了一段时间它就停止接收任何消息 当推到google c2dm链接时,我得到了响应“id=0:1325918022124320%6c25a09400000031”。在标题正确的情况下,这里是否有错误 我正在使用以下命令发送消息Android c2dm未收到任何消息,android,android-c2dm,Android,Android C2dm,我已经在我的手机应用程序上实现了c2dm。c2dm应用程序几天前确实接收到消息,但过了一段时间它就停止接收任何消息 当推到google c2dm链接时,我得到了响应“id=0:1325918022124320%6c25a09400000031”。在标题正确的情况下,这里是否有错误 我正在使用以下命令发送消息 public void SendMessage(string registrationId, string data, string sAuth) { Http
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);
}
用你的谷歌注册密钥检查两次。我想可能会有什么变化,那就是你不能接受任何按摩。确保服务器和客户端上的密钥相同 如果您有任何疑问,请进一步询问。我已尝试手动输入注册表项,但它仍然不起作用。我甚至重新启动了我的手机,用全新的gmail账号重新注册了注册器,然后用c2dm注册。之后,您将获得注册id,并将该id传递给服务器端代码以发送消息。我想你对密钥注册器设备有问题,比如发送电子邮件到服务器并从广播中取回“注册id”?ThanksInt registrationIntent=new Intent(“com.google.android.c2dm.Intent.REGISTER”);registrationIntent.putExtra(“app”,PendingIntent.getBroadcast(this,0,new Intent(),0));registrationIntent.putExtra(“发送方”xyz@gmail.com"); 此。startService(注册内容);