I read here on how to receive a GCM message: http://developer.android.com/google/gcm/client.html - I'm talking about the title: Receive a downstream message. There is a note: Using WakefulBroadcastReceiver is not a requirement. If you have a relatively simple app that doesn't require a service, you can intercept the GCM message in a regular BroadcastReceiver and do your processing there. Once you get the intent that GCM passes into your broadcast receiver's onReceive() method, what you do with it is up to you.
When a GCM message is received all I want is to extract the title from it and put it in the notification area so when the user clicks on it, it will open my app with a specific fragment. Ofcourse, the device might be asleep when that message arrives.
The broadcast receiver example is this:
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
So here are several questions:
1) Wakeful broadcast receiver is solely to prevents the device from going to sleep or also to wake it up when a message arrives?
2) How can I know if I need a regular broadcast receiver or a wakeful one?
3) Assuming I have several broadcast receivers, how does the app knows which to use when a message arrives?
4) Instead of calling an intent service that uses the intent of the broadcast receiver, if I only want to extract the title and put it in the notification area, I should just handle the intent inside the broadcast receiver itself?