Saturday, February 1, 2014

Google Cloud Messaging (GCM)

I am back after long time but with tons of mobility knowledge to share with you. I am going to start with the cloud related technology as you know cloud computing and wearable technologies are the future technologies.(Microsoft also thinks so... that's why their cloud head Satya Nadella is front runner to become next Microsoft CEO.)
Let's start with Google Cloud Messaging (GCM)...


GCM is advanced push technology developed by Google for Android platform. It replaces Android’s old push technology C2DM (Cloud to Device Messaging) which has many limitations. Google has deprecated C2DM and stopped manual sign-ups for the C2DM service officially on June 26, 2012 at the Google I/O 2012 event. Current C2DM developers can continue using the service, but without increase in quota. For more details on C2DM, read my previous blog here.
Android developers can use the GCM service to send notifications to Android clients running on the Android devices. GCM service takes care of all aspects of queuing and delivering messages to these target devices.
The paramount factor which differentiates GCM from other push notification services is the bi-directional messaging. To supplement this aspect, GCM has introduced Cloud Connection Server (CCS), which supports XMPP protocol.

Salient Features of GCM

  • It is a free service.
  • Supports payload data up to 4KB.
  • Compatible with Android 2.2+ (Devices with Google play store application installed OR Emulator with Google APIs).
  • Apps need not be deployed through Google Play Store.
  • Upstream messaging (device-to-cloud) using GCM Cloud Connection Server.
  • Multi-device messaging – send message to multiple devices owned by a single user.
  • Applications are free to provide their own UI to handle raw data received from GCM. No built-in interfaces for handling notification data.
  • No additional burden on network as it uses existing connection to Google services.
  • Application need not be running in background to receive GCM messages as they get delivered to  the app by the system using Intent broadcast.
  • GCM generally uses 5228 port, and occasionally, the 5229 and 5230 ports. Therefore, ensure these ports are opened in your organization’s firewall. In addition, firewall should accept all outgoing connections to all IP addresses contained in the IP block, listed under Google’s ASN* of 15169 (as there is no specific IP address for GCM).
  • Microsoft’s Windows Azure Mobile Service has notification hub, which supports sending push notifications to Windows 8, Windows Phone 8, Android and iOS. It supports broadcasting notification to Android devices via GCM.
  • Visit Google Developer console (not API console) to view the GCM statistics.
*ASN – Autonomous System Number

Workflow - Below diagram shows the entire GCM workflow starting from registration to message delivery. GCM workflow has major 3 steps such as GCM registration, sending message and receiving message. 

Before adding support for GCM in your Android application, make sure below prerequisites are fulfilled
  • Project Number – Used as sender ID for GCM registration. To obtain the project number, create an API project using Google API.
  • Enable GCM – Go to Service tab in Google API Console and enable the GCM service
  • API Key – In Google API Console, click API Access tab. In API access screen, select the Create New Server Key option to create new key. All third party applications will use this API key as part of header while sending message to the GCM server.


Core functionality of GCM is similar to C2DM. However, it has added many powerful features to provide simple and efficient way of pushing messages to the device. Let's explore the differences between GCM and C2DM and gather information which will help smooth migration from C2DM to GCM.

Differences - GCM differs from C2DM by having additional useful features and enhancing existing ones. The features that differentiate it are as follows:

  • Simple API Key – this API key can be created from Google API console page.
  • Sender ID – GCM uses project number acquired from API console instead of an email address as used in C2DM.
  • JSON format – JSON support in addition to plain text.
  • Multicast messages – supports simultaneous sending of a single message to multiple devices.
  • Multiple senders – App can receive message from multiple parties using a single registration ID.
  • Time-to-live messages (Expiry) – Expiry can be set between 0 to 4 weeks.
  • Messages with payload – supports up to 4KB of messages

Migration - If you are migrating from C2DM to GCM, then you need to make below mentioned changes

  • Client changes – a client app needs to use project number instead of email account as sender in registration intent. If a server needs to support existing C2DM registrations, then client app has to send some flag (indicating its GCM) along with the registration ID. This will enable the server to differentiate it from requests coming from existing C2DM apps.
  • Server changes – Perform the following simple modifications to ensure successful migration for server apps.
    • Change GCM request endpoint to
    • Use API key instead of authentication token in authorization header of the request


Applications can integrate GCM and take advantage of Google’s powerful push infrastructure. Most of the Google apps available on Android devices make use of this existing infrastructure and so you can be sure that this service is stable and reliable. GCM also provides better user experience for end-user without any additional cost as this service is free while other alternatives like SMS or polling mechanism can cost more to the user in terms of network usage and battery consumption.

If you want to know more about GCM, you can download GCM whitepaper from here

Thursday, June 21, 2012

WP7 Platform Insights : Part 3 (Supported features)

In last two blogs I have discussed Windows Phone overview and app development related topics. Today we will discuss more about supported features in initial version of WP7. Also we will discuss about features which are added in mango and tango updates.
Basic features in 7.0
In this section, we will discuss major features supported by initial version of WP7 i.e. 7.0
  • Improved UI Design
    • WP7 supports slick, touch friendly UI similar Zune HD
    • Tiles serve as a shortcut to your favorite apps
    • Live tiles which can link to facebook profile or any other live information
  • Hubs
    • WP7 supports different social and productivity hubs
    • People hub aggregates your friends from your social networks
    • Picture hub gives access to all of your photos
    • Office hub will be useful for syncing documents between phone and PC
    • App Hub is lists of apps from Marketplace and also downloaded apps
  • Sensors
    • Accelerometer – It measures the three-dimensional force applied on a device.
    • Assisted GPS – Traditional GPS cannot provide accurate position when used in closed space. This error/drift can be avoided using AGPS (assisted GPS), which makes use position of Wi-Fi access points and cellular towers to provide more accurate position.
    • Proximity and Ambient light sensor – These sensors are available on WP7 devices. However, these are not available to developers through APIs.
  • Media
    • One of the best feature is developer can access FM Radio stations in their apps
    • You can integrate your app with Music + Videos hub
    • It supports PlayReady DRM
  • Data Storage/ Isolated Storage
    • WP7 supports sandbox model storage to improve security and reduce the unauthorized access and data corruption
    • WP7 supports three types of storage options like 
      • IsolatedStorageSettings class to store app settings (key/value pairs)
      • IsolatedStorageFile class to store files and folders
      • LINQ to SQL to store relational data
    • Isolated Storage Explorer (ISETool.exe) can be used for different I/O operations
  • Notifications
    • WP7 supports three types of notifications like tile, toast and raw
    • Tile notifications are used to update app tiles
    • Toast notifications will be added to status bar
    • Raw notifications can be delivered to running applications directly
Delicious features in Mango Update (7.5)
WP7 first version has been missing some of the most sought features available on other mobile platforms. Mango update (version 7.5) filled this gap by adding more than 500 features to WP7. Out of these 500 only few features stand out from others are like tethering, social feature and multitasking.
  • More social networks in people hub like Twitter, LinkedIn
  • Share Music and video content with Windows Live messenger
  • Bing experience is improved with Voice guidance for turn-by-turn navigation, Indoor Maps (US only) and Audio/Music search
  • TellMe (voice to text) service enables hands-free messaging and chatting
  • SkyDrive and Office-365 document syncing
  • IE9 mobile which supports hardware acceleration for HTML5 rendering
  • Wi-Fi hotspot support (carrier dependent)
  • Sensors
    • Gyroscope – measures rotational velocity on 3d axis
    • Compass – determines the angle by which device is rotated relative to earth’s magnetic north pole
    • Motion API combines data from compass, gyroscope and accelerometer sensors
  • Socket communication is supported
  • Alarms and Reminders
    • Both can be used as a scheduled notification
    • Sound file for alarm can be changed whereas reminders use default sound file
    • Clicking on alarm takes user to alarm app whereas clicking on reminders takes user to corresponding app which has set that reminder
  • Multitasking
    • Supports single foreground application
    • App can perform below actions in background
      • Playing audio
      • Scheduled tasks using background agents
      • HTTP file transfer requests
      • Scheduled notifications like Alarms and reminders
Features and limitations in Tango Update (7.5 Refresh)
This update has two branches. First branch does impose some restrictions on low-end (256MB RAM) devices while other branch adds some minor changes to high-end devices.
  • Missing features for 256MB RAM devices
    • Fast app switching
    • Generic Background agents
    • SkyDrive automatic photo upload
    • Managing podcast subscriptions and watching video podcasts
    • HD Video playback
  • New features
    • MMS supports multiple attachments, video and voice note
    • Location aware icon will be displayed whenever app accesses location
    • Supports exporting of contacts to SIM card
    • Memory status information
Update: Today Microsoft has announced major update to WP7 namely Windows Phone 8. To know more about WP8 features, visit this blog

Monday, June 18, 2012

WP7 Platform Insights : Part 2 (App Development)

Today we will explore WP7 application development frameworks and app development life cycle in detail.


Most of the developers working on Microsoft technologies are aware of two popular frameworks namely Silverlight and XNA. Silverlight is cross-platform, cross-browser implementation of .Net framework for building media experiences and rich interactive applications for the web on desktop. Microsoft uses XNA framework for game development on its most popular gaming platforms like Xbox 360, Zune HD and Windows 7.
Considering popularity of these frameworks and availability of expertise, Microsoft has decided to use these frameworks for its new mobile OS WP7. However, restrictions on mobile device like memory constraints and form factors forced Microsoft to tweak these frameworks slightly for WP7.
We listed imported features regarding these application frameworks below
  • Silverlight for Windows Phone
    • Based on Silverlight 4
    • Optimized runtime to display content on memory constrained devices
    • Hosted on client and will not support web apps
    • Additional features which are not part of Silverlight like
      • Gesture aware controls
      • Support for SIP (software input panel)
      • Manipulation events for touch input
    • Supports building and running managed applications
    • Useful for RIA style or XAML based UI and event driven app
    • Includes WP native controls, HTML browser control
  • XNA
    • Based on .Net framework 2.0
    • Single framework targeted for multiple gaming platforms
    • Greater portability using cross-platform input APIs which are orientation-aware and resolution-aware
    • Includes set of managed APIs for 2D/3D geometry, textures and shading
    • High performance gaming framework to create multi-screen 2D/3D games
    • Allows managing art assets (like models, meshes, textures)
Before mango update of WP7, developer has to use any one of the above frameworks for his application’s visual designs though sharing of some classes across framework was possible.
Mango update of WP7 removed this restriction and allowed to use combination of both frameworks for your application’s visual design as well. However, prefer using single framework based on your applications requirements. If at all required, combine these two frameworks in your application by using the new SharedGraphicsDeviceManager and UIElementRenderer class.

Development Lifecycle

Above diagram shows development lifecycle of WP7 apps.
Below are some of the highlights of this development lifecycle
  • Windows Live ID is necessary for publishing apps on marketplace
  • Your device need to be registered as test device for debugging purpose
  • If you unregister your test device, you can’t run manually installed (side loaded) apps
  • Maximum three devices can be registered per developer account
  • Zune software necessary to deploy app on device
In next blog we will explore features provided in WP7 initial version, mango and tango updates.

WP7 Platform Insights : Part 1 (Overview)

Today we will be discussing Microsoft’s latest mobile OS Windows Phone 7 (in short WP7). We can consider WP7 as a successor to Windows Mobile (WM) but not update to WM as WP7 developed from scratch. It is completely new refreshed mobile OS, which will compete with other mobile platforms. Focus of WP7 is more towards consumer as against Windows Mobile’s enterprise focus.

One of the major differentiator from other OS is its Metro design interface. Hub is another feature through which it combines local and online content. In addition, WP7 has tight integration with other Microsoft products like Xbox (most popular gaming platform), MS Office and Windows Live web-based services.

Brief History

In 2004, Microsoft started working on major update to WM under the codename ‘Photon’. However, this project came to end without any product release due to slowness. In 2008, Microsoft’s WM OS started losing its market share to Blackberry and iPhone. As an effect, Microsoft revamped the WM team in 2008 and started working on WM 7. Again, Microsoft failed to meet deadlines and it has released WM 6.5 as interim release instead of initially planned WM7.
Due to these hiccups, Microsoft developed new mobile OS from scratch in short span of time without providing backward compatibility. World saw the glimpse of Microsoft’s new mobile OS on 15 February, at Mobile World Congress (MWC) 2010 held in Barcelona. At MIX 2010 event, world witnessed some more details about this new OS. Finally, SDKs are arrived in September 2010.
Microsoft had many hiccups in OS naming also. Initially they released new mobile OS with name as ‘Windows Phone 7 Series’ transitioning from old windows mobile. As expected, this lengthy and difficult name came under criticism from around the world including developers and partners. Bowing to this pressure, Microsoft dropped ‘Series’ word from this name.
Year 2011, mobility world saw the new mega partnership between Microsoft and Nokia. As part of this partnership, WP7 became primary Smartphone OS for Nokia.

Platform Overview

Lets discuss how the WP7 application platform architecture is there and what development tools it provides.


There are four main components in the WP7 Application Platform architecture

  • Runtimes
    • WP7 runtime supports Silverlight and XNA frameworks
    • You can run your Silverlight or XNA apps on WP7 with minor changes. These changes include adjusting UI for device’s screen resolution or making use of device specific features like GPS, Camera etc.
    • Runtime also includes phone specific components like sensors, Media etc.
  • Tools - When you install SDK, you will get many tools that are helpful for app development.
    • Visual studio – One of the best IDE is part of SDK. It supports debugger, designer, compiler, packager etc.
    • Expression Blend - Your UX team can use this tool and can create XAML files, which you can use it in your app directly. This helps developers and UX team to do their tasks independently.
    • Emulator – Developers can use emulator to run/debug their app before testing on actual device as it provides comparable performance to an actual device. WP7 emulator also supports emulating different device specific features like GPS, accelerometer etc. You can also take screenshots of your application.
    • XNA Game Studio – This is integrated game development environment used for Microsoft’s other platforms like Windows, Xbox 360 and Zune. Same tool is now available for WP7 developers. It includes other tools, which are useful for adding graphical and audio content into your game.
    • Documents – WP7 tools also includes sample codes, guides, API documentation etc.
  • Cloud Services – Cloud services are very useful to build powerful WP7 web applications with scalable features. It includes below mentioned services
    • Notifications (MPNS – Microsoft Push Notification Service) – Many applications need to fetch up to date information from server. For this, push notification is better as it reduces burden of polling and consumes less battery power.
    • Location – This cloud service is single source to get the position lookup data by making use of Wi-Fi, Cellular and GPS data. This service also includes AGPS, which improves fix for GPS.
    • Advertising SDK – This service is useful for monetizing your apps. Also provides efficient reporting mechanism.
    • Other services – Azure, Map, Identity, Social and Feeds are some other services which are supported WP7 platform.
  • Portal Services – Portal services supports marketplace related activities from single location. Below is list of some of the activities which portal services supports
    • Registration and validation – Developers can register here for App Hub using their Live ID.
    • Application submission – This includes set of online tools for helping developers to submit their apps in Marketplace. Here developers can track their apps certification status, provide updates to existing apps etc.
    • App Billing – Developers can use portal services to sell their paid apps. Marketplace supports mobile operator and credit card billing.
    • Business Intelligence – This is dashboard for your apps on marketplace. This dashboard shows all details of your apps like downloads, reviews, crashes etc.

Development Tools

We all know that Microsoft always provides best development tools compared any other technologies. Same is true in case of WP7. WP7 Developers can download and install Windows Phone SDK, which includes all necessary development tools and documents. WP7 SDK package contains below mentioned tools
Visual Studio 2010 Express for WP7
  • Development environment for WP7 which includes
    • Code editor and design surface for WP7
    • WP7 project templates
    • Toolbox containing WP7 controls
  • You can debug and deploy your apps on emulator or device
Note: If VS 2010 Professional or higher is already installed on your PC then WP7 SDK will install only plug-in for VS 2010 instead of VS 2010 Express for WP7
Silverlight SDK
  • Application framework used for writing RIA style user interfaces
  • It is XAML based and event driven app framework
  • Includes WP7 controls and web browser control
Expression Blend
  • Best UI design tool for designing XAML based interfaces for web and desktop applications
  • Accelerated results as design and development can be done independently
  • XAML files designed by UX team can be used by developer in their solutions directly
XNA Game Studio 4.0
  • Programming environment for creating games with VS
  • Includes XNA framework and managed libraries useful for game development for WP7, Windows, Xbox and Zune
WP7 Emulator
  • It can be used as a virtualized environment where you can debug, deploy and test your WP7 apps
  • Provides comparable performance to an actual device
  • Also supports simulation of GPS, accelerometer and orientation
  • Allows capturing screenshots
Other Tools
  • Advertising SDK allows you to monetize your apps
  • XAP deployment, isolated storage explorer and phone registration are some of the tools available as part of SDK
In next blog of this series, I will be discussing more about application development topics like frameworks and development lifecycle.

Thursday, February 16, 2012

Android C2DM: Part 3

In first two parts (Part 1 and Part 2) we have seen C2DM overview, architecture and workflow. Today in this part, we will explore more about error handling, comparison with other push technologies like Apple's APNS and Microsoft's MPNS etc. Finally, we will give references of some C2DM demo applications.
Error Handling
C2DM implementation should have error handling at different stages of C2DM workflow like while registration, sending registration ID to third party application server or sending push request to C2DM server. Mobile app and third party app server should handle HTTP error codes as usual. In this section, we will be discussing C2DM specific error handling only.

Registration Errors
Mobile app might get below mentioned errors as a response to registration intent.
  • SERVICE_NOT_AVAILABLE – App will get this error in two scenarios. First when a device gets internal server error (500) or Service unavailable (503) from server. When device is unable to read the response it received from server then also it gets this error. Application should retry for registration.
  • ACCOUNT_MISSING – As per pre-requisites, if there is no single logged in Google user present on device then we will get this error. App should convey this to user and open the settings account for adding new account.
  • AUTHENTICATION_FAILED – App gets this error when user gives wrong password for his Google ID.
  • TOO_MANY_REGISTRATIONS – When too many apps are C2DM registered from device, then C2DM server returns this error to avoid any abuse.
  • INVALID_SENDER – Sender Email ID is not white listed or not registered for C2dM. Therefore, C2DM server will not recognize sender ID and will return this error.
  • PHONE_REGISTRATION_ERROR – When user’s current device does not support C2DM then app will get this error.
Push Message Errors
When third party app sends HTTP post request to C2DM server for sending push message, it might get HTTP errors like 503 (service unavailable) or 401 (unauthorized), which it has to handle as usual. However, in this section we will discuss C2DM specific errors
  • QuotaExceeded – Too many messages from current sender ID
  • DeviceQuotaExceeded – Too many messages to device from sender ID
  • MissingRegistration – Request doesn’t contain mandatory registration_id field
  • InvalidRegistration – Request contains wrong registration_id
  • MismatchSenderId – Sender ID used for getting registration_id and sender ID contained in push request does not match.
  • NotRegistered – App got uninstalled or unregistered
  • MessageTooBig – Payload size more than allowed size (i.e. 1024 bytes)
  • MissingCollapseKey – Request doesn’t contain mandatory collapse key field
Comparison with other push technologies
In this section, let us see how Android C2DM is different from other push technologies available on other mobile platforms.


Windows Phone 7
(For push services)
OS Version
2.2+ (Froyo)
iOS 3.0 +
Mac X v7.0
Payload Size
1 KB
256 bytes
8 KB
3 KB (+ 1 KB Header)
Payload Format
Expiry Time
Controllable up to 30 days
Quota (per day)
(500 for unauthenticated web services)
Queue/Channels support
(4 per app)
(1 per app)
1 per app, 30 per device
SSL/TLS Support
Notification UI
App has to provide
Toast, Tile or Raw
Delivery guarantee
Delivery status
C2DM –Cloud to Device Messaging
APNS – Apple Push Notification Service
BPS – Blackberry Push Service
MPNS – Microsoft Push Notification Service

Demo Applications
Developers can refer below mentioned three applications for C2DM implementation. First two demo applications are open source and give complete understandings of C2DM flow. Third application ‘Earthquake Alerter’ highlights best usage of C2DM and Google App Engine. 

This is notepad-like open source demo application/solution and it has support for bidirectional synchronization. Native mobile client app in this solution is makes use of C2DM while Google App Engine is used as a third-party application server. This also has web client built using Google Web Toolkit
For more details visit here 

Google Chrome to Phone
This is another open source C2DM solution, which includes chrome extension, Android app and third-party server (using Google App Engine). This solution allows user to send the links from Chrome browser to mobile device. 
For more details visit here 

Earthquake Alerter 
This application makes use of push notification to alert the user whenever there is earthquake that matches users predefined filtered criteria. User can create filter based on location, radius, magnitude etc. This solution uses C2DM and Google App Engine.
For more details visit here 

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

Tuesday, January 31, 2012

Android C2DM: Part 2 (Lifecycle)

In Part 1 of this blog series we have seen C2DM overview. Today in this blog we will explore C2DM in details. We will see C2DM architecture and C2DM workflow.

C2DM Architecture
Below diagram explains high level C2DM architecture
Three parties are involved in this C2DM architecture 
  • Mobile device running C2DM based Android app
  • Third Party app server will send push message to device through C2DM server
  • C2DM server receives messages from third party app server and sends to mobile device/app
Different credentials passed between these parties while transferring C2DM message to authenticate involved parties and make secured data transfer between them. These credentials explained below
  • Sender ID/Email used in C2DM signup process and is associated with application’s developer
  • Application ID (package name) ensures messages are delivered to correct application
  • Registration ID issued by C2DM server is uniquely represents app running on specific device
  • Google User Account for at least one logged in user on device
  • Auth token required to get authorized access to Google services like C2DM

C2DM Workflow
Above diagram shows C2DM workflow in detail starting from C2DM registration to actual message delivery. These workflow steps grouped into three processes/categories as given below
  • C2DM setup
  • Sending message
  • Receiving message
Below sections gives more details about these three processes
C2DM Setup
  • C2DM signup - App developer has to sign up for C2DM service before implementing C2DM in his app. In signup process, he has to provide his app ID (package name) and Role Account Email ID. Generally, white listing of your account and getting developer quota is very quick. This is one time process for each application.
  • C2DM registration - Android app registers itself for C2DM service by firing registration intent ( App includes additional parameters in this intent like sender (Email ID used in C2DM signup process) and app (package name).
  • Get Registration ID - Android app has to register broadcast receiver for registration intent ( Google will send this intent upon successful registration.
  • Send registration ID to third Party App Server - Application has to send registration ID received from C2DM server to third party App server. We recommend sending device ID along with registration ID so that third party app server can update it into its database against device.
  • Storing registration ID - Third party app server stores or updates registration ID received from Android app in a database. App server uses this ID for sending message to Android apps.
  • Unregistering C2DM - When Android app does not want to receive C2DM message any more then it can do by calling unregister intent. In response C2DM server will send response which app can use to notify user about un-registration.
Sending message
  • Get Authentication Token - App server can get the authentication token by providing sender ID (Email ID) and password to Google’s client login service. You can get this token via any http tools or command line tools like curl. However, we recommend you to get the authentication token programmatically because over a time this might be changed.
  • App server initiates message sending - App server makes post request to Google’s C2DM server. This request includes auth token and registration ID. This request also contains payload data (key-value pairs) and collapse key (used to collapse group of like messages when device is offline). If C2DM server receives optional parameter delay_while_idle from app server in above request, it will not send message immediately if device is in idle.
  • C2DM server validates credentials - C2DM server will validate credentials received from app server by sending those details to Google authentication service.
  • Queue the message - Once credentials validated C2DM server queues the message.
  • Initiate message delivery - C2DM server initiates message delivery by sending request to C2DM messaging server.
  • Message Delivery - If targeted device (decided based on registration ID) is online then C2DM messaging server delivers message to it. After successful delivery, messaging server removes it from message queue.
Receiving message
  • Receive message - Android device running registered app receives message from C2DM server. Android system extracts key/value pairs from message payload. It then broadcasts the receive intent ( with extra parameters.
  • Process message - Application’s broadcast receiver receives intent along with additional information like account name and message. Application processes this data for further usage.
In Part 3 of this blog series we will see error handling, comparison with other push technologies and list of demo applications.

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