Reputation: 13
Run android 2.3.7 crash to android 4.2.2 run ok sorry for my english
package com.lemieapp.gcmclient;
import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.extensions.android.json.AndroidJsonFactory;
import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
import com.google.api.client.googleapis.services.GoogleClientRequestInitializer;
import com.lemieapp.backend.registration.Registration;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Created by Dead or Alive on 07/04/2015.
*/
class GcmRegistrationAsyncTask extends AsyncTask<Void, Void, String> {
private static Registration regService = null;
private GoogleCloudMessaging gcm;
private Context context;
// TODO: change to your own sender ID to Google Developers Console project number, as per instructions above
private static final String SENDER_ID = "xxxxxxxxx";
public GcmRegistrationAsyncTask(Context context) {
this.context = context;
}
@Override
protected String doInBackground(Void... params) {
if (regService == null) {
Registration.Builder builder = new Registration.Builder(AndroidHttp.newCompatibleTransport(),
new AndroidJsonFactory(), null)
.setRootUrl("https://gcmclient-907.appspot.com/_ah/api/");
// end of optional local run code
regService = builder.build();
}
String msg = "";
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(context);
}
String regId = gcm.register(SENDER_ID);
msg = "Device registered, registration ID=" + regId;
// You should send the registration ID to your server over HTTP,
// so it can use GCM/HTTP or CCS to send messages to your app.
// The request to your server should be authenticated if your app
// is using accounts.
regService.register(regId).execute();
} catch (IOException ex) {
ex.printStackTrace();
msg = "Error: " + ex.getMessage();
}
return msg;
}
@Override
protected void onPostExecute(String msg) {
Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
Logger.getLogger("REGISTRATION").log(Level.INFO, msg);
}
}
LOg.cat
04-12 12:40:47.284 2162-2162/com.lemieapp.gcmclient D/szipinf﹕ Initializing inflate state 04-12 12:40:49.524 2162-2182/com.lemieapp.gcmclient W/dalvikvm﹕ threadid=9: thread exiting with uncaught exception (group=0x40015608) 04-12 12:40:49.584 2162-2182/com.lemieapp.gcmclient E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1 java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:200) at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274) at java.util.concurrent.FutureTask.setException(FutureTask.java:125) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) at java.lang.Thread.run(Thread.java:1019) Caused by: java.lang.IllegalArgumentException: running on Android SDK level 10 but requires minimum 11 at com.google.api.client.repackaged.com.google.common.base.Preconditions.checkArgument(Preconditions.java:119) at com.google.api.client.util.Preconditions.checkArgument(Preconditions.java:69) at com.google.api.client.extensions.android.AndroidUtils.checkMinimumSdkLevel(AndroidUtils.java:48) at com.google.api.client.extensions.android.json.AndroidJsonFactory.(AndroidJsonFactory.java:75) at com.lemieapp.gcmclient.GcmRegistrationAsyncTask.doInBackground(GcmRegistrationAsyncTask.java:36) at com.lemieapp.gcmclient.GcmRegistrationAsyncTask.doInBackground(GcmRegistrationAsyncTask.java:21) at android.os.AsyncTask$2.call(AsyncTask.java:185) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) at java.lang.Thread.run(Thread.java:1019) 04-12 12:40:49.684 2162-2164/com.lemieapp.gcmclient D/dalvikvm﹕ GC_CONCURRENT freed 228K, 50% free 2874K/5639K, external 0K/0K, paused 2ms+3ms 04-12 12:40:49.704 2162-2162/com.lemieapp.gcmclient W/KeyCharacterMap﹕ No keyboard for id -1 04-12 12:40:49.704 2162-2162/com.lemieapp.gcmclient W/KeyCharacterMap﹕ Using default keymap: /system/usr/keychars/qwerty.kcm.bin
Upvotes: 0
Views: 395
Reputation: 7494
Your logs actually give you what your error is - you need to set the minimum API level in the AndroidMaifest.xml to 11. According to the official docs, using GCM on pre 3.0 devices, requires the user to be signed into their Google Play services account. This is not needed in version 4.0.4 and above and that is why you are not seeing the error.
Upvotes: 0