我正在尝试在Firebase中注册某个应用,但它一直在说不成功。
这是我的代码。
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
private EditText etEmail;
private EditText etPassword;
private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
firebaseAuth = FirebaseAuth.getInstance();
if (firebaseAuth.getCurrentUser() != null){
//Start profile activity here.
finish();
startActivity(new Intent(getApplicationContext(), HomeActivity.class));
}
progressDialog = new ProgressDialog(this);
etEmail = (EditText) findViewById(R.id.editTextEmail);
etPassword = (EditText) findViewById(R.id.editTextPassword);
Button btnRegister = (Button) findViewById(R.id.buttonRegister);
assert btnRegister != null;
btnRegister.setOnClickListener(this);
}
@Override
public void onClick(View v) {
registerUser();
}
private void registerUser(){
String email = etEmail.getText().toString().trim();
String password = etPassword.getText().toString().trim();
if (TextUtils.isEmpty(email)){
//Email is empty. Create a toast to enter a email.
Toast.makeText(this, "Please enter your email address.", Toast.LENGTH_SHORT).show();
// return to the email field.
return;
}
if (TextUtils.isEmpty(password)){
//Password is empty. Create a toast to enter a password.
Toast.makeText(this, "Please enter your password.", Toast.LENGTH_SHORT).show();
// return to the password field.
return;
}
progressDialog.setMessage("Registration on Process...");
progressDialog.show();
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
//User is successfully registered.
Toast.makeText(RegisterActivity.this, "Registration is successful.", Toast.LENGTH_SHORT).show();
//Log in and User will start profile activity.
finish();
startActivity(new Intent(getApplicationContext(), HomeActivity.class));
}else{
progressDialog.dismiss();
Toast.makeText(RegisterActivity.this, "Registration failed. Please try again.", Toast.LENGTH_SHORT).show();
}
}
});
}
}
我尝试使用电子邮件登录活动,我在FirebaseAuth中手动创建并且成功了。但注册活动经常不成功。 我无法在代码中发现任何错误。你能帮帮我吗?