I know that in Android, both in iOS and WP7 ( In which mobile platforms is the “token token” not constant?), The token provided to the CAN device is changed.
This means that we must deal with this by requiring a new token, at least every time our application starts.
However, this leads to a complete contradiction with what I have found so far in googles tutorials. (I can't remember exactly where I found this code, but I'm sure it was provided by Google). The code looks like this: this:
//registering for push GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); if (regId.equals("")) { GCMRegistrar.register(this, SENDER_ID); Log.i("****************","I just Registered!!"); } else { Log.i("****************","Already registered"); }
The above code will execute the line GCMRegistrar.register(this, SENDER_ID); only once, at the first launch of the application. But I guess this is wrong? Because if the token changes, there is no way for our application to see this, because it requires the token only once.
EDIT
Actually, I just found where exactly this code was. Take a look here: Getting Started Guide
I quote:
In the onCreate () method, add the following code:
GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); if (regId.equals("")) { GCMRegistrar.register(this, SENDER_ID); } else { Log.v(TAG, "Already registered"); }
When registering a device, the onRegistered(Context context, String regId): function is onRegistered(Context context, String regId): . This function is described in the tutorial:
onRegistered (Context context, String regId): Called after receiving a registration application, passes the registration identifier assigned by GCM to this pair of devices / applications as a parameter. Typically, you should send regid to your server so that it can use it to send messages to this device.
So, he says that I should send this identifier to my server. But earlier the code showed us that this function will be called only once! So what happens when the token changes? How am I going to update it on my server? I think I should run this function every time the application starts ...
Am I missing something here? Is the code incorrect? Any thought would be helpful :)