[Java for Android App Development] FridayAngel:
Hello all,

I am trying to implement Google Cloud Messaging in my app, but I get the error java.io.IOException: AUTHENTICATION_FAILED when I test it on the device. Everything goes well on an Android 4 device, but I have two Android 2.3.3 devices (Samsung Galaxy II) and it fails every time.

From online search I learned that the error is/used to be because of a password problem or having multiple Google account installed. I checked the password and it's correct. It's true that the two devices tested had two Google accounts installed on each, but I uninstalled one and tried again but it failed again.

Anyone has any idea what could cause the problem?

The code that fails:

GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String regId = null;

try {
[B]regId = gcm.register(params[0]);[/B]
setRegistrationId(context, regId);
sendRegistrationToServer(regId);
} catch (IOException e) {
Log.e(getClass().getSimpleName(), "Registration failed. " + e);
e.printStackTrace();
}

The code is inside an AsyncTask. (Full code:

static public class BaseRegisterTask extends AsyncTask<String, Void, String> {
protected Context context = null;

BaseRegisterTask(Context context) {
this.context = context;
}

[MENTION=439709]override[/MENTION]
protected String doInBackground(String... params) {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String regId = null;

try {
regId = gcm.register(params[0]);
setRegistrationId(context, regId);
sendRegistrationToServer(regId);
} catch (IOException e) {
Log.e(getClass().getSimpleName(), "Registration failed. " + e);
e.printStackTrace();
}

return regId;
}

protected void sendRegistrationToServer (String regId) {
// OVERRIDE ME
}

protected void onError(IOException e) {
Log.e(getClass().getSimpleName(), "Exception registering for GCM: ", e);
}
}

)

The caller:

new RegisterTask(getBaseContext()).execute(MESSAGING_SERVER_ID);

@ onCreate of the main activity.

The log:

10-04 13:25:37.238: E/RegisterTask(4057): Registration failed. java.io.IOException: AUTHENTICATION_FAILED
10-04 13:25:37.253: W/System.err(4057): java.io.IOException: AUTHENTICATION_FAILED
10-04 13:25:37.421: W/System.err(4057):	at com.google.android.gms.gcm.GoogleCloudMessaging.register(Unknown Source)
10-04 13:25:37.421: W/System.err(4057):	at com.app.pushnotification.GCMRegistrarCompat$BaseRegisterTask.doInBackground(GCMRegistrarCompat.java:170)
10-04 13:25:37.421: W/System.err(4057):	at com.app.pushnotification.GCMRegistrarCompat$BaseRegisterTask.doInBackground(GCMRegistrarCompat.java:1)
10-04 13:25:37.421: W/System.err(4057):	at android.os.AsyncTask$2.call(AsyncTask.java:185)
10-04 13:25:37.421: W/System.err(4057):	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
10-04 13:25:37.421: W/System.err(4057):	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
10-04 13:25:37.421: W/System.err(4057):	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
10-04 13:25:37.421: W/System.err(4057):	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
10-04 13:25:37.421: W/System.err(4057):	at java.lang.Thread.run(Thread.java:1019)

Thank you in advance!