Jon*_*ate 5 android xamarin.android accountmanager android-account
我的应用只存储用户/通行证.没有使用令牌.
方法setAccountAuthenticatorResult(Bundle)和onResult(Bundle)意图是通知AbstractAccountAuthenticator结果,但我有一个没有它们的项目,它们有什么用?
什么时候addAccount完成并创建帐户,应该onActivityResult在Activity触发它的时候调用它?
如果在实现中Intent返回带有键AccountManager.KEY_INTENT的a addAccount,AbstractAccountAuthenticator则将启动Intent.我注意到许多开发人员添加额外内容.谁得到了他们?
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException
{
Intent intent = new Intent(mContext, AuthenticatorActivity.class);
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
intent.putExtra(AuthenticatorActivity.ARG_ACCOUNT_TYPE, accountType); // <-- this
intent.putExtra(AuthenticatorActivity.ARG_AUTH_TYPE, authTokenType); // <-- this
intent.putExtra(AuthenticatorActivity.ARG_IS_ADDING_NEW_ACCOUNT, true); // <-- this
Bundle bundle = new Bundle();
bundle.putParcelable(AccountManager.KEY_INTENT, intent);
return bundle;
}
Run Code Online (Sandbox Code Playgroud)
克里斯拉森:
谢谢你的回答.我认为我们可能会使用AccountManager错误来说实话.
我们希望在我们的应用中共享一些凭据,因此我们可以Service保留自定义帐户类型.由于应用知道帐户类型并共享签名证书,因此他们可以访问Account.
当每个应用程序启动时,他们会尝试获取Account.如果不Account存在,则Service通过调用触发我们的登录页面AccountManager.addAccount(...).
一旦登录(通过Web服务)成功,我们就可以将其提供给其他应用程序AccountManager.addAccountExplicitly(...).不在其后设定结果,不会影响结果.
它是如何影响的AccountManager?这种方法是否正确?
方法 setAccountAuthenticatorResult(Bundle) 和 onResult(Bundle) 旨在通知 AbstractAccountAuthenticator 有关结果,但我有一个项目没有它们,它们有什么用?
这些方法(以及onError)是将结果传递回任何可能等待结果的人,例如,查看一下AccountManager.getAuthToken(...)以及许多其他允许您指定AccountManagerCallback<Bundle>. 这是您的结果将被传递到的地方。null对于回调有效,因此除非您围绕结果构建应用程序,否则它将在没有它的情况下运行。
AccountAuthenticatorResponse.onResult(Bundle)如果您实现了从异步后端调用(例如令牌刷新)返回访问令牌的方式,则onError(...)更为重要。getAuthToken
onRequestContinued() 的用途是什么?
可用的信息非常少(读作:无)。我能找到的唯一一次使用它的地方是AccountManagerService它的位置,但它是一个为了记录目的而增加的计数器。我认为目前它没有任何作用。
当 addAccount 完成并创建帐户后,是否应该在触发它的 Activity 上调用 onActivityResult ?
只要你使用就应该有效startActivityForResult(..)
如果在 addAccount 实现中返回带有 AccountManager.KEY_INTENT 键的 Intent,则 AbstractAccountAuthenticator 将启动该 Intent。我注意到许多开发人员添加了额外的功能。谁得到它们?
正如 kris 已经提到的,您可以返回启动 Activity 的 Intent 并传递您可能需要的任何额外内容。
一个不相关的说明:您真的应该尽量不要以纯文本形式存储任何密码。即使 AccountManager 说它setPassword()不受保护,因此不安全。
| 归档时间: |
|
| 查看次数: |
617 次 |
| 最近记录: |