gpt4 book ai didi

java - 如何检测用户取消 AccountPicker 对话框 Android Eclipse

转载 作者:行者123 更新时间:2023-11-29 05:20:51 24 4
gpt4 key购买 nike

我想通过 AccountPicker.newChooseAccountIntent 获取用户电子邮件 ID。我想要检测用户取消 AccountPicker 对话框

这是代码

     private static final int REQUEST_CODE_EMAIL = 1;
private TextView email = (TextView) findViewById(R.id.email);



try {
Intent intent = AccountPicker.newChooseAccountIntent(null, null,
new String[] { GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE }, false, null, null, null, null);
startActivityForResult(intent, REQUEST_CODE_EMAIL);
} catch (ActivityNotFoundException e) {
// TODO
}



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_EMAIL && resultCode == RESULT_OK) {
String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
email.setText(accountName);
}
}

最佳答案

Activity 中还有一个RESULT_CANCELEDRESULT_CANCEL 常量。

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_EMAIL && resultCode == RESULT_OK) {
String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
email.setText(accountName);
} else if(requestCode == REQUEST_CODE_EMAIL && resultCode == RESULT_CANCELED) {
Toast.makeText(getApplicationContext(), "error", Toast.LENGTH_SHORT).show();
}
}

关于java - 如何检测用户取消 AccountPicker 对话框 Android Eclipse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24844624/

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