0

I am integrating GCM in my application. I did one R&D 2 years back where user can send the detail on the main activity like this

GCMRegistrar.checkDevice(this);
        GCMRegistrar.checkManifest(this);
        String regId = GCMRegistrar.getRegistrationId(this);
        if (regId.equals("")) {
          GCMRegistrar.register(this, SENDER_ID);   
        } else {
          Log.v(TAG, "Already registered");
        }

Here we can send the SENDER_ID, which was api key(if I recall correctly something like AIxxxxxxxxxxxxxp-xxxxx_xxxx_2xxxxxx2_De).

But how do we send this using the sample app. What is difference between SENDER_Id generated and API_KEY and SERVER_API_KEY. How is this implemented? I havegone through this link https://developers.google.com/cloud-messaging/registration. But got confuse. Can any body help me for these

  1. SENDER_ID, API_KEY and SERVER_API_KEY. What are those? when and where are they used?
  2. Use of google-service.json file in debug mode? Already gone through link What does google-services.json really do?
  3. Do we need to fill the entries inside json manually, or is it filled by android api's? Entried like "oauth_client": [], "api_key": [],
  4. In below line taken from RegistrationIntentService.java. R.string.gcm_sender_id is basically SENDER_ID or API_KEY String token = instanceID.getToken(getString(R.string.gcm_sender_id), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

Also is there any tutorial which is implemented based on the latest GCM integration(apart from sample provided by developer.android)

Help will be appreciated.

Community
  • 1
  • 1
Android
  • 3,660
  • 8
  • 41
  • 76

1 Answers1

0
  1. SENDER_ID is the 13-digit(currently) numeric String, which is the project number of your Google project created in Google Developer console, it's used on client side to register the application and get device token(registration_id) which is then used as recipient when you send notifications to gcm end server.

    API_KEY,SERVER_API_KEY are same thing, they are the 40-character String starting with AIza, they are used as authentication so GCM server knows who is sending the notification and does the person have the right to send notification to those registration_id(initially to the SENDER_ID, as that's where the registration_id come from).

2&4. In debug mode, the use of the file is to pass in the SENDER_ID, which is where R.string.gcm_sender_id in your question 4 comes from.

  1. I don't quite understand the question, API_KEY is used on the server side, Android client shouldn't need to deal with it.
Community
  • 1
  • 1
gherkin
  • 456
  • 7
  • 24
  • Okay understood. as per point3, What my question is, if you open google-service,json, it has lot of empty values, like I given in question. Do we need to fill those values manually or GCM API will take care of that.? – Android Feb 01 '16 at 10:38