Accountmanager.addAccount()vs Accountmanager.addAccountExplicitly()

问题描述 投票:8回答:2

当我们使用Accountmanager.addAccount()创建所有参数的帐户时,为什么我们使用Accountmanager.addAccountExplicitly()

我用谷歌搜索并发现当我们使用qazxsw poi时,它琐事qazxsw poi qazxsw poi事件,但有什么意义呢?为什么我们应该使用addAccount方法?

更新

我们可以这样创建帐户:

Accountmanager.addAccount()
android account accountmanager
2个回答
10
投票

经过多次尝试,我终于找到了!

Accountmanager.addAccount()和Accountmanager.addAccountExplicitly()是非常不同的方法!

当你调用Accountmanager.addAccount()时,它调用一个相同的方法,在你的AbstractAccountAuthenticator中你可以处理发生的事情。另一方面,当用户转到手机设置/帐户并选择您的自定义帐户类型并按“添加帐户”时,此方法将调用。所以我处理帐户类型和许多东西,并指导用户登录/单一页面。

AbstractAccountAuthenticator

然后在我的活动中,用户选择创建一个帐户或登录。在唱歌或注册后,用户从服务器获取令牌并完成操作,最后我使用addAccount添加帐户。

 Account account = new Account(accountname, accountType);
 mAccountManager.addAccountExplicitly(account, accountPassword, null);

1
投票

必须使用public class MyAuthenticator extends AbstractAccountAuthenticator { @Override public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException { final Intent intent = new Intent(mContext, DirectLogin.class); intent.putExtra(Constants.ARG_ACCOUNT_TYPE, accountType); intent.putExtra(Constants.ARG_AUTH_TYPE, authTokenType); intent.putExtra(Constants.ARG_IS_ADDING_NEW_ACCOUNT, true); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; } 来要求用户创建某种类型的帐户。用户必须批准设备并与设备交互,以便确实创建帐户。此方法可用于创建任何类型的帐户。

Accountmanager.addAccountExplicitly()允许您在没有用户批准/交互的情况下创建帐户,但它仅限于验证者与您的签名具有相同签名的帐户类型。

© www.soinside.com 2019 - 2024. All rights reserved.