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.


Platform
Parameters
Android

iOS
Blackberry
Windows Phone 7
Name
C2DM
APN
BPS
MPNS
Registration
(For push services)
Yes
No
Yes
No
OS Version
2.2+ (Froyo)
iOS 3.0 +
Mac X v7.0
4.2+
7.x
Payload Size
1 KB
256 bytes
8 KB
3 KB (+ 1 KB Header)
Payload Format
String
JSON
XML
XML
Expiry Time
No
Controllable
Controllable up to 30 days
No
Quota (per day)
200,000
NA
100,000
Unlimited
(500 for unauthenticated web services)
Queue/Channels support
Yes
(4 per app)
Yes
(1 per app)
Configurable
Channels
1 per app, 30 per device
SSL/TLS Support
Yes
Yes
Yes
Yes
Notification UI
App has to provide
In-Built
In-Built
Toast, Tile or Raw
Free/Paid
Free
Free
Free
Free
Delivery guarantee
No
No
No
No
Delivery status
No
No
Yes
No
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. 

JumpNote
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.

3 comments:

  1. Cool read. I'm using C2DM for my Android project (server-side in AppEngine), but... I've been thinking if this is going to work for WP7 or iOS. Do you know if C2DM could be suitable for those devices? Or maybe should I consider something like WebOrb? Thanks for any comment.

    ReplyDelete
    Replies
    1. C2DM is Android specific and you can't use it for WP7 or iOS. There is similar push technology service available for WP7 and iOS devices as shown in above comparison table. You need to use APNS (Apple Push Notification Service) for iOS devices whereas MPNS (Microsoft Push Notification Service) for WP7 devices.

      Hope this helps.

      Delete
  2. Great post!!Thanks for sharing it with us....really needed.Our mission is to understand the value proposition of your business to better target your potential customers, in order to maximize the possibility of converting them into a qualified prospects.expert google

    ReplyDelete