https://developers.google.com/cloud-messaging/android/client I\'ve read this article. And it says that I need to download and add the configuration file to my project. But t
If you do not generate and add the proper configuration file to your project, then yes, you will not be able to get push notification working.
In previous version of the SDK, you had to configure the senderID manually in your code.
Now, with GCM 3, Google has unified the way to configure Google Service. Their portal now let you configure all the service you want to enable for your app. Once done, it generates a configuration file that contains the parameter you need from the mobile to use the service.
Without that info, and most notably the project number, Google will be unable to generate InstanceID that allows receiving push with your senderID and Server API key. This is a way to match the client credential on Android, with the server credentials on the backend that allows you to send push notifications to your Android app and your app only.
The configuration file is used by the google-services Gradle Android plugin to generate the needed configuration resources. It means you are using it if you have this in your build.gradle
file:
apply plugin: 'com.google.gms.google-services'
Then, it will generate the resource R.string.gcm_defaultSenderId
that you see in Google GCM example code:
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
However, if you decide to hardcode the SenderID in your code and pass it to the instanceID.getToken
method, then indeed, it will work.
Having the JSON configuration file is a convenience provided by Google. It is cleaner as it centralize all your Google Service parameter.
The link of your app to project / senderID is mandatory, but if you really do not like the idea of having this JSON Google server configuration file you can work around it by putting the needed values elsewhere manually.
I am also working on multiple GCM-projects but still using Eclipse, Eclipse-ADT-plugin and the old project structure and I did not include this config-file into my projects. I also was confused at the beginning and hence tried it in a Android-Studio project using Gradle but the config file was not necessary either.
So Rémond´s answer might make sense but for me everything is working fine (including generating InstanceID-Token and also Topic-Messaging is working).
So in fact, it should work without adding the file and you do not need this file anyway.