gpt4 book ai didi

android - 通过代码添加谷歌账户

转载 作者:太空狗 更新时间:2023-10-29 14:26:55 24 4
gpt4 key购买 nike

如何通过代码添加 Google 帐户?

我只需要添加一个现有帐户,而不是创建一个新帐户。交互过程类似于设置>帐户>添加帐户

谢谢!

最佳答案

您必须设计出您的用户界面,但添加现有帐户的最简单代码如下所示:

AccountMager mgr = (AccountManager)getSystemService(ACCOUNT_SERVICE);
Account acc = new Account("user@domain.com", "com.google"));
if(mgr.addAccountExplicitly(acc, "password", new Bundle())) {
//account added successfully
//do whatever is needed;
}
else {
//something did not work
}

您需要AUTHENTICATE_ACCOUNTS 权限。如果您传递 null 代替密码,则将添加没有密码的帐户,并在下次重新同步时提示用户输入密码。

如果你需要对过程有更多的控制,那么你可以使用方法

public AccountManagerFuture<Bundle> addAccount (String accountType,
String authTokenType,
String[] requiredFeatures,
Bundle addAccountOptions,
Activity activity,
AccountManagerCallback<Bundle> callback,
Handler handler)

在类 AccountManager 中。看看 AccountManager class documentation了解更多详情。

关于android - 通过代码添加谷歌账户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11466377/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com