Tuesday, January 17, 2012

Android C2DM: Part 1 (Overview)

Today we will be exploring Google’s own cloud based push technology called C2DM (Cloud to Device Messaging) available for Android platform. C2DM helps third party Android app developers to receive push notifications sent by their application server.
Before getting into C2DM details let’s see why push is required.

Why Push is required?

Most mobile solutions have client-server architecture where mobile apps frequently need to download updated data from server. In some situations server need to push some short messages to mobile client like notification regarding new app update or event. For these kinds of features, we can use polling or push mechanism.
In polling mechanism, mobile app pings server periodically and checks if any new data is available for download. Polling is easy to implement and works well in most of the situations but tricky part is selecting the frequency for polling. Polling rarely can make data on device stale and polling frequently can create stress on server and network. This approach is not suitable for mobile devices as it uses precious network bandwidth more and so battery consumption will be more.
Other alternative is push mechanism for which we can follow two different implementation approaches. First approach is using proper push bearer, a network mechanism that can deliver unsolicited messages to devices. SMS and Blackberry’s proprietary push solution are the examples of push bearer. Second implementation approach is to simulate this technology by opening TCP connection to the push server. As we know TCP streams are full duplex (having pair of byte streams, one following each direction), server can push data to device anytime provided stream is active.
Most Smartphone platforms like iOS, Blackberry, Windows Mobile have their own push technology. Android OS was exception till its Froyo release as Android’s framework does not has support for push technology and app developers have to use open source alternatives like MQTT, Urban Airship and Deacon. With Froyo release, Android received support for Google’s own cloud based push technology known as C2DM.

C2DM Overview
C2DM is a solution to send real time notifications to user on his Android handset and most Google Services (Gmail, Market, Maps etc.) supports it. C2DM server/service takes care of all aspects of queuing and delivery of messages to target devices running developer’s target apps. C2DM also acts as an intermediary between developer’s App server and Android device.
Before moving into implementation details, we will see prerequisites for C2DM implementations, advantages and limitations of C2DM service and some guidelines for C2DM implementation.

Prerequisites

  • Android 2.2+ Device or Emulator
  • At least one logged in Google user on device/emulator
  • Application server which can talk HTTP and connect to C2DM server
  • Android application should have permissions to receive C2DM message and to make internet connection
  • Developer must register on C2DM site to use C2DM for his application and to get developer quota for C2DM messages.

Advantages

  • Application need not be running in background to receive push messages as those gets delivered to your app (Intent Receiver) by system using Intent broadcast.
  • It does not create additional burden on network as it uses existing connection to Google services.
  • Data delivery to device will always secured as device to C2DM server connection supports SSL.
  • Broken connections will be re-established using heartbeat implementation.
  • C2DM framework does not provide any built-in user interface to display the received push message content. C2DM framework provides full freedom to application so that it will have full control over the received raw message content. For example, the application might post a notification, display a custom user interface, or silently synchronize data.

Limitations

  • Push message size limit is 1K (1024 bytes)
  • C2DM framework doesn’t give guarantee about delivery or order of push messages
  • C2DM sender account will have daily limit on total number of messages sent as well as messages sent per device. Currently total limit is 200,000 messages per day.

Guidelines

  • When Google service is down your application will get HTTP error code 503 along with retry value. Your app should respect these kinds of errors and it should have advanced error-handling mechanism in place.
  • Your solution should have its own queue mechanism in place, which will be useful when Google C2DM service returns over quota error.
  • Application server should not send large data; instead, it has to send ‘tickles’ to your application telling it to download latest data from server.
  • Avoid using ‘Role Account Email ID’ on device
Part 2 of this blog will cover C2DM architecture and life-cycle in details.

Update : Google has deprecated C2DM and replaced it with GCM. Please read more about GCM here.

Wednesday, January 4, 2012

Great Journey of Android: Part 2

In first part of this blog we have looked at all major releases, events happened till Android 2.2 Froyo release. In this part we will see what are major releases, events and milestone happened starting from gingerbread release to till the end of 2011.

December 6, 2010

Android 2.3 (Gingerbread)
  • Supports new ways of communications like NFC (Near Field Communication) and SIP-based VoIP
  • Support for new sensor types like Gyroscope, barometer etc.
  • Adds support for rich multimedia features like multiple cameras, mixable audio effects
  • Powerful Dalvik VM with optimized JIT, improved code verification and concurrent garbage collector
  • Updated Media framework with AAC and AMR-WB encoding, integrated support for VP8 and WebM formats

February 9, 2011

Android 2.3.3 (Gingerbread)
  • Read/write access to different types of tags like NFC-A/B/F/V, MIFARE Classic/Ultra light and NFC Forum NDEF tags
  • Apps can decode rectangular region of a image
  • Minor update 2.3.4 released in May 2011 includes optional Open Accessory Library as part of Google APIs Add-On

February 22, 2011

Android 3.0 (Honeycomb)
  • First tablet only Android release with optimized UI designs
  • New UI components like fragments, Action bar, app widgets and status bar notifications
  • Support added for multi-core processor architecture
  • Redesigned keyboard, improved copy/paste and visual multitasking
  • Improved 2D graphics with hardware acceleration
  • Improved clipboard APIs can be used to copy/paste plain text, a URI or and Intent.
  • Enhancements for enterprise by supporting new types of policies like Encrypted Storage, Password Expiration and Password History
  • Rich multimedia and connectivity options like HTTP Live streaming and Pluggable DRM framework
May 10, 2011
Android 3.1 (Honeycomb)

  • Newly introduced MTP/PTP APIs can be used to interact directly with connected cameras and other PTP devices
  • Support for different types of input sources like mice, joystick and gamepads
  • New UI improvements like resizable widgets, expandable recent app list etc.
July 15, 2011
Android 3.2 (Honeycomb)
  • New features for user like media syncing from SD card, view fixed size apps in compatibility zoom mode
  • Developers can use new resource qualifiers to support wide range of screen sizes
October 18, 2011
Android 4.0 (Ice Cream Sandwich)
  • Unified framework for tablets, phones and more
  • Includes new typeface ‘Roboto’ optimized for high-resolutions with improved readability
  • You can unlock your device with your face using newly introduced facial recognition technology
  • Wi-Fi Direct feature allows you to connect to nearby Wi-Fi enabled device and share files
  • Lock screen provides different options for launching camera, checking received messages and managing music tracks while listening music
  • User can take screenshot and share it through gallery
  • In-built support for Bluetooth HDP (Health Device Profile)
  • Adds new controls to manage network data usage overall as well as application wise
December 6, 2011
10 Billion Downloads
  • Android crosses 10 billion downloads on Android Market
  • Photobucket Mobile app was the lucky 10 billionth download
  • Exponential growth as it just took about 9 months to reach this milestone from 3 billion in march
  • Android celebrates this milestone with 10-cent apps on Android Market for 10 days

December 16, 2011

Android 4.0.3 (Ice Cream Sandwich)
  • Improvements in graphics, database, Bluetooth, spell checker and more
  • Improved camera features like checking and managing video stabilization
  • Accessibility refinements through improved content access for screen readers and new status/error reporting for TTS engines
  • Calendar enhancements like color for events, new attendee types and states

I hope you have enjoyed reading these blogs and got enough information regarding Android’s Great Journey which is going to continue this year also. I hope in 2012 we will see more powerful Android tablets, smart phones and other devices.

First part of this blog can be read here.