0

I am learning how to send and receive push notifications via GCM, I followed this tutorial

and there is a class called GCMRegistrationIntentService posted below. concerning the following line:

InstanceID instanceID = InstanceID.getInstance(getApplicationContext());
//Getting the token from the instance id
token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

what is R.string.gcm_defaultSenderId)? I tried to find it in strings.xml, but such an entry was not available

could please clarify and explain?

Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • 3
    Possible duplicate of [GCM defaultSenderID](https://stackoverflow.com/questions/30694817/gcm-defaultsenderid) –  Jul 20 '17 at 15:17
  • in other way you can use fcm instead –  Jul 20 '17 at 15:22

2 Answers2

0

You can use FirebaseInstanceIdService to get token.. like bellow

       public class FirebaseIDService extends FirebaseInstanceIdService {


     @Override
       public void onTokenRefresh() {
         String token = FirebaseInstanceId.getInstance().getToken();


      }
   }

Don't forget to add bellow code to andoridmainfest.xml

  <service android:name=".FirebaseIDService" android:exported="true">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>
Enamul Haque
  • 4,789
  • 1
  • 37
  • 50
0

That string contains your project_number and is auto-generated by Gradle based on your google-services.json file:

The main result of the JSON processing is to produce two XML files which you can reference as Android resources in your Java code. Below is an example of each file:

app/build/generated/res/google-services/{build_type}/values/values.xml

Source: https://developers.google.com/android/guides/google-services-plugin

CarHa
  • 1,148
  • 11
  • 31