【发布时间】:2011-08-04 15:44:45
【问题描述】:
我正在尝试来自here 的示例代码。但是我的应用程序崩溃了。
我添加了日志记录,发现它在 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 = "somebody@gmail.com";
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();
}
}
【问题讨论】:
-
你能发布你的代码吗?还有例外吗?
-
用代码更新了问题。我试图用 try/catch 捕捉异常,但 eclipse 说它无法到达,所以我不得不删除它。我不确定在哪里添加 try/catch。
-
你能发布异常吗?如果你查看你的 logcat,它应该在 session.flush(); 处显示一个异常;
-
好的,问题与android id有关。当我将 android id 更改为“dead000beef”时,我得到了来自服务器的有效响应。当我使用自己的 androidid 时,出现 400 错误。
-
session.login 总是抛出 LoginException 错误。有什么帮助吗?
标签: java android flush google-play