gpt4 book ai didi

java - 如何在我的编码 android studio 项目中实现此代码 setDisplayName?

转载 作者:行者123 更新时间:2023-11-29 22:53:13 30 4
gpt4 key购买 nike

我想将我的 setDisplayName() 实现到我的代码中,但不确定如何去做。我应该将 setDisplayName 放在我的代码中的什么位置?我想在我的导航栏标题中显示客户名称。

这是我的代码

//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));
}
});
}
}
});

这是我找到的代码,但不确定如何在我的代码中实现它。

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.");
}
}
});
}
});
}

这是我的客户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;
}
}

最佳答案

代码流程如下:

  1. 用户使用电子邮件和密码注册。
  2. 然后使用 FirebaseAuth 设置用户显示名称 UserProfileChangeRequest
  3. 成功完成后。您的数据将保存在数据库中

    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));
    }
    });
    }
    }
    });
    }
    });
    }

关于java - 如何在我的编码 android studio 项目中实现此代码 setDisplayName?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57707607/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com