我在嘗試從here
的示例代碼。但是我的應用崩潰了。如何使用非官方的Android Market API?
我添加了日誌記錄,發現它崩潰在session.flush();
,所以我刪除了該行,它不再崩潰。
但它沒有達到onResult
的回調。
package com.mytest.app;
import com.gc.android.market.api.MarketSession;
import com.gc.android.market.api.MarketSession.Callback;
import com.gc.android.market.api.model.Market.AppsRequest;
import com.gc.android.market.api.model.Market.AppsResponse;
import com.gc.android.market.api.model.Market.ResponseContext;
import android.app.Activity;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.util.Log;
public class MarketAPITestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d("Market API", "Started");
String email = "[email protected]";
String pass = "mypass";
String AndroidId = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID);
MarketSession session = new MarketSession();
session.login(email,pass);
session.getContext().setAndroidId(AndroidId);
String query = "maps";
AppsRequest appsRequest = AppsRequest.newBuilder()
.setQuery(query)
.setStartIndex(0).setEntriesCount(10)
.setWithExtendedInfo(true)
.build();
session.append(appsRequest, new Callback<AppsResponse>() {
@Override
public void onResult(ResponseContext context, AppsResponse response) {
Log.d("Market API", "Got response");
}
});
session.flush();
}
}
您可以發佈您的代碼?還有什麼例外? – Jack
用代碼更新了問題。我試圖用try/catch來捕獲異常,但eclipse說它無法到達,所以我不得不刪除它。我不確定在哪裏添加try/catch。 – mrburns
你能發佈異常嗎?如果你看看你的logcat,它應該在session.flush()上顯示一個異常。 – Jack