4

I am integrating GCM into my app, what i did was i have made the configuration file google-services.json and placed it inside the app folder (i am using Android Studio) the resource file is also imported and I am also including the plugin in my build.gradle of application like this

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

the problem is that it is still not resolved. I want to know what is wrong?

I have searched about it and i find this, i have used my project number now there is no error coming up. Is it right way to do? Someone please explain

Syed Raza Mehdi
  • 4,067
  • 1
  • 31
  • 47
  • I am not sure if I am right but I assume you are not sure about the purpose of the sender id? Have a look at this https://developers.google.com/cloud-messaging/gcm#senderid, here sender id and the other credentials used for GCM-implementations are explained. You have to get the sender id from your GCM-project from the Google Dev Console and use it when calling 'instanceID.getToken("place_your_sender_id_here", GoogleCloudMessaging.INSTANCE_ID_SCOPE, null)' – sschmid Aug 06 '15 at 07:44
  • i know the purpose of sender ID what i am asking it should read itself by reading the json config file, isn't it? – Syed Raza Mehdi Aug 06 '15 at 08:26
  • No you have to pass it manually to the register-method. As far as I know the config file is quite useless, I have got two Gcm-projects running fine without even having the config file included. – sschmid Aug 06 '15 at 08:32
  • I downloaded the sample and there i just added the config file in app folder and it doesn't ask me to add it manually. I don't understand why it is not working in my other project Also if i added it manually will it work perfectly. It is creating the gcm token so i am presuming it is working fine. – Syed Raza Mehdi Aug 06 '15 at 08:38
  • As soon as you receive a token everything is fine of course. We are having a similar discussion on another thread, refer to this answer: http://stackoverflow.com/a/31717800/3863059 As you discovered, you can manually hand over your sender id or, if the plugin would do it´s work, you should be able to use the generated R.string.gcm_defaultSenderId-resource containing your sender id defined in the config file. If the plugin is not working in your own project, I personally would just copy the sample and remove everything you do not need or just keep going with manually passing the sender id – sschmid Aug 06 '15 at 08:55
  • You can drop the R.string id and get the value by name: http://stackoverflow.com/a/38995785/606351 – Vaiden Aug 18 '16 at 10:43

1 Answers1

2

Take a look at the gradle files of the official google example: https://github.com/googlesamples/google-services/tree/master/android/gcm

You will see you need to do two things:

add

classpath 'com.google.gms:google-services:2.0.0-beta6'

to project gradle build file and

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

at the bottom of module app gradle build file.

Micro
  • 10,303
  • 14
  • 82
  • 120