title: Android gcm client using GoogleCloudMessaging
body: <p>I am using the new way of using gcm described <a href="http://developer.android.com/google/gcm/client.html" rel="nofollow">here</a> using <code>GoogleCloudMessaging</code> class.
  But 9 out of 10 times it is giving me <code>SERVICE_NOT_AVAILABLE</code> error. Only once it registers a device.</p>
  
  <pre><code>07-01 14:24:55.907    2074-2090/com.deveyes.carrefour          W/System.err:                   java.io.IOException: SERVICE_NOT_AVAILABLE
  
  07-01 14:24:56.037    2074-2090/com.deveyes.carrefour          W/System.err: at com.google.android.gms.gcm.GoogleCloudMessaging.register(Unknown Source)
  </code></pre>
  
  <p>My code is as follows inside my Activity:</p>
  
  <pre><code> .....
       gcmRegId = gcm.register(CarrefourConfig.GCM_SENDER_ID);   
   .....                                                       
  </code></pre>
  
  <p>Later I came to know that I need to use Automatic retry. I have read <a href="http://developer.android.com/google/gcm/adv.html" rel="nofollow">this</a> but this document seems to be old. As with the new way we do not use IntentService anymore. or do we ? Inside BroadcastReciever i can get the message and notify user.</p>
  
  <p>what I am doing wrong here?</p>
  
  <p>EDIT:</p>
  
  <p>MY manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="17" /&gt;
  
  
  &lt;supports-screens
          android:xlargeScreens="false"
   /&gt;
  
  
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  
  &lt;uses-feature android:name="android.hardware.location" android:required="true" /&gt;
  &lt;uses-feature android:name="android.hardware.location.gps" android:required="false" /&gt;
  
  &lt;permission
          android:name="com.deveyes.carrefour.android.MAPS_RECEIVE"
          android:protectionLevel="signature" /&gt;
  
  
  &lt;uses-feature
          android:glEsVersion="0x00020000"
          android:required="true" /&gt;
  
  &lt;uses-permission android:name="com.deveyes.carrefour.android.permission.MAPS_RECEIVE" /&gt;
  &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  
  
  &lt;permission android:name="com.deveyes.carrefour.android.permission.C2D_MESSAGE"
              android:protectionLevel="signature" /&gt;
  &lt;uses-permission android:name="com.deveyes.carrefour.android.permission.C2D_MESSAGE" /&gt;
  
  &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;
  &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;
  &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/Theme.Carrefour"
          android:name=".CarrefourApplication"&gt;
  
      &lt;meta-data
              android:name="com.google.android.maps.v2.API_KEY"
              android:value="AIzaSyCKznwauzk_rNdKf7Qw0rjpmf4AWchCRwI" /&gt;
  
      &lt;activity
          android:name=".ui.MainActivity"
          android:label="@string/app_name"
          android:screenOrientation="portrait"&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;receiver
              android:name=".gcm.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;category android:name="com.deveyes.carrefour" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  
      &lt;!--service android:name=".services.CarrefourLocationService" /--&gt;
  
  
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>My MainActivity:</p>
  
  <pre><code>private void registerBackground() {
  
      new AsyncTask(){
  
          @Override
          protected Object doInBackground(Object[] objects) {
  
              try {
                  if(gcm == null){
                      gcm = GoogleCloudMessaging.getInstance(context);
                  }
                   gcmRegId = gcm.register(CarrefourConfig.GCM_SENDER_ID);
  
                  Log.i(TAG,"regid:"+gcmRegId);
  
                  setRegistrationId(context,gcmRegId);
                  ServerUtilities.register(context,gcmRegId);
  
  
              } catch (IOException e) {
                  e.printStackTrace();
              }
              return null;
          }
      }.execute(null,null,null);
  }
  </code></pre>