gpt4 book ai didi

Android M 电子邮件完成

转载 作者:太空宇宙 更新时间:2023-11-03 13:53:40 24 4
gpt4 key购买 nike

如您所知,Android M 上的权限系统已更新。

我目前使用 GET_ACCOUNTS 权限在他登录/注册我的应用程序时自动完成用户电子邮件。

final ArrayList<String> emails = new ArrayList<String>();
for (Account account : AccountManager.get(this).getAccounts()) {
emails.add(account.name);
}
email.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, emails));

问题是在 Android M 上,要继续使用此功能,我需要请求用户允许读取他的帐户。这没有意义,因为为了节省用户一点时间,我需要使用烦人的权限请求。

还有另一种无需请求任何许可即可自动完成用户电子邮件的方法吗?

最佳答案

Google Play 服务 8.3 添加了可用于自动填充电子邮件地址的提示信息

http://android-developers.blogspot.co.uk/2015/11/whats-new-in-google-play-services-83.html

And to make signing in easier across devices, whether you use Google Sign-In or still have password-based authentication, the Smart Lock APIs received some important updates. We’ve added a new API method to show a dialog that helps your user select a previously-used email address to pre-fill sign in or up forms easily: check out getHintPicker. This doesn’t require any device permissions and provides an alternative to a picker you may have previously populated from accounts on the device, which would now require a runtime permission with Marshmallow.

https://developers.google.com/identity/smartlock-passwords/android/retrieve-hints

HintRequest hintRequest = new HintRequest.Builder()
.setHintPickerConfig(new CredentialPickerConfig.Builder()
.setShowCancelButton(true)
.build())
.setEmailAddressIdentifierSupported(true)
.build();

PendingIntent intent =
Auth.CredentialsApi.getHintPickerIntent(mCredentialsClient, hintRequest);
try {
startIntentSenderForResult(intent.getIntentSender(), RC_HINT, null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG, "Could not start hint picker Intent", e);
}

系统会提示用户选择要使用的电子邮件地址。

然后,在 Activity 的 onActivityResult() 方法中,从 Credential.EXTRA_KEY 包中检索提示,检查用户是否在您的用户数据库中,并使用凭据提示启动适当的 Activity 。

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == RC_HINT) {
if (resultCode == RESULT_OK) {
Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
Intent intent;
// Check for the user ID in your user database.
if (userDatabaseContains(credential.getId())) {
intent = new Intent(this, SignInActivity.class);
} else {
intent = new Intent(this, SignUpNewUserActivity.class);
}
intent.putExtra("com.mycompany.myapp.SIGNIN_HINTS", credential);
startActivity(intent);
} else {
Log.e(TAG, "Hint Read: NOT OK");
Toast.makeText(this, "Hint Read Failed", Toast.LENGTH_SHORT).show();
}
}

...

}

我已经为我的应用程序测试过它,credential.getId() 包含您可以用来在选择后预填表单字段的电子邮件地址。最后我没有使用它,因为它只提供了使用 Google 帐户的选项,但如果您只想要一个电子邮件地址,它会非常有效!

关于Android M 电子邮件完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32354696/

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