Sunday, September 6, 2015

Google Cloud Messaging - Learning Part 1


This enables to send the message to the devices from the server and receive message from the users device on the same connection. The GCM handles all aspects of queuing of message and delivery to client applications running on target devices, and its completely  free. 

Below are the main features of this 

1. Versatile messaging targets : Distribute message to the client app in any of three ways - to single devices, to group of devices, or to devices subscribed to topics. 
2. Downstream messaging : For purposes such as alerting users, chat messaging or kicking off background processing before user opening the app, GCM provides a battery efficient connection between server and devices 
3. Upstream messaging : Send ACKs, chats, and other messages from devices back to the servers over GCM’s reliable and battery efficient connection channel. 

Sending a message using GCM-HTTP connection server protocol: 

https://gcm-http.googleapis.com/gcm/send 
Content-Type:application/json
Authorization:key=AISS….. 
{
“to” : “/topics/foo-bar”,
“data” : 
{
“message” : “This is a GCM topic message”,
}

}

To Handle a downstream message on an Android device, below is the code 

@override 
public void onMessageReceived (String from, Bundle data)
{
String message = data.getString(“message”);
}

References:

No comments:

Post a Comment