[英]How to implement this code setDisplayName in my coding android studio project?
i would like to implement my the setDisplayName() into my code but not sure on how to do it.我想将我的 setDisplayName() 实现到我的代码中,但不确定如何去做。 where should i put the setDisplayName inside my code ?
我应该将 setDisplayName 放在我的代码中的什么位置? i want to display the customer name inside my nav bar header.
我想在我的导航栏标题中显示客户名称。
this is my code这是我的代码
//create customer
firebaseAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(RegisterActivity.this, new OnCompleteListener < AuthResult > () {
@Override
public void onComplete(@NonNull Task < AuthResult > 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));
}
});
}
}
});
and this is code that i found but in not sure on how to implement this inside my code.这是我找到的代码,但不确定如何在我的代码中实现它。
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(mName).build();
user.updateProfile(profileUpdates)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "User profile updated.");
}
}
});
}
});
}
this is my Customer java class这是我的客户 java 类
package com.example.gerobokgo;
public class Customer {
public String name,email,home_address,telephone_number,gender;
public Customer(){
}
public Customer(String name, String email, String home_address, String telephone_number, String gender) {
this.name = name;
this.email = email;
this.home_address = home_address;
this.telephone_number = telephone_number;
this.gender = gender;
}
}
The code flow will be following :代码流程如下:
UserProfileChangeRequest
with FirebaseAuth.UserProfileChangeRequest
。 After it successfully complete.顺利完成后。 Your data will be save in Database
您的数据将保存在数据库中
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)); } }); } } }); } }); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.