gpt4 book ai didi

android - 检查帐户是否已在 AccountManager 中注册

转载 作者:行者123 更新时间:2023-12-02 12:15:56 26 4
gpt4 key购买 nike

我正在尝试确定用户是否已添加该帐户,以防止在我的应用程序上多次添加同一帐户。我正在使用我自己的帐户验证器 Activity 。这是我的代码:

public class AuthenticatorActivity extends AccountAuthenticatorActivity {



private AccountManager mAccountManager;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setup_mail_dialog);
mAccountManager = AccountManager.get(getBaseContext());


findViewById(R.id.bSetupConfirm).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
checkAccount();

}
});

}


private void checkAccount() {
mAccountManager = AccountManager.get(getBaseContext());
String accountName = ((EditText) findViewById(R.id.etSetupEmail)).getText().toString().trim();
Account[] accounts = mAccountManager.getAccountsByType(getResources().getString(R.string.account_type));
for(Account account : accounts) {
if(account.name == accountName) {
System.out.println("Account exists");
return;
}else{
System.out.println("Account do not exists");
return;
}
}

}

但是,即使帐户存在,应用程序也始终显示“帐户不存在”。

最佳答案

通过引用,您必须将其与等号进行比较。

解决方案:

 if(account.name.equals(accountName))

关于android - 检查帐户是否已在 AccountManager 中注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32030499/

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