Migrate from C2DM to GCM for a background service

123 views
Skip to first unread message

KL_Weston

unread,
Nov 21, 2013, 10:42:54 AM11/21/13
to androi...@googlegroups.com
Hi
My app has a bacground service in it, which currently uses C2DM. I want to migrate to GCM.
 
There are 2 GCM implementations available to me
1: using gcm.jar and replace the C2DM email address with the sender ID
2: use Google Play Services and the GoogleCloudMessaging class to register for GCM
 
Option 1 above provides the simplest migration path from C2DM to GCM, however, that gcm.jar is deprecated. So I'd be moving from one deprecated push mechanism (C2DM) to another (GCM using the gcm.jar)
 
Option 2, requires you to check that the GooglePlayServices are up to date on your device before you can register for GCM. You can make the Google Play Services ready for use by calling GooglePlayServicesUtil.getErrorDialog() api. However, I cant call this api from a background service as it may result in screens being displayed to the user, something which you should not do from a background service.
 
Currently I have both C2DM and GCM (using Google Play Services) active in my Android client. I would prefer to have just GCM active, and to drop C2DM, but if the Google Play Services are not ready for use on the device, then I cant use GCM. Now I could have a situation where my background service is not registered for GCM and if it had continued to use C2DM it would have be registered for that.
 
 

Questions:

1: What is Googles recommended migration path for C2DM->GCM for background services. Should I use the gcm.jar approach, even though its deprecated?

2: If Google Play Services are not currently available on the device, should you fall back to using C2DM, rather than call GooglePlayServicesUtil.getErrorDialog()?

3: Having both C2DM and GCM active in my client is unsatisfactory. When I register for GCM using GoogleCloudMessaging.register(senderId), a com.google.android.c2dm.intent.REGISTRATION message is broadcast, which is picked up my my C2DM receiver. I can not tell if the message is a C2DM registration message or a GCM registration message. Is there a way to distinguish between the 2 registration messages? I know that GoogleCloudMessaging.register() returns the registration Id, but it also results in that com.google.android.c2dm.intent.REGISTRATION message being broadcast which seems unnecessary and confuses the real C2DM receiver.

I welcome your advise / insight into my problem. The documentation around Google Play services seems a little light and does not address its use from background services.

Kind regards

 
 
 
 

Guillaume Perrot

unread,
Nov 22, 2013, 11:15:23 AM11/22/13
to androi...@googlegroups.com
Hi,
If GCM is not available on the device, why would C2DM be available?
AFAIK, the Android device has a unique XMPP connection for both and is not aware of the differences: GCM works with old Android 2.2 devices, at Android 2.2 time, only C2DM was released.
This may be the reason why you can't tell the difference between a C2DM registration identifier and a GCM registration identifier in the intent: you have to remember the last service you sent the registration intent for and assume the result corresponds to the last request.

According to me, you should only use GCM from now on.
Compatibility with C2DM should only be managed server side, not client side.

KL_Weston

unread,
Nov 22, 2013, 11:46:23 AM11/22/13
to androi...@googlegroups.com
If you use Google Play Services on the client side to implement GCM, this service may not be available. The user can go into the Settings app and remove Google Play Services. Then they are not available on the device so the client can not register for GCM using Google Play Services.
C2DM and GCM (using the gcm.jar) are not like that. You just register by firing off a "com.google.android.c2dm.intent.REGISTER" intent. They are always available to the client.
 
I'm thinking if I want to move my client to GCM, then I should just use the gcm.jar and replace the email address with the SenderId and forget about using the Google Play Services. Its just that the Google docs say that the gcm.jar has been superceeded by Google Play Services.
 
Thanks for your input on this.

Guillaume Perrot

unread,
Nov 22, 2013, 11:56:54 AM11/22/13
to androi...@googlegroups.com
Even if you don't use Google Play Services lib, the intents are managed by the same system application, which is Google Play.
The libs are just helper code on top of the intents, and I don't use them at all by the way.
So yes the intents are available to use from ad-hoc code, but that does not mean they will work better than when using the google libs ;)

The only reason to use Google Play Services for me is the advanced features of GCM like bidirectional stream, but I don't need that.


2013/11/22 KL_Weston <klavi...@gmail.com>

--
You received this message because you are subscribed to a topic in the Google Groups "android-c2dm" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-c2dm/6w8wQpWgnyo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-c2dm...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Guillaume Perrot
Software Engineer, Capptain
a. 18 rue Tronchet, 75008 Paris, France
IMPORTANT: The contents of this email and any attachments are confidential. They are intended for the named recipient(s) only. If you have received this email by mistake, please notify the sender immediately and do not disclose the contents to anyone or make copies thereof.

KL_Weston

unread,
Nov 22, 2013, 12:14:20 PM11/22/13
to androi...@googlegroups.com
Thanks for your help on this.
I dont need bidirectional messaging either.
 
So did you only need to replace the email address with the sender id, in the C2DM0 register intent. Did you use gcm.jar on the client side? I'm not sure thats even needed if you are just using the same old C2DM intent.
 
So the GCM registration is simply:
        Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
        registrationIntent
.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
        registrationIntent
.putExtra("sender", senderID);
        startService
(registrationIntent);
And then you listen for registration intents like you do for C2DM?

Many thanks again.

Guillaume Perrot

unread,
Nov 22, 2013, 12:30:35 PM11/22/13
to androi...@googlegroups.com
Yeah I use the same intent and just replaced sender ID ;)
Listener for results and received messages are also the same.

2013/11/22 KL_Weston <klavi...@gmail.com>
Reply all
Reply to author
Forward
0 new messages