0

I am attempting to do a POST on "https://gcm-http.googleapis.com/gcm/send".

The connection I receive is as follows:

200
{"multicast_id":6570365141544424316,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1446150341234481%2c7295a7f9fd7ecd"}]}

In other words, it is talking to the GCM and should send a push notification to my phone. However, I have a suspicion that the JSON I am sending is incorrect. Here is the JSON:

String json ="{\"registration_ids\" : [\"APA91bGxHWapgmxgyvPceu85ArDMLaFekbTt5RGzy3gv1xtSO09tJbvnaeVLefBqNl_iBrctoZQ2AltSMfrXykq8-AEQtUUWnCVH566xcwib4HinI16W3_g\"],\"notification\" : {\"sound\" : \"default\",\"badge\" : \"1\",\"title\" : \"default\",\"body\"  : \"Test\"},\"data\" : {\"msg\":{\"message\":\"this is it\"}}}";

I wasn't sure how to debug this issue, as I am not receive anything. I would appreciate it if someone could show me the proper syntax for this. Perhaps my syntax is correct and I am just not sending the correct parameters to the GCM?

BNK
  • 23,994
  • 8
  • 77
  • 87
VedhaR
  • 495
  • 5
  • 21
  • Replace `registration_ids` with`to`. It may solve the problem. – Ali Oct 30 '15 at 04:36
  • 1
    I think your server-side code is OK, just need to check cliend-side app (android). You can read my answer at the following http://stackoverflow.com/questions/32299997/how-to-implement-a-gcm-hello-world-for-android-using-android-studio – BNK Oct 30 '15 at 05:55
  • @Ali I gave this a shot, and it returned a error code of 400. Maybe it doesn't under stand 'to'? – VedhaR Oct 30 '15 at 13:06
  • 1
    @BNK It was actually my JSON string that I was sending! I copied that string from your answer and changed the registration id, and it worked like a charm :). I up-voted your answer. Thanks for the help! Also, if you want, maybe put an official answer to this post so I can mark it as the correct answer? Not sure if that is needed. – VedhaR Oct 30 '15 at 14:16

1 Answers1

1

As you can find in the following question:

How to implement a GCM Hello World for Android using Android Studio

final String postData = "{ \"registration_ids\": [ \"" + CLIENT_REG_ID + "\" ], " +
                    "\"delay_while_idle\": true, " +
                    "\"data\": {\"tickerText\":\"My Ticket\", " +
                    "\"contentTitle\":\"My Title\", " +
                    "\"message\": \"Test GCM message from GCMServer-Android\"}}";

Of course, you can also use to with a string instead of registration_ids with an array.

Please read Google's documentation - Downstream message syntax for more details. Hope this helps!

Community
  • 1
  • 1
BNK
  • 23,994
  • 8
  • 77
  • 87
  • Hey I have a couple of questions. 1. Do you know why I don't receive push notification in app but receive them outside the app? 2. The note 6 seems to get these push notifications in a delayed fashion as opposed to other phones – VedhaR Nov 03 '15 at 14:33
  • Hi! I don't understand your 1st question. Regarding 2nd one, I don't have Note6 to check. I think you can create new questions in SO so that anyone can help. – BNK Nov 03 '15 at 23:58
  • Oh don't worry about it, the first question is related to the plugin I am using. I may post a question on it in a bit. – VedhaR Nov 04 '15 at 16:26