Exploring Android Cloud to Device Messaging (C2DM)
One of the most talked about new features of Android 2.2 is Android Cloud to Device Messaging announced during Google IO last week. This blog will take a quick look at the feature and what is actually happening behind the scenes.
In a nutshell, C2DM provides a way for third party applications to send short data messages to Android devices. This closely mimics the Push Notification services currently available on the iPhone.
The primary characteristics of C2DM are listed on the C2DM website:
- It allows third-party application servers to send lightweight messages to their Android applications. The messaging service is not designed for sending a lot of user content via the messages. Rather, it should be used to tell the application that there is new data on the server, so that the application can fetch it.
- C2DM makes no guarantees about delivery or the order of messages. So, for example, while you might use this feature to tell an instant messaging application that the user has new messages, you probably would not use it to pass the actual messages.
- An application on an Android device doesn’t need to be running to receive messages. The system will wake up the application via Intent broadcast when the the message arrives, as long as the application is set up with the proper broadcast receiver and permissions.
- It does not provide any built-in user interface or other handling for message data. C2DM simply passes raw message data received straight to the application, which has full control of how to handle it. For example, the application might post a notification, display a custom user interface, or silently sync data.
- It requires devices running Android 2.2 or higher that also have the Market application installed. However, you are not limited to deploying your applications through Market.
- It uses an existing connection for Google services. This requires users to set up their Google account on their mobile devices.
So how does this work? Well your third party application decides that it needs to push data to an Android device. It sends a message to the C2DM server, which sends it to the Android device. The Android device accepts the message, wakes up the application (if needed), and connects to your Google server to download the needed information to perform its task. As an example, look at Google’s Chrome to Phone project, which was demoed at Google IO. In this project, there is a Chrome extension that allows you to send links from your PC to your Android device. For example, if you are looking at driving directions on Google Maps in Chrome, and you decide you would like to send those directions to your phone, you can do so with one click instead of retyping in the destination on your mobile device.
Some quick notes, there is a 1024 byte limit on the messages that can be pushed to devices, which is slightly smaller than the size of a text message. Part of the allocated 1024 bytes will be used for C2DM metadata, making the actual payload size even smaller. The idea behind the small size, as listed in the first bullet, is to make the C2DM message a notification, not a data push. When the device receives the notification, it should be able to pull the data from your third party’s application as needed. Again, this is very similar to Apple’s Push Notification services. Android did improve on the idea though, and allows a C2DM message to actually wake the application for you, instead of displaying a confirmation message to the user as Push Notification currently does,
Also as stated, delivery is not guaranteed. I assume this is because the C2DM service is a fire-and-forget service, and it is possible that certain messages are corrupted or lost - especially in busy networks. I will be curious to see how often this happens in practice though.
Don't miss any posts! Subscribe to our blog feed or only posts by Paul Bourdeaux.
Short URL: http://sundog.net/e/3718


Comments
Be the first to comment!
Leave A Comment