GCM defaultSenderID

Quoting THIS document, where you can find details about that implementation:

String authorizedEntity = PROJECT_ID; // Project id from Google Developers Console
String scope = “GCM”; // e.g. communicating using GCM, but you can use any
                      // URL-safe characters up to a maximum of 1000, or
                      // you can also leave it blank.
String token = InstanceID.getInstance().getToken(authorizedEntity,scope);

So as you can see, the first param you should pass to getToken() is the authorizedEntity, which should be your project id from Google Developers :)

Even if the project in GitHub had that string, it wouldn't server you any good, as this authorizedEntity is something unique for each app.


The gcm_defaultSenderId is a string is included by the google-services gradle plugin. Be sure you have the:

  apply plugin: 'com.google.gms.google-services'

in your build.gradle file.

This plugin should be available in the latest version of the build tools.

Like Vesko said this is your Sender ID which in this case is the Project Number in your dev console project. The google-services plugin extracts this from your downloaded project configuration file.


I hate those buggy Gradle plugins, and trying to get the google-services plugin to operate in a project with multiple flavours is no fun either.

I ended up getting the Sender Id by name:

InstanceID instanceID = InstanceID.getInstance(this);
String gcmDefaultSenderId = getString( getResources().getIdentifier("gcm_defaultSenderId", "string", this.getPackageName()) );
String token = instanceID.getToken( gcmDefaultSenderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);