AccountManager を使用して、インストールされている Google アカウントのトークンを取得しようとしています。AccountManagerFuture オブジェクトで getResult() を呼び出すと、デバイスに「サインインできませんでした」という画面が表示されます (さらに、「Google サーバーとの通信中に問題が発生しました。後でもう一度試してください。)」と表示されます。このメソッドを呼び出す前に、ネットワーク接続が利用可能であることを確認しました. また、ブラウザで google.com など、アクセスできるデバイスを確認しました. これが私の AccountManagerCallback のコードです:
amf = accMgr.getAuthToken(account, authTokenType, null, true,
new AccountManagerCallback<Bundle>() {
public void run(AccountManagerFuture<Bundle> arg0) {
Bundle result;
Intent i;
String token;
try {
result = arg0.getResult();
if (result.containsKey(AccountManager.KEY_INTENT)) {
i = (Intent)result.get(AccountManager.KEY_INTENT);
if (i.toString().contains("GrantCredentialsPermissionActivity")) {
// Will have to wait for the user to accept
// the request therefore this will have to
// run in a foreground application
cbt.startActivity(i);
} else {
cbt.startActivity(i);
}
token = (String)result.get(AccountManager.KEY_AUTHTOKEN);
} else {
token = (String)result.get(AccountManager.KEY_AUTHTOKEN);
}
} catch (OperationCanceledException e) {
e.printStackTrace();
} catch (AuthenticatorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}, handler);
また、LogCat の次のエントリが役立つ場合があります。
08-02 15:51:00.911: I/GLSUser(10134): GLS error: Unknown XXXX@gmail.com com.google
08-02 15:51:00.911: V/GoogleLoginService(10134): Returning error intent with: ComponentInfo{com.google.android.gsf.login/com.google.android.gsf.login.LoginActivity}
08-02 15:51:03.294: I/ActivityManager(324): START {cat=[XXXX@gmail.com] flg=0x10000000 cmp=com.google.android.gsf.login/.LoginActivity (has extras) u=0} from pid 11147
(注: スパムを避けるため、実際の Gmail アカウント名は削除されています。)