title: java.io.IOException: INVALID_PARAMETERS while implementing Google Cloud Messaging client
body: <p>I am following the tutorial as <a href="http://hmkcode.com/android-google-cloud-messaging-tutorial/" rel="nofollow">here</a>: </p>
  
  <p>While my GCM server is implemented, in implementing the GCM client, I get the exception: java.io.IOException: INVALID_PARAMETERS at this line(in the getRegId() in MainActivity as in that tutorial):</p>
  
  <pre><code>GoogleCloudMessaging gcm=GoogleCloudMessaging.getInstance(getApplicationContext());
  </code></pre>
  
  <p>My Android manifest looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="raf.rahulserver.com.myapplication" &gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&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="raf.rahulserver.com.myapplication.permission.C2D_MESSAGE"
          android:protectionLevel="signature" /&gt;
  
      &lt;uses-permission android:name="raf.rahulserver.com.myapplication.permission.C2D_MESSAGE" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name" &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=".GcmBroadCastReceiver"
              android:enabled="true"
              android:exported="true" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
                  &lt;category android:name="raf.rahulserver.com.myapplication"/&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          &lt;meta-data android:name="com.google.android.gms.version"
              android:value="@integer/google_play_services_version" /&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>It must be noted that the GCM AsyncTask (where that line is in doInBackground()), is an inner class in the activity, so getApplicationContext() is not wrong. Also I tried MainActivity.this instead of getApplicationContext(), still same effect.</p>
  
  <p>So what could I be doing wrong?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Here is the code which malfunctions as described above:</p>
  
  <pre><code>public void getRegId(){
          new AsyncTask&lt;Void, Void, String&gt;() {
              @Override
              protected String doInBackground(Void... params) {
                  String msg = "";
                  try {
                      if (gcm == null) {
                          gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
                      }
                      regid = gcm.register(PROJECT_NUMBER);
                      msg = "Device registered, registration ID=" + regid;
                      Log.i("GCM",  msg);
  
                  } catch (IOException ex) {
                      msg = "Error :" + ex.getMessage();
  
                  }
                  return msg;
              }
  
              @Override
              protected void onPostExecute(String msg) {
                  etRegId.setText(msg + "\n");
              }
          }.execute(null, null, null);
      }
  </code></pre>