我知道如何使用firebase创建电子邮件和密码身份验证,但这只会创建电子邮件和ID,但如何为该ID添加名称和更多详细信息,例如我如何调用user.getdisplayname?
以下是我创建身份验证电子邮件和密码的代码
bv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final ProgressDialog pros=ProgressDialog.show(Register.this,"please wait..","registerring..",true);
mAuth.createUserWithEmailAndPassword(email.getText().toString(),password.getText().toString()).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
pros.dismiss();
if(task.isSuccessful()){
Toast.makeText(Register.this,"sucsseful",Toast.LENGTH_LONG).show();
Intent i=new Intent(Register.this,login.class);
}else {
Log.e("ERROr",task.getException().toString());
Toast.makeText(Register.this,task.getException().getMessage(),Toast.LENGTH_LONG).show();
}
}
});
如果您说创建数据库,那么我如何将其链接到用户身份验证?
private FirebaseUser UserDetaill = FirebaseAuth.getInstance().getCurrentUser() ;
答案 0 :(得分:2)
您可以像这样使用UserProfileChangeRequest
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName("XXX YYYY")
.setPhotoUri(URI)
.build();
UserDetaill.updateProfile(profileUpdates);
使用任务
FirebaseAuth.getInstance().createUserWithEmailAndPassword(email, password)
.continueWithTask(new Continuation<AuthResult, Task<? extends Object>>() {
@Override
public Task<? extends Object> then(@NonNull Task<AuthResult> task) throws Exception {
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName("XXX YYYY")
.setPhotoUri(URI)
.build();
return task.getResult().getUser().updateProfile(profileUpdates);
}
});