I am not sure where exactly the empty registration identifier is returned, but it is important to understand that:
GCMRegistrar.register(this, "517739810110");
is an asynchronous event and does not occur immediately. Therefore, the call:
GCMRegistrar.getRegistrationId(this);
right after you do not specify the registration identifier only an empty string. To get the registration ID correctly after your device has registered with the GCM servers, you need to process the following callback in your GCMBaseIntentService:
protected void onRegistered(Context context, String registrationId)
Here you will receive the registration ID and where you must register on the application server. You should use the GCM client sample as a guide for this:
@Override protected void onRegistered(Context context, String registrationId) { Log.i(TAG, "Device registered: regId = " + registrationId); displayMessage(context, getString(R.string.gcm_registered, registrationId)); ServerUtilities.register(context, registrationId); }
You should also keep track of how the GCM client sample is registered with DemoActivity :
final String regId = GCMRegistrar.getRegistrationId(this); if (regId.equals("")) { // Automatically registers application on startup. GCMRegistrar.register(this, SENDER_ID); }
Note that it does not request a registration identifier immediately after calling the register () method.
source share