運行Android 2.3.7碰撞到Android 4.2.2運行正常 對不起,我的英語GCM註冊的AsyncTask crasch的Android 2.3.7
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:初始化充氣狀態 04-12 12:40:49.524 2162-2182/com.lemieapp.gcmclient W/dalvikvm:threadid = 9:thread退出與未捕獲的除外E/AndroidRuntime:致命異常:AsyncTask#1 java.lang.RuntimeException:執行doInBackground()時發生錯誤() 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.ja va:581) at java.lang.Thread.run(Thread.java:1019) 引起:java.lang.IllegalArgumentException:在Android SDK級別10上運行,但在com.google.api.client上最少需要11 。請訪問com.google.api com.google.api.client.util.Preconditions.checkArgument(Preconditions.java:69) 以重新包裝..com.tw。com.mon.base.Preconditions.check參數(Preconditions.java:119) 。 (com.google.api.client.extensions.android.json.AndroidJsonFactory。 .doInBackground(GcmRegistrationAsyncTask.java:36) at com.lemieapp.gcmclient.GcmRegistrationAsyncTask.doInBackground(GcmRegistratio nAsyncTask.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 (ThreadPoolExecutor.java:581) 在java.lang.Thread.run(Thread.java:1019) 04-12 12:40:49.684 2162-2164/com.lemieapp.gcmclient D/dalvikvm:GC_CONCURRENT已釋放228K,50%空閒2874K/5639K,外部0K/0K,暫停2ms + 3ms 04-12 12:40:49.704 2162-2162/com.lemieapp.gcmclient W/KeyCharacterMap:無鍵盤ID -1 十二月4日至12日:40:49.704 2162年至2162年/ com.lemieapp.gcmclient W/KeyCharacterMap:使用默認的鍵盤對應:/system/usr/keychars/qwerty.kcm.bin
我也面臨同樣的問題,你解決了嗎? – Programmer