I received this response from the GCM server {"success": 1} But the notification did not arrive on the device

I am trying to notify a device using Push Notification

I received a response from the GCM server

{"multicast_id":8594338261894783737,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1355822022916886%8ae6056ef9fd7ecd"}]}

But still Don't get notified

With Knowledge This → "success":1

But I think something is wrong here → "canonical_ids":0


This is my code ...

  private string SendGCMNotification(string apiKey, string postData, string postDataContentType = "application/json") { ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateServerCertificate); // // MESSAGE CONTENT byte[] byteArray = Encoding.UTF8.GetBytes(postData); // // CREATE REQUEST HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://android.googleapis.com/gcm/send"); Request.Method = "POST"; Request.KeepAlive = false; Request.ContentType = postDataContentType; Request.Headers.Add(HttpRequestHeader.Authorization, string.Format("key={0}",apiKey)); Request.ContentLength = byteArray.Length; Stream dataStream = Request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); try { WebResponse Response = Request.GetResponse(); HttpStatusCode ResponseCode = ((HttpWebResponse)Response).StatusCode; if (ResponseCode.Equals(HttpStatusCode.Unauthorized) || ResponseCode.Equals(HttpStatusCode.Forbidden)) { Label1.Text = "Unauthorized - need new token"; } else if (!ResponseCode.Equals(HttpStatusCode.OK)) { Label1.Text = "Response from web service isn't OK"; } StreamReader Reader = new StreamReader(Response.GetResponseStream()); string responseLine = Reader.ReadToEnd(); Reader.Close(); return responseLine; } catch (Exception e) { return "error"; } // return "error"; } 

and I call this method using

  string deviceId = "APA91bHomX3zb6Y87fb4GAjyj8zIaI-tt1n6ZFmgtmu16nmLW7ntwnOyv4BXMH7RzQWk3JrKdLjttJMxKzvpFd3Kmrid_RzsC3zR46GLJGiZKERXOSIR8fYReBEfz1f0G_FIm5bPttWUBDwz9jPuF2lS8RQh-0DKbw"; string message = "some test message"; string tickerText = "example test GCM"; string contentTitle = "content title GCM"; string postData = "{ \"registration_ids\": [ \"" + deviceId + "\" ], " + "\"data\": {\"tickerText\":\"" + tickerText + "\", " + "\"contentTitle\":\"" + contentTitle + "\", " + "\"message\": \"" + message + "\"}}"; Label1.Text = SendGCMNotification("AIzaSyBEvtrtbbfy2-p2zS8Zi8DweZiRy8M-nZc", postData); 0DKbw";  string deviceId = "APA91bHomX3zb6Y87fb4GAjyj8zIaI-tt1n6ZFmgtmu16nmLW7ntwnOyv4BXMH7RzQWk3JrKdLjttJMxKzvpFd3Kmrid_RzsC3zR46GLJGiZKERXOSIR8fYReBEfz1f0G_FIm5bPttWUBDwz9jPuF2lS8RQh-0DKbw"; string message = "some test message"; string tickerText = "example test GCM"; string contentTitle = "content title GCM"; string postData = "{ \"registration_ids\": [ \"" + deviceId + "\" ], " + "\"data\": {\"tickerText\":\"" + tickerText + "\", " + "\"contentTitle\":\"" + contentTitle + "\", " + "\"message\": \"" + message + "\"}}"; Label1.Text = SendGCMNotification("AIzaSyBEvtrtbbfy2-p2zS8Zi8DweZiRy8M-nZc", postData); 

Thanks in advance

+4
source share
1 answer

Take a look at the response format in the GCM documentation: http://developer.android.com/google/gcm/gcm.html#response

 success Number of messages that were processed without an error. 

I understand that this means that GCM was able to process this message, this does not mean that the message was sent successfully to the device. (For example, the device can be offline and receive it later, but the message was processed successfully).

"canonical_ids": 0 Does not mean that an error has occurred, it means that there were no devices that needed to be updated. You can learn more about the canonical id here: http://developer.android.com/google/gcm/adv.html#canonical

On the server side, as long as the application behaves well, everything should work fine. However, if an error in the application triggers multiple registrations for the same device, it can be difficult and you may get duplicate messages.

GCM provides a facility called "canonical registration identifiers" easily from these situations. A canonical registration identifier is defined to be the identifier of the last registration requested by your application. This is the identifier that the server should use when sending messages to the device.

If you later try to send a message using a different registration ID, GCM will process the request as usual, but it will include the canonical registration identifier in the registration_id response field. Be sure to replace the registration identifier stored in your server with this canonical identifier, because in the end the identifier you use will stop working.

I would suggest adding some sort of logging code to your client to make sure that you did not receive the message. In particular, in the GCMntentService onMessage () methods.

+2
source

All Articles