2. Agenda
• Polling Mechanism
• What is GCM
• Need / advantages of GCM
• GCM Architecture
• Working of GCM
• GCM – Send to Sync [ HTTP ] and Send Data [ XMPP ]
• Google Cloud Messaging – APIs
• Implementation
2
3. Existing FCM uses Polling
3
Polling is simple to implement,
But Polling consumes lot of battery , resource.
Extra Network Usages.
Any new updates ?
No
Any new updates ?
No
Any new updates ?
YES
5. What is GCM
5
• GCM stands for Google Cloud Messaging.
• It is a free service that allows you to send data from your
servers to your users and vice versa.
• Handles queuing of messages and delivery to the target
application.
6. Need / advantages of GCM
6
• Application does not need to be running in the background
for receiving data messages. The system will wake up the
Android application via Intent broadcast when the
message arrives.
• Lower cost and better tracking than SMS
• Scalability & extensibility
• GCM is completely free no matter how big your messaging
requirements
8. Working of GCM
8
Mobile App
GCMGCM
1.Request for Registration
2.Reply with Registration Id
5. Send Message
3.Send Registration Id 4. Send message {RegId, msg }
9. GCM – Send to Sync [HTTP]
9
Mobile App
GCMGCM
2. Send Notification message
3. Download data 1. Send Notification message
10. GCM – Send Data [ XMPP ]
10
Mobile App
GCMGCM
Send message
Send message
Persistent XMPP connection
11. 11
Google Cloud Messaging – APIs
Time To Live and Delay While Idle
Multiple Senders
Message Multicasting
14. Implementation
• Expose Service to receive and store user information and GCM
registration Id.
• Send message to GCM service.
14
Application Server
15. Minimum requirements ( device side )
• Android 2.2 +
• Google Play Store application should be installed
• Internet connection
• Google account ( device version < 4.0.4 )
• For Developer Emulator with Google APIs
15
Polling is about checking periodically for updates on your server and is bad for several reasons:
1) it consumes lot of battery, periodically waking up the mobile device network stack.
2) it consumes a lot of useless resources on the server as most of this resource lead to a “no update” reply.
3) it introduces latency as the request for new data can happen long after the data availability (unless you put a very low polling interval, which is even worse for the mobile battery). You can get your news alert hours after every one already knows about it, which defeat the purpose of the alert in the first place.
Google Cloud Messaging have been announced last year as a replacement of Google Cloud to Device Messaging.
This is a service that allows mobile developer to notify mobile devices (but also Chrome browser) about important changes on the server-side component of the application.
It makes it possible for the device to stay up to date, without the need to use polling.
Google-provided GCM Connection Servers take messages from a 3rd-party application server and send these messages to a GCM-enabled Android application (the &quot;client app&quot;) running on a device. Currently Google provides connection servers for HTTP and XMPP.
The 3rd-Party Application Server is a component that you implement to work with your chosen GCM connection server(s). App servers send messages to a GCM connection server; the connection server enqueues and stores the message, and then sends it to the device when the device is online.
The Client App is a GCM-enabled Android application running on a device. To receive GCM messages, this app must register with GCM and get a registration ID. If you are using the XMPP(CCS) connection server, the client app can send &quot;upstream&quot; messages back to the connection server.
Give example of Email application.
Give example of sending notification to the users to download videos or pictures.
Give example of Instant Messaging Application.
Give example of my favourite location on surf application.
A) Time to live: allows you to set expiration date for a message. For example the surf application identify that my favourite location due to wind and tidy weather is a place which is perfect for surfing from this hour to next hour. So if GCM discovers that time is expired before device comes online, it simply drop that message.
By Default time is 4 weeks.
B) Delay when idle: can be use for less urgent notifications. Device will get it when becoming active again.
Multiple Sender: GCM is even powerful when multiple senders want to send data to the same application.
Multicasting: To send message via GCM, you need to use open http connection. When you want to connect to all of your users, it is difficult to open these many http connections. For 1000 recipeints 1 http request per message(GCM provides this facility).