title: Not able to Obtain a registration token and display in Logcat in android studio
body: <p>Not able to Obtain a registration token and display in Logcat in android studio this is my InstanceIDListenerService class</p>
  
  <pre><code>public class GCMTokenRefreshListenerService extends InstanceIDListenerService {
  
  //If the token is changed registering the device again
  @Override
  public void onTokenRefresh() {
      Log.d("GCMRegIntentService", "GCMTokenRefreshListenerService:" );
  
      Intent intent = new Intent(this, GCMRegistrationIntentService.class);
      startService(intent);
  }
  </code></pre>
  
  <p>this is my IntentService class file</p>
  
  <pre><code>public class GCMRegistrationIntentService extends IntentService {
  //Constants for success and errors
  public static final String REGISTRATION_SUCCESS = "RegistrationSuccess";
  private static final String[] TOPICS = {"global"};
  
  public static final String REGISTRATION_ERROR = "RegistrationError";
  
  
  //Class constructor
  public GCMRegistrationIntentService() {
      super("");
  }
  
  
  @Override
  protected void onHandleIntent(Intent intent) {
      Log.d("GCMRegIntentService", "token:" );
  
      //Registering gcm to the device
  
      registerGCM();
  }
  
  
  private void registerGCM() {
      //Registration complete intent initially null
      Intent registrationComplete = null;
  
      //Register token is also null
      //we will get the token on successfull registration
      //String token = null;
      SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
      try {
          //Creating an instanceid
  
  
  
          InstanceID instanceID = InstanceID.getInstance(this);
          String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                  GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
          //InstanceID instanceID = InstanceID.getInstance(this);
  
          //Getting the token from the instance id
          //token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
  
          //Displaying the token in the log so that we can copy it to send push notification
          //You can also extend the app by storing the token in to your server
          Log.e("GCMRegIntentService", "token:" + token);
          // Subscribe to topic channels
          subscribeTopics(token);
  
          //on registration complete creating intent with success
          registrationComplete = new Intent(REGISTRATION_SUCCESS);
  
          //Putting the token to the intent
          //registrationComplete.putExtra("token", token);
      } catch (Exception e) {
          //If any error occurred
          Log.w("GCMRegIntentService", "Registration error");
          registrationComplete = new Intent(REGISTRATION_ERROR);
      }
  
      //Sending the broadcast that registration is completed
      LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
  }
  private void subscribeTopics(String token) throws IOException {
      GcmPubSub pubSub = GcmPubSub.getInstance(this);
      for (String topic : TOPICS) {
          pubSub.subscribe(token, "/topics/" + topic, null);
      }
  }
  </code></pre>
  
  <p>this is my manifest file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;!-- needed for older devices -
   used to check app background / foreground status --&gt;
  &lt;uses-permission android:name="android.permission.GET_TASKS" /&gt;
  
  &lt;!-- START Added for GCM --&gt;
  &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;
  
  &lt;permission
      android:name="nath.prem.com.premgcmproject.permission.C2D_MESSAGE"
      android:protectionLevel="signature" /&gt;
  
  &lt;uses-permission android:name="nath.prem.com.premgcmproject.permission.C2D_MESSAGE" /&gt;
  &lt;!-- END Added for GCM --&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;activity android:name=".MainActivity"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
  
  
      &lt;!-- START Added for GCM --&gt;
  
      &lt;receiver
          android:name="com.google.android.gms.gcm.GcmReceiver"
          android:exported="true"
          android:permission="com.google.android.c2dm.permission.SEND"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
              &lt;action android:name="com.google.android.c2dm.intent.REGISTRATION" /&gt;
  
              &lt;category android:name="nath.prem.com.premgcmproject" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  
      &lt;service
          android:name="nath.prem.com.premgcmproject.GCMPushReceiverService"
          android:exported="false"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
  
      &lt;service
          android:name="nath.prem.com.premgcmproject.GCMTokenRefreshListenerService"
          android:exported="false"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.android.gms.iid.InstanceID" /&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
  
      &lt;service
          android:name="nath.prem.com.premgcmproject.GCMRegistrationIntentService"
          android:exported="false"&gt;
  
      &lt;/service&gt;
      &lt;meta-data
          android:name="com.google.android.gms.version"
          android:value="@integer/google_play_services_version" /&gt;
  
      &lt;!-- END Added for GCM --&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>
  this is my project based gradle file dependencies</p>
  
  <pre><code>   dependencies {
      classpath 'com.android.tools.build:gradle:2.1.2'
      classpath 'com.google.gms:google-services:1.5.0-beta2'
  
  
  }
  </code></pre>
  
  <p>this is my app-based gradle file content dependencies</p>
  
  <pre><code>dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:appcompat-v7:24.1.1'
  compile "com.google.android.gms:play-services:8.3.0"
  </code></pre>
  
  <p>getting this error message</p>
  
  <pre><code>'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzb
  07-25 15:08:54.919 19852-19874/? E/AndroidRuntime: FATAL EXCEPTION: IntentService[]
                                                     java.lang.IncompatibleClassChangeError: android.support.v4.content.ContextCompat
                                                         at com.google.android.gms.iid.zzd.zzdL(Unknown Source)
                                                         at com.google.android.gms.iid.zzd.&lt;init&gt;(Unknown Source)
                                                         at com.google.android.gms.iid.zzd.&lt;init&gt;(Unknown Source)
                                                         at com.google.android.gms.iid.InstanceID.zza(Unknown Source)
                                                         at com.google.android.gms.iid.InstanceID.getInstance(Unknown Source)
                                                         at nath.prem.com.premgcmproject.GCMRegistrationIntentService.registerGCM(GCMRegistrationIntentService.java:60)
                                                         at nath.prem.com.premgcmproject.GCMRegistrationIntentService.onHandleIntent(GCMRegistrationIntentService.java:41)
                                                         at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
                                                         at android.os.Handler.dispatchMessage(Handler.java:99)
                                                         at android.os.Looper.loop(Looper.java:153)
                                                         at android.os.HandlerThread.run(HandlerThread.java:60)
  07-25 15:08:54.961 520-539/? E/AppErrorDialog: Failed to get 
  </code></pre>