Victor Ronin
Victor Ronin

Reputation: 23308

Problems with Android GCM

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:

This service thing confuses me a lot:

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

Answers (1)

Eran
Eran

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

Related Questions