Receiving downstream messages

With the basic blocks required to set up the GCM client already in place, in our first GCM example we will send a simple downstream message through the GCM Platform and print it as a notification on the Android Notification drawer.

To handle GCM messages, we will have to implement a service that extends from GcmListenerService and override the onMessageReceived(String,Bundle) method. Since GcmReceiver extends WakefulBroadcastReceiver, it is guaranteed that the CPU is going to be awake until the service completes the delivery.

Our GcmListenerService subclass will receive a message from GCM and create an Android Notification as soon as it receives it.

public class NotificationGCMHandler extends GcmListenerService { public ...

Get Asynchronous Android Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.