Reputation: 1
I want to send customized message through gcm like a question with options and get the reply of that question from the receiver. In simple terms I want to make a voting app which uses GCM service for asking questions and getting response.
Upvotes: 0
Views: 50
Reputation: 3331
Have you checked Sending Upstream Messages? A code Block from the source Link:
try {
Bundle data = new Bundle();
data.putString("my_message", "Hello World");
data.putString("my_action","SAY_HELLO");
String id = Integer.toString(msgId.incrementAndGet());
gcm.send(SENDER_ID + "@gcm.googleapis.com", id, data);
msg = "Sent message";
}
catch (IOException ex) {
msg = "Error :" + ex.getMessage();
}
You can add your Votes in data
. Also you might wanna send your GCM token
, that you receive in RegistrationIntentService.onHandleIntent()
. This token can then be used by the server to uniquely identify you and send messages to you directly via GCM
.
Check Downstream Messaging Via HTTP Post, your JSON will look something like this.
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"data": {
"score": "5x1",
"time": "15:10"
},
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}
Where "to" has the device's token.
Upvotes: 1