创建用户时出现Android Firebase错误

时间:2018-05-24 18:27:40

标签: java android firebase firebase-authentication

我正在尝试制作Firebase聊天应用程序,但我无法找到在创建用户时出现错误的原因。在Firebase控制台中,登录方法已在电子邮件/密码上启用。

我试过了:

- 从Firebase控制台引入用户

- 引入合法凭证,因此我不会提出无效密码,用户名,电子邮件错误

- 我尝试使用Android Assistant Firebase提供的代码,同样的错误给了我

有人指出我可能错了吗?

public class RegisterActivity extends AppCompatActivity {

private TextInputLayout mDisplayName;
private TextInputLayout mEmail;
private TextInputLayout mPassword;
private Button mCreateBtn;
private FirebaseAuth mAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    mAuth = FirebaseAuth.getInstance();

    mDisplayName = (TextInputLayout) findViewById(R.id.reg_display_name);
    mEmail = (TextInputLayout) findViewById(R.id.reg_email);
    mPassword = (TextInputLayout) findViewById(R.id.reg_password);
    mCreateBtn = (Button) findViewById(R.id.reg_create_btn);

    mCreateBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            String display_name = mDisplayName.getEditText().getText().toString();
            String email = mEmail.getEditText().getText().toString();
            String password = mPassword.getEditText().getText().toString();


                register_user(display_name, email, password);
        }
    });
}

private void register_user(String display_name, String email, String password) {

    mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {

           if(task.isSuccessful()){
                Intent mainIntent = new Intent(RegisterActivity.this, MainActivity.class);
                startActivity(mainIntent);
                finish();
           }
           else {
               Toast.makeText(RegisterActivity.this, "You got some error with creating the new user.", Toast.LENGTH_LONG).show();
           }
        }
    });
}

}

1 个答案:

答案 0 :(得分:0)

auth.createUserWithEmailAndPassword(email, password)
  .addOnCompleteListener(RegisterActivity.this, new OnCompleteListener<AuthResult>() {
    @Override
    public void onComplete(@NonNull Task<AuthResult> task) {
        Toast.makeText(SignupActivity.this, "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
        if (!task.isSuccessful()) {
            Toast.makeText(SignupActivity.this, "Authentication failed." + task.getException(), Toast.LENGTH_SHORT).show();
        } else {
            startActivity(new Intent(SignupActivity.this, MainActivity.class));
            finish();
        }
    }
});

尝试这个我认为你已经忘记addOnCompleteListener(Executor executor, OnCompleteListener listener),Executor确定将用于调用监听器的线程。