在JellyBean设备上.
我正在关注this以请求oauth2令牌,例如
AccountManager am = AccountManager.get(getActivity());am.invalIDateAuthToken(MY_AUTH_TOKEN_TYPE, null);am.getAuthToken(aGoogleAccount, MY_AUTH_TOKEN_TYPE, null, this, new OnTokenAcquired(), new Handler(new one rror()));
然后按照后面的代码示例进行检查:
private class OnTokenAcquired implements AccountManagerCallback<Bundle> {@OverrIDe public voID run(AccountManagerFuture<Bundle> result) { Bundle bundle = result.getResult(); ... Intent launch = (Intent) bundle.get(AccountManager.KEY_INTENT); if (launch != null) { startActivityForResult(launch, 0); return; } }}
我从未得到过KEY_INTENT.我理解以下内容:
There may be many reasons for the authenticator to return an Intent. It may be the first time the user has logged in to this account. Perhaps the user’s account has expired and they need to log in again, or perhaps their stored credentials are incorrect. Maybe the account requires two-factor authentication or it needs to activate the camera to do a retina scan. It doesn’t really matter what the reason is. If you want a valID token, you’re going to have to fire off the Intent to get it.
但是,getAuthToken始终会导致权限屏幕或登录屏幕出现在代码到达run方法之前,此时令牌有效.我试过了:
>启用2步验证.在运行之前请求帐户登录,因此始终在运行中具有令牌.
>更改服务器上的密码.在运行之前再次请求帐户登录,因此始终在运行中具有令牌.
没有能力尝试视网膜扫描,所以有点不知所措.
编辑1我遇到的问题是可能存在一个我将获得KEY_INTENT的情况,所以我宁愿现在测试这个代码路径,而不是当它在现场时.
提前致谢.
彼得.
解决方法:
有机会在项目上做类似的事情.这与你的代码并不完全相同,我仍然说回调文档有太多’maybes’来确定它应该如何工作,但如果你使用this method传递false为notifyAuthFailure,你会得到一个意图如果您更改密码或启用2FA,请重新登录屏幕.这适用于ClIEntLogin,但应该与OAuth 2类似(不测试).就像是:
// using Calendar ClIEntLogin for simplicityBundle authResult = am.getAuthToken(account, "cl", false, null, null).getResult();if (authResult.containsKey(AccountManager.KEY_INTENT)) { Intent authIntent = authResult.getParcelable(AccountManager.KEY_INTENT); // start activity or show notification}
总结 以上是内存溢出为你收集整理的android – 永远不要从getAuthToken请求获取AccountManager.KEY_INTENT全部内容,希望文章能够帮你解决android – 永远不要从getAuthToken请求获取AccountManager.KEY_INTENT所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)