Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCM defaultSenderID

Could somebody please help me understand what the gcm_defaultSenderId is in the following code (found in onHandleIntent in RegistrationIntentService.java):

InstanceID instanceID = InstanceID.getInstance(this);             String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),                     GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);             // [END get_token]             Log.i(TAG, "GCM Registration Token: " + token); 

This is from the Google sample app for implementing GCM into your app, and it doesn't even compile in their app! I'm sure it's something specific to each app. I've already added the GCM API to my application, just don't know what this string is supposed to be! Thanks!

like image 240
Brandon Avatar asked Jun 07 '15 14:06

Brandon


People also ask

What is a GCM message ID key?

Google Cloud Messaging (GCM) Sender ID: A unique numerical value which is created when you configure your Project in the Google Developers Console/ Google Cloud Console.

What is GCM connection?

This document describes the Google Cloud Messaging (GCM) HTTP connection server. Connection servers are the Google-provided servers that take messages from the 3rd-party application server and sending them to the device.


2 Answers

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.

like image 63
Arthur Thompson Avatar answered Oct 19 '22 22:10

Arthur Thompson


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.

like image 23
Vesko Avatar answered Oct 20 '22 00:10

Vesko