【发布时间】:2014-10-22 22:20:20
【问题描述】:
您好,我在拨打电话时无法恢复我的 authToken
mAccountManager.blockingGetAuthToken(Auth.getAccount(), Auth.AUTH_TOKEN_TYPE, true)
我得到一个空字符串,这导致我查看我的 AbstractAccountAuthenticator 类,特别是 getAuth()。它的作用如下:
public Bundle getAuthToken(AccountAuthenticatorResponse response,
Account account, String authTokenType, Bundle options)
throws NetworkErrorException {
final AccountManager am = AccountManager.get(mContext);
String authToken = am.peekAuthToken(account, authTokenType);
String uid = am.getUserData(account, AccountManager.KEY_CALLER_UID);
// return bundle with authToken
if (!TextUtils.isEmpty(authToken)) {
final Bundle result = new Bundle();
result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
result.putString(AccountManager.KEY_CALLER_UID, uid);
return result;
}
return null;
}
peekAuthToken 返回一个空值,但是我从 getUserData 获得了正确的 uid,这让我相信我正在正确添加帐户。这就是我设置 authToken 的方式:
mAccountManager.addAccountExplicitly(account, accountPassword, extraData);
//The addAccount is working, and I can obtain the extraData in getAuth
mAccountManager.setAuthToken(account, Auth.AUTH_TOKEN_TYPE, authtoken);
//I assume this is where the authToken is to be cached…but I can't retrieve it…
//The token does exist at this point
有什么建议吗?
【问题讨论】:
-
你确定传入的account变量和你调用setAuthToken时的那个一样吗?
-
我相信,Auth.getAccount() 返回 AccountManager.get(App.getContext()).getAccountsByType(ACCOUNT_TYPE)[0];它正确地保存了有关帐户的信息
-
我无法通过查看此代码片段来弄清楚发生了什么。但是您可以查看此链接以了解 accountmanager 的完整报道。 udinic.wordpress.com/2013/04/24/…
标签: android auth-token