In May 2010 Google released a monumental update to it’s Android OS with the release of Android 2.2 (Froyo). Alongside the quite ridiculous improvement in performance over the previous version AND a host of amazing extra features (JIT compilation, USB tethering, Wi-Fi hotspot, an improved browser to name but a few) was the announcement of the Cloud to Device Messaging (C2DM) service, or to use it’s more commonly known name – push notifications. Push notifications systems have fast become an industry standard in the world of advanced mobile computing, allowing a central server to push data to individual devices, rather than the power hungry alternative of continually polling a server for updates.
Announced at Google I/O 2012 was the next iteration of C2DM, now called Google Cloud Messaging (GCM). Along with the moniker change, there are a few key changes between C2DM abnd GCM which add functionality and make it easier to use. Of note:
- Multicast messages: you can broadcast messages of up to 1000 registration IDs at the same time from a single request
- Multiple senders: messages to the same app can be sent by multiple parties thanks to a change in the way registration is handled
- Time-to-live (TTL) messages: messages can have a TTL value of between 0 to 4 weeks helping to ensure messages about events that expire don’t reach your users after the fact. The GCM servers will throttle the messages to prevent notification spam. Messages that can’t be instantly delivered will be stored by the Google servers until they are delievered or expire, messages with a TTL of 0 aren’t stored anywhere and also aren’t subject to any throttling.
- Payload: messages can bundle up to 4Kb (up from 1024 bytes with C2DM) of data to be delivered with the message, up to 100 of these messages can be stored on the GCM servers if they can’t instantly be delivered, after which you’ll receive an error code which your server will have to deal with.
Google states that C2DM will be maintained for moment but won’t accept any new users nor grant new quotas. They also point out that ‘C2DM and GCM are not interoperable. For example, you cannot post notifications from GCM to C2DM registration IDs, nor can you use C2DM registration IDs as GCM registration IDs. Your server-side application must keep keep track of whether a registration ID is from C2DM or GCM and use the proper endpoint.’ fortunately they provide easy to follow instructions as to how to migrate your apps from C2DM to GCM and google has even provided sample GCM apps (both client and server side) for you to look at (something which was sorely missing with C2DM)
If you haven’t yet used Google’s cloud messaging service, it’s now easier than ever – full instructions on getting started with GCM are given on the developer website. Just remember that it requires devices running android 2.2 (sdk version 8) or later.