Google Cloud Messaging

3,762 views

Published on

Document references are taken from http://developer.android.com/google/gcm/index.html

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,762
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
399
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Google Cloud Messaging

  1. 1. Lavakush Verma
  2. 2. Introduction Google Cloud Messaging for Android (GCM):  Its a service that helps developers send data from servers to their Android applications on Android devices.  It could be a lightweight message telling application to fetch new data, or a message with payload data to be consumed instantly.  GCM handles all aspects of queuing of messages and ensures delivery to the application on target devices up to a great extent.  The best part, its totally free irrespective of your needs and has No Quota system as we had with version of C2DM.  It’s a replacement to C2DM, which is now deprecated. As no more C2DM signups are acceptable.  Provides backward support for devices running on Android 2.2 OS version. Pre OS-Ver 3.x devices, it requires to setup at least on Google account. Which is not at all required for devices running Ver-4.0 and above. 1
  3. 3. GCM Architecture  Components: physical entities – Mobile Device (running with 2.2 or above OS Version) – 3rd Party App Server – GCM Servers  Credentials: to ensure approved sender and delivery to correct place – SenderID (ProjectID) – ApplicationID – RegistrationID – Google Account: if device running below ICS version. – Sender Auth Token 2
  4. 4. Enabling GCM: Registration @Override protected void onCreate(Bundle saveInstanceState){ if( GCMRegistrar.getRegistrationId(this).equals(“”)){ GCMRegistrar. Register(this, “965748474884”); } } @Override protected void onRegistered(Context ctx, String regId){ sendToFootballServer(regId); } 3
  5. 5. How GCM Server works? (Receiving/Sending) Content-Type:application/json Authorization:key=AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA { “registration_ids” : [“APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...”], “data” : { “Team” : “Portugal”, “Score” : “3”, “Player” : “Varela”, }, } 4
  6. 6. Sending a Message:  The application server issues a POST request to https://android.googleapis.com/gcm/send HttpRequest :Body(JSON) { "collapse_key": "score_update", "time_to_live": 108, “delay_while_idle": true, "data": { "score": "4x8", "time": "15:16.2342" }, "registration_ids":["4", "8", "15", "16", "23", "42"] } HttpResponse:Body(JSON) { "multicast_id": 216, "success": 3, "failure": 3, "canonical_ids": 1, "results": [ { "message_id": "1:0408" }, { "error": "Unavailable" }, { "error": "InvalidRegistration" }, { "message_id": "1:1516" }, { "message_id": "1:2342", "registration_id": "32" }, { "error": "NotRegistered"} ] } 5
  7. 7. Uniqueness of GCM: Features  Message Multicasting – More than 1 devices can receive one message simultaneously  Multiple Senders with Single RegID – More than 1 server can send messages to one App  TTL : Time To Live – Expiry of sent messages  Messages with Payload – To avoid sync with server for certain needs.  Throttle Queue – GCM Optimization for battery  GCM Reliability 6
  8. 8. Message Multicasting  One Message Request – Many Devices  Up to 1000 Devices simultaneously 7
  9. 9. Multiple Senders  One common Registration ID  Multiple sender can send messages to one Application  Up to 100 Project IDs (Servers) @Override protected void onCreate(Bundle savedInstanceState) { if (GCMRegistrar.getRegistrationId(this).equals(“”)) { GCMRegistrar.register(this, “968350041068”, “652183961211”); } 8
  10. 10. TTL: Time To Live  Indicates the duration to which GCM can store this message.  From 0 sec to 4 weeks  Messages with 0 will not be stored on GCM (Receive – Send – Delete)  Default is 4 Weeks  Best Use case for Advertisements( Like sending deals and offers during football match) 9
  11. 11. Messages with Payload  Payload up to 4K per message  Up to 100 Messages can be stored  Deletes all and creates a message to trigger sync after that  Best use for Ims and Online Server Gaming Apps { “message_type” : “deleted_messages”, “total_deleted” : “115”, }, 10
  12. 12. GCM Optimization  Throttle Queue – Provide fresh data all the time. – Optimized for battery life. – Delay in Delivery  Reliability 11
  13. 13. GCM Un-Registration 12

×