Wednesday, July 3, 2013

Introduction

In this blog I’ll demonstrate a solution for implementing push notification services for Android applications. It will leverage on the existing technologies that Google provides for the developers: Android platform, Google Cloud Messaging (GCM) and Google App Engine.

As you are probably already familiar, GCM is push notification service for Android platform that delivers notifications to your phone. Notifications are commonly used for notifying user about installed application updates or important status updates, for example, the Twitter application that notifies you about re-tweets. It is important to mention that push notification services (PNS) should be used with precaution since there are intended only to notify user about crucial things at the current moment. For example, if a user bids on an auction on the eBay, he/she should be notified if someone places bigger bid. Also, notifications should not be used if the messages will come too frequently. Too frequent notifications will annoy user and he/she will probably uninstall your app. PNSs are also not intended for delivering any confidential content since they don’t support encryption and they should not be used for these purposes. Instead, make sure you meet requirements as frequency, importance and sending it in a relevant time.

Architectural overview

First let’s get familiar with GCM, in order to better understand how our solutions will look like in the very end.GCM system consists of three components:

Client (Android application)

Backend server (Google App Engine backend)

GCM service

GCM provides us services for sending notifications to the Android smart phones. These notifications are messages that are constructed and sent to GCM by backend server who initiates notification sending (in Figure01 step a), i.e. backend server behaves as notification trigger. Backend server also stores all registration_ids of every subscriber (phone with installed application) and with these information server knows which group of subscribers it wants to target (in Figure01 step 3). Mobile app simply asks GCM for registration_id and connects to push service in order to receive notifications (in Figure01 step 1). It can also send registration_id delivered by GCM to the backend server (in Figure01 step 3).For using GCM notification system several credentials need to be used:

sender_id - project number that uniquely identifies the project in Google Application Console,

application_id - identifies the application and it’s necessary to be used for receiving messages,

registration_id - identifies device with the installed app and it’s also necessary to be used for receiving messages. Device receives it from GCM service during connection process.

sender_auth_token - or API_KEY that is used on a server side in order to use GCM services

Step 04: In the left navigation menu go to Services and enable Google Cloud Messaging for Android

Figure03 – Turn on GCM for Android

Step 05: In the same menu go to API Access. Now you need to create a server key. Click on Create New Server Key… and for this case leave IPs field empty and follow with create (no IP address needs to be specified if you want to be in public domain).

Step 06: In the same menu go to Overview.

So far we generated following credentials:

sender_id: in the Overview you can see Project Number and that is your sender_id (will be used in Android application)

application_id: as explained before will be received from the GCM when the mobile connects to the GCM

registration_id: as explained before will be received from the GCM when the mobile connects to the GCM

sender_auth_token: in the API Access you can see under Key for server apps (with IP locking) the API key which is your sender authentication token (will be used in Google App Engine web application)

google_user_account: is not necessary since in this tutorial will develop Android 4.0 application

Now we are ready to implement our notification system. Follow this next blog.