简体   繁体   English

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

[英]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 :代码流程如下:

  1. User Register with Email and password.用户注册电子邮件和密码。
  2. Then you set User display name UserProfileChangeRequest with FirebaseAuth.然后您使用 FirebaseAuth 设置用户显示名称UserProfileChangeRequest
  3. 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.

相关问题 如何在我的 Android Studio 项目中实现库的固定版本? - How to implement fixed version of library to my Android studio project? 我在 android studio 中编码,我需要使用 Http url 连接而不是 httpclient。 我如何转换我的代码? - I am coding in android studio and I need to use Http url connection instead of httpclient. How do i convert my code? 如何将Maven导入我的Android Studio项目? - How to import maven into my Android Studio project? 如何将Jsoup添加到我的Android Studio项目中? - How to add Jsoup to my Android Studio project? 如何在Android Studio上为我的项目添加库? - How to add a library to my project on Android Studio? 如何使用我以前的应用程序中的所有代码启动一个新的Android Studio项目? - How to start a new Android Studio project with all the code from my previous app? 如何在新项目中实现文本到语音的代码? - How do i implement the text to speech code in my new project? 如何在我的 Android 项目中实现 anychart? - How do I implement anychart into my Android project? 如何在Android Studio中更改我已弃用的​​代码 - How to change my depreated code in Android Studio 如何在我的项目中实现 opencyc? - How to implement opencyc into my project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM