gpt4 book ai didi

Android - 使用什么代替 AccountPicker.newChooseAccountIntent 因为它已被弃用

转载 作者:太空狗 更新时间:2023-10-29 14:48:05 33 4
gpt4 key购买 nike

我正在做一个项目,我必须显示帐户选择器,以便用户可以选择存储在他的设备中的电子邮件帐户。问题是我有 AccountPicker.newChooseAccountIntent 已弃用。

Is there any alternate way to show the account chooser instead of getting the email manually, and showing it in a custom view

现在我正在使用:

Intent googlePicker = AccountPicker.newChooseAccountIntent(null, null,
new String[] { GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE }, true, null, null, null, null);
startActivityForResult(googlePicker, PICK_ACCOUNT_REQUEST);

最佳答案

也许它会对某人有所帮助,在 2020 年根据 docs 使用它:

Intent intent =
AccountPicker.newChooseAccountIntent(
new AccountChooserOptions.Builder()
.setAllowableAccountsTypes(Arrays.asList("com.google"))
.build());

startActivityForResult(intent, SOME_REQUEST_CODE);

您也可以使用 AccountManager :

Intent intent;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
intent = AccountManager.newChooseAccountIntent(null, null,
new String[] { GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE }, null, null, null, null);
} else {
intent = AccountManager.newChooseAccountIntent(null, null,
new String[] { GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE }, false, null, null, null, null);
}

startActivityForResult(intent, SOME_REQUEST_CODE);

您可以从 authAccount 额外获取选定的电子邮件:

protected void onActivityResult(final int requestCode, final int resultCode,
final Intent data) {
if (requestCode == REQUEST_CODE_EMAIL && resultCode == RESULT_OK) {
String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
// Do what you need with email
}
super.onActivityResult(requestCode, resultCode, data);
}

关于Android - 使用什么代替 AccountPicker.newChooseAccountIntent 因为它已被弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37722544/

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