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 static final int NOTIFICATION_ID ="GCMNotification". hashCode(); @Override public void onMessageReceived(String from, Bundle data) { String msgType = data.getString("type"); // Notification...