不显示DisplayName firebase Android?

时间:2018-01-29 10:36:53

标签: android firebase firebase-authentication

一切正常但不仅仅显示名称。

enter image description here

我的代码是:

user = profAuth.getCurrentUser();
    if (user != null) {

        // Name, email address
        String uid = user.getUid();
        String name = user.getDisplayName();
        String email = user.getEmail();
        txtName.setText(name);
        txtEmail.setText(email);
        txtUserid.setText(uid);
    }

1 个答案:

答案 0 :(得分:1)

这是因为Firebase Auth在注册电子邮件/密码时没有提示用户提供显示名称。但你可以do that manually。提示用户输入他想要的显示名称,然后将其传递给setDisplayName()方法:

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
        .setDisplayName(desiredName)
        .build();

user.updateProfile(profileUpdates)
        .addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                if (task.isSuccessful()) {
                    Log.d(TAG, "User display name updated.");
                }
            }
        });