1 回答
TA贡献1878条经验 获得超4个赞
代码流程如下:
用户使用电子邮件和密码注册。
然后使用 FirebaseAuth 设置用户显示名称
UserProfileChangeRequest
。顺利完成后。您的数据将保存在数据库中
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
// Sign in is successful
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName(name).build();
user.updateProfile(profileUpdates)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Customer info = new Customer(name, email, address, number, gender);
FirebaseDatabase.getInstance().getReference("Customer")
.child(Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid())
.setValue(info).addOnCompleteListener(new OnCompleteListener < Void > () {
@Override
public void onComplete(@NonNull Task < Void > task) {
regProgressBar.setVisibility(View.VISIBLE);
Toast.makeText(RegisterActivity.this, "Registration Complete", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(), Home.class));
}
});
}
}
});
}
});
}
添加回答
举报