Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
820 views
in Technique[技术] by (71.8m points)

android - Change DisplayName in Firebase

I am using email registration Firebase. As of now their is no option to set DisplayName in Firebase. So I am redirecting users to a class where they can change DisplayName soon after signing up through email and password.

My problem is I am unable to achieve that. Here's what I have done so far:

public class UsernameActivity extends AppCompatActivity {
private FirebaseAuth.AuthStateListener authListener;
private FirebaseAuth auth;
private EditText mName;
private TextView btnSignUp;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_username);
    //get firebase auth instance
    auth = FirebaseAuth.getInstance();
    mName = (EditText) findViewById(R.id.name);

    btnSignUp = (TextView) findViewById(R.id.sign_up_button);
    final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    btnSignUp.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            auth = new FirebaseAuth.AuthStateListener() {
                @Override
                public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                    FirebaseUser user = firebaseAuth.getCurrentUser();
                }

                if(user!=null)

                {
                    UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
                            .setDisplayName(mName)
                            .build();
                    user.updateProfile(profileUpdates);
                    Intent intent = new Intent(UsernameActivity.this, JokeActivity.class);
                    startActivity(intent);
                }
            };
        }
    });
}}

Below is the image of what I want to achieve.

EditText

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...