9
以下方法在我的Android設備上調用時系統拋出IOException,而Internet連接處於活動狀態(我可以檢索電子郵件或使用Android設備連接到Gmail)。由AccountManagerFuture.getResults拋出的IOException,而連接處於活動狀態
任何人都可以請幫忙嗎?
private void performAuthentication() {
Log.d("GAWidget", "performAuthentication");
GoogleCredential credential = new GoogleCredential();
GoogleAccountManager accountManager = new GoogleAccountManager(this);
Log.d("GAWidget", "after getting accountManager");
Account account = accountManager.getAccountByName("[email protected]");
Log.d("GAWidget", "after getting account"+"account.name: "+account.name);
accountManager.getAccountManager().getAuthToken(account, "oauth2:https://www.googleapis.com/auth/analytics.readonly",
true, new AccountManagerCallback<Bundle>() {
public void run(AccountManagerFuture<Bundle> future) {
try {
String token = future.getResult(15, TimeUnit.SECONDS).getString(AccountManager.KEY_AUTHTOKEN);
Log.d("GAWidget", "token: "+token);
useToken(token);
} catch (OperationCanceledException e) {
Log.e("GAWidget", "OperationCanceledException", e);
} catch (AuthenticatorException e) {
Log.e("GAWidget", "AuthenticatorException", e);
} catch (IOException e) {
Log.e("GAWidget", "IOException", e);
}
}
}, null);
}
編輯:這裏是堆棧跟蹤:
05-27 19:09:04.319: E/GAWidget(12487): IOException
05-27 19:09:04.319: E/GAWidget(12487): java.io.IOException
05-27 19:09:04.319: E/GAWidget(12487): at android.accounts.AccountManager.convertErrorToException(AccountManager.java:1440)
05-27 19:09:04.319: E/GAWidget(12487): at android.accounts.AccountManager.access$400(AccountManager.java:138)
05-27 19:09:04.319: E/GAWidget(12487): at android.accounts.AccountManager$AmsTask$Response.onError(AccountManager.java:1301)
05-27 19:09:04.319: E/GAWidget(12487): at android.accounts.IAccountManagerResponse$Stub.onTransact(IAccountManagerResponse.java:69)
05-27 19:09:04.319: E/GAWidget(12487): at android.os.Binder.execTransact(Binder.java:320)
05-27 19:09:04.319: E/GAWidget(12487): at dalvik.system.NativeStart.run(Native Method)
運罐:
google-http-client-1.9.0-beta.jar
google-http-client-android2-1.9.0-beta.jar (only for SDK >= 2.1)
google-http-client-android3-1.9.0-beta.jar (only for SDK >= 3.0)
gson-2.1.jar
guava-11.0.1.jar
jackson-core-asl-1.9.4.jar
jsr305-1.3.9.jar
protobuf-java-2.2.0.jar
順便說一句,這個工作對我的Galaxy Nexus(4.0.4)的罰款,但你似乎有一些奇怪的字符s在你的令牌類型中。可能只是一個複製粘貼錯誤,但重新輸入字符串,並確保它只是爲了以防萬一。 –
感謝您的回覆尼古拉,我試圖刪除URL中的「oauth2:」部分,並且我得到一個空令牌。你能否詳細說明令牌類型中的奇怪字符?我不明白你的意思。關於警告我也得到這個:「GoogleLoginService:狀態200,但響應不包括授權令牌」。任何想法? – balteo
我還有時會收到以下警告:「IInputConnectionWrapper showStatusIcon處於非活動狀態的InputConnection」 – balteo