我需要触发toast说具有相同电子邮件的用户已经注册。在注册时出现问题时,在我的代码Toast触发器中。例如密码太短。但是,当用户尝试使用已经采用的电子邮件进行注册时,他并不知道这一点。请帮帮我,告诉我该如何编辑我的代码?
private void registerUser(){
String email = editTextemail.getText().toString().trim();
String password = editTextpassword.getText().toString().trim();
if(TextUtils.isEmpty(email)){
Toast.makeText(this, "Enter email ", Toast.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(password)){
Toast.makeText(this, "enter password", Toast.LENGTH_SHORT).show();
return;
}
progressDialog.setMessage("please wait...");
progressDialog.show();
firebaseAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
progressDialog.dismiss();
Toast.makeText(MainActivity.this, "registration complete", Toast.LENGTH_SHORT).show();
}else{
progressDialog.dismiss();
Toast.makeText(MainActivity.this, "Email is invalid or password contains less than 6 symbols", Toast.LENGTH_SHORT).show();
}
}
});
}
答案 0 :(得分:0)
在其他人之后编辑您的代码:
progressDialog.dismiss();
String message = "The email address is already in use by another account."
if (task.getException().getMessage().equals(message))
Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
else
Toast.makeText(MainActivity.this, "Email is invalid or password contains less than 6 symbols", Toast.LENGTH_SHORT).show();