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