Reputation: 23308
I am integrating GCM to my app (based on this Google's article). They claim that "it also offers a streamlined registration API that is recommended." I feel it's pain in the ass. I fought through a couple of layers of problems and now I'm stuck on the following one:
The article mentions:
MyBroadcastReceiver
(in the manifest) and GcmBroadcastReceiver
(in the code).
I assumed it's the same thing and correct name in the Manifest should be GcmBroadcastReceiver
MyIntentService
(in the manifest) and isn't mentioned in the code at all.
As I understand this is a service which should extend/implement GCMBaseIntentService
.
This service thing confuses me a lot:
I am using String regID = GoogleCloudMessaging.register(SENDER_ID);
. In such case, GCMBaseIntentService.onRegistered()
seems unnecessary for getting the regID.
Also, I have a broadcast receiver GcmBroadcastReceiver
which receives pushed messages. In such case, GCMBaseIntentService.onMessage()
is unnecessary.
Taking this into account, I have a feeling that I should either use GCMBaseIntentService
+ GcmBroadcastReceiver
or GCMBaseIntentService
.
Please, can somebody explain which combination of these should I use with this pesky streamlined registration API?
Upvotes: 3
Views: 1061
Reputation: 394146
An Android application running on a mobile device registers to receive messages by calling the GoogleCloudMessaging method register(senderID...). This method registers the application for GCM and returns the registration ID. This streamlined approach replaces the previous GCM registration process.
Based on this, GCMBaseIntentService
is obsolete when using the new registration method. It is replaced by GcmBroadcastReceiver
and GoogleCloudMessaging
.
I don't know in what way the new registration process is better than the old one. If you don't plan to use GCM for sending messages from the device to the cloud, you can stick with the old GCMBaseIntentService
. This link shows the old way of doing things. The old way also requires the broadcast receiver, but you use the class supplied by Google, and the only code you have to write (beside initiating the registration) is a class that extends GCMBaseIntentService
, in which you implement onRegistered
and onMessage
.
If you want to use the new "streamlined" registration, you only need GcmBroadcastReceiver
for handling the message and GoogleCloudMessaging.register
for registering.
As for the manifest :
.MyIntentService
is optional :
An intent service to handle the intents received by the broadcast receiver. Optional.
.MyBroadcastReceiver
probably refers to a broadcast receiver that you should implement, and GcmBroadcastReceiver
is an example of such a receiver.
Upvotes: 4