Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registration confusion Android GCM

I am trying to migrate to GCM in Android, C2DM now being deprecated. The registration process described here is different from registration described here. Are both registration same? Can we see code for GCMRegistrar to know for sure?

like image 347
Gaurav Agarwal Avatar asked Jun 29 '12 10:06

Gaurav Agarwal


3 Answers

They are actually the same thing. The second one encapsulates the first one in a static method and registers a broadcast receiver. You can attach the source to the gcm.jar and see for yourself. You can find source code in ~/android-sdks/extras/google/gcm/gcm-client/gcm-src.jar

like image 20
vlada Avatar answered Oct 21 '22 00:10

vlada


I've successfully migrated my C2DM project to GCM. Tested, it works fine. The only changes were:

  • in the Android app - change the value of sender upon registration
  • on the server side - change the auth header and the URL

That was it, as far as the interaction with Google goes. There were more some changes dictated by the app's logic:

  • in the Android app, the registration ID was cached in its preferences. Upon upgrade, I remove reg ID from the preferences to force re-registration, this time with GCM.
  • the logic of passing the reg ID to the server got an extra boolean parameter - if this is a C2DM or GCM reg ID
  • the logic of sending messages became conditional upon the said parameter.

Throwing out the C2DM logic completely out of the server would be unwise - not everyone upgrades their Android apps. The old, C2DM-enabled versions will be out in the wild for some time. And Google pledged to keep C2DM running in the short term. So message sending is conditional - depending on reg ID type, it sends either to GCM or to C2DM.

EDIT re: conditional logic:

if($RegID_Is_GCM)
{
    $Auth = GCM_Auth();
    $URL = $GCM_URL;
}
else
{
    $Auth = C2DM_AUTH();
    $URL = $C2DM_URL;
}
like image 73
Seva Alekseyev Avatar answered Oct 20 '22 23:10

Seva Alekseyev


The Thing I like most in GCM is the RegID we will get from GCM server,it is not only an ID its an Address of this application on this Device. So this time you don't need to send a device Id to server along with your Registration Id as per was in C2DM.

In C2DM every time you request a registration id you will get a new ID.

But in GCM RegId generated by using your application package along with some device id so if you will request for Registration Id again and again you will receive the same RegId.

And if you uninstall an application and will install it again still GCM server will give you the same Registration Id.

So one Registraion Id will do no need of any Device Id to send to server.

like image 1
Piyush Agarwal Avatar answered Oct 20 '22 23:10

Piyush Agarwal