Android push notifications with Google C2DM

19 05 2012

Push notification is message sent by server logic to specific android device. Message can be caught by specified application and handled in any way. For example some notification can be shown on the android status bar. Received message can also be handled by Application in the way which user will not even see. Application will just update its configuration, perform some action and close without showing anything on GUI.

Android users are familiar with it – GMail synchronization works this way. GMail server sends notification to the Android smartphone right after there is a new mail on the GMail Server. Developers can also make use from these notifications.

It is realized by permanently opened socket in the Android OS, listening for the messages sent from server. It is built-in component present in all Androids 2.2 and higher.

How to Do it?

The best description and instruction is on the google site. Key points are listed in this part. There are three components in the architecture:

1. Android Device

2. Google C2DM Server

3. Your application’s server with logic that decides when and to which device to send push message

How does it work?

1. Android device registers in C2DM Service, and receives its unique registration ID, sends this Id to App server where it is stored. Registration ID has to be periodically refreshed.

2. When application server logic decides to send push message it sends it to Google C2DM Server (using REST Webservice request) giving registration ID of target Android device

3. Google C2DM Server delivers message to Android device or queues it and retries if device is currently not available in network

4. C2DM message is converted by android OS to intent and Android application that is listening for message from app server receives it  by intentBroadcast and handles it.

What is required?

  • Need to have c2dm account (fast & free to create here). In basic contract you have 200 000 notifications per day for free(testing and low production apps). It can be extended.
  • User’s Google account set up on the android device and Google Play App installed
  • Additional Google account to create C2DM account and authorize while sending push from Application server
  • Android 2.2 or higher
  • Application permissions and listeners registrations defined in AndroidManifest.xml. Presented here.
  • you can pass parameters in push message (However remember that message size limit is 1024 bytes)
    • rather include parameters with instructions to download data, not the date itself due to message size limit
  • I don’t know if there is any QoS or guarantees regarding delay and reliability of this service. however due to my observations – mostly it works well. in most cases the message is delivered after few seconds after sending it.
Alternatives for using C2DM
Alternatives enables You to skip Google C2DM Server and service, and implement permanently listenting socket on the android device on You own. If you believe that it can be better than C2DM – you should read this article where alternative ways are described.

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!



One response

14 07 2012
Best Android push notification (C2DM) tutorials « Looks OK!

[…] Best Android push notification (C2DM) tutorials 14 07 2012 Here are the best tutorials (in my opinion) that I have found on the Internet about C2DM service for sending push notifications to Android device. There are three groups of them, each corresponds to one actor in the architecture. Details about Push notifications you can find in my previous post here. […]

Give Your feedback:

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: