title: Android Push Notifications: getting SERVICE_NOT_AVAILABLE as response
body: <p>I wrote code for push notifications.But response is "SERVICE_NOT_AVAILABLE". I tried so many times. I want to know the registration id of the device. Please any one help me how to get the registration id of the device. I install the google cloud messaging library in sdk manager too,.</p>
  
  <p>My code:
  GCMIntentService :</p>
  
  <pre><code>public class GCMIntentService extends IntentService{
  
      private static int count = 1;
      private NotificationManager notificationManager;
  
      public GCMIntentService() {
          super(null);
  
      }
      @Override
      protected void onHandleIntent(Intent intent) {
  
          handleMessage(this, intent);
      }
  
  
      @SuppressWarnings("deprecation")
      private void handleMessage(Context mContext, Intent intent) {
  
          long when = System.currentTimeMillis();
          int icon = R.drawable.reload_logo;
          try {
              Bundle gcmData = intent.getExtras();
              notificationManager = (NotificationManager) mContext
                      .getSystemService(Context.NOTIFICATION_SERVICE);
              PendingIntent contentIntent = null;
  
              Intent gotoIntent = new Intent();
              gotoIntent.setClassName(mContext,"com.reloadapp.reload.fragments.SplashActivity");//Start activity when user taps on notification.
              contentIntent = PendingIntent.getActivity(mContext,
                      (int) (Math.random() * 100), gotoIntent,
                      PendingIntent.FLAG_UPDATE_CURRENT);
  
              Notification notification = new Notification(icon,gcmData.getString("message"), when);
              notification.defaults |= Notification.DEFAULT_SOUND;
              notification.defaults |= Notification.DEFAULT_VIBRATE;
              notification.setLatestEventInfo(mContext,
                      "Reload.in",//title
                      intent.getExtras().getString("message"), contentIntent);//message
              notification.flags = Notification.FLAG_AUTO_CANCEL;
              count++;
              notificationManager.notify(count, notification);//This will generate seperate notification each time server sends.
          }catch (Throwable e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>GcmBroadcastReceiver :</p>
  
  <pre><code>public class GcmBroadcastReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
  
          ComponentName comp = new ComponentName(context.getPackageName(),
                  GCMIntentService.class.getName());
          context.startService((intent.setComponent(comp)));
          setResultCode(Activity.RESULT_OK);
      }
  }
  </code></pre>
  
  <p>GcmUtilities :</p>
  
  <pre><code>public class GcmUtilities {
  
      public static String GCMProjectId="xxxxxxxx"; 
  
      /**
       * This method used to get GCM project id.
       * 
       * @return represented {@link String}
       */
      public static String getGCMProjectId() {
          return GCMProjectId;
      }
  }
  </code></pre>
  
  <p>MainActivty:</p>
  
  <pre><code> public void enableGCM() {
  
          try {
              if (checkPlayServices()) {
                  gcm = GoogleCloudMessaging.getInstance(this);
                  String regid = getRegistrationId();
  
                  if (regid==null|regid.isEmpty()) {
                      registerInBackground();
                  }
              } else {
                  Log.i("GCM", "No valid Google Play Services APK found.");
              }
  
          } catch (Throwable e) {
              e.printStackTrace();
          }
      }
  
      private boolean checkPlayServices() {
          try {
              int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
              if (resultCode != ConnectionResult.SUCCESS) {
                  if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
  
                  } else {
                      Log.i("GCM", "This device is not supported.");
                      finish();
                  }
                  return false;
              }
          }catch(Exception e){
              e.printStackTrace();
          }
          return true;
      }
  
      private void registerInBackground() {
          new AsyncTask&lt;Void, Void, Void&gt;() {
  
              @Override
              protected Void doInBackground(Void... params) {
  
                  try {
                      if (gcm == null) {
                          gcm = GoogleCloudMessaging.getInstance(SplashActivity.this);
                      }
                      String regid = gcm.register(GcmUtilities.getGCMProjectId());
                      storeRegistrationId(regid);
                      Log.v("TAG_GSMMMMM_regid", "" + regid);
                  } catch (Exception ex) {
                      Log.v("TAG_GSMMMMM",""+ ex.getMessage().toString());
  
                  }
                  return null;
              }
          }.execute();
      }
  
      private void storeRegistrationId(String regId) {
          Editor editor = m_sharedPreference.edit();
          editor.putString("regid", regId);
          editor.commit();
      }
  
      public String getRegistrationId(){
          String registration_id=m_sharedPreference.getString("regid","");
          return registration_id;
      }
  </code></pre>
  
  <p>Manifest:</p>
  
  <pre><code> &lt;meta-data android:name="com.google.android.gms.version"
              android:value="@integer/google_play_services_version" /&gt;
          &lt;receiver android:name="com.reloadapp.reload.fragments.GcmBroadcastReceiver"
              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;action android:name="com.google.android.c2dm.intent.GCM_RECEIVED_ACTION" /&gt;
  
                  &lt;category android:name="com.reloadapp.reload" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          &lt;service android:name="com.reloadapp.reload.fragments.GCMIntentService"
              android:enabled="true" /&gt;
  </code></pre>