【发布时间】:2019-05-18 12:00:07
【问题描述】:
我已经使用 createUserWithEmailAndPassword 方法注册了用户,并且他们已在我的 firebase 项目中注册(我可以看到他们的信息)。但是当我尝试使用创建的电子邮件和密码登录时,task.isSuccessful 方法总是返回 false,并且每次都在运行 else 语句。
登录和注册代码:
private Button buttonRegister;
private EditText editTextEmail;
private EditText editTextPassword;
private TextView textViewSignin;
private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressDialog=new ProgressDialog(this);
firebaseAuth= FirebaseAuth.getInstance();
buttonRegister = (Button) findViewById(R.id.buttonRegister);
editTextEmail=(EditText) findViewById(R.id.editTextEmail);
editTextPassword=(EditText) findViewById(R.id.editTextPassword);
textViewSignin=(TextView) findViewById(R.id.textViewSignin);
buttonRegister.setOnClickListener(this);
textViewSignin.setOnClickListener(this);
if(firebaseAuth.getCurrentUser()!=null){
//start the profile activity
finish();
startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
}
}
private void registerUser(){
String email=editTextEmail.getText().toString().trim();
String password=editTextEmail.getText().toString().trim();
if(TextUtils.isEmpty(email)){
Toast.makeText(this, "Please enter E-mail first", Toast.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(password)){
Toast.makeText(this, "Please enter password first", Toast.LENGTH_SHORT).show();
return;
}
progressDialog.setMessage("Registerring User......");
progressDialog.show();
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
progressDialog.dismiss();
if(task.isSuccessful()){
finish();
startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
}
else{
Toast.makeText(MainActivity.this, "Unable to Register! Please try again.", Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
public void onClick(View v) {
if(v == buttonRegister){
registerUser();
}
if(v == textViewSignin){
finish();
startActivity(new Intent(this, LoginActivity.class));
}
}
【问题讨论】:
标签: android android-studio firebase-authentication