I have followed http://developer.android.com/guide/google/gcm/gs.html#server-app to implement GCM in my application
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
if (GCMRegistrar.isRegistered(this)) {
Log.d(TAG, GCMRegistrar.getRegistrationId(this));
}
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, sender_id);
Log.d(TAG, "Registration id : "+GCMRegistrar.getRegistrationId(this));
}
else {
Log.d("info", "already registered as" + regId);
}
that returns empty string as registration ID what else is needed to get the registration ID??
I also got the empty string as a registration id and solved it as follow :
I have tried the second solution of Nick Wong and i changed =>
public static final String PROPERTY_REG_ID = "registration_id";
to =>public static String PROPERTY_REG_ID = "registration_id";
and simply it worked.
I also got the empty registration ID and finally fix it. Here are my solutions:
1) check the project ID. It should be the 12 char long shown in the hyperlink of Google API's console (not the Project ID you named in the project summary)
2) try change the final String regId to String regId. I don't know why but it works for me.
Hope it helps.
Make sure you defined the service in the "app_package" as this intent service will be called by the GCMBroadcastReceiver
For example
or
Fail to define the service correctly, there will be no callback for onRegister, and your Register Id is always empty
I got the same issue, the solution was:
You need to implement a GCMIntentService (extending from GCMBaseIntentService). And DO NOT !!! rename GCMIntentService by something else, this was a reason in my case.
Calling getRegistrationId() straight after register() is risky because register might not return the id straight away.
For my case I did a check later on in my script (upon button press) using:
if registered then call GCMRegistrar.getRegistrationId(this)); to get the ID registered.