firebaseAuth.getCurrentUser() return null DisplayName

前端 未结 9 1867
[愿得一人]
[愿得一人] 2020-12-09 05:24

When I signIn with my google account and get the name with the getDisplayName(), my name appear correctly, but in the AuthStateListener doesn\'t.

here part of my cod

9条回答
  •  粉色の甜心
    2020-12-09 05:45

    I found a solution for this problem, in the Firebase documentation! The solution is to update the user profile using the: UserProfileChangeRequest:

    UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
                          .setDisplayName(mUser.getName())
                          .setPhotoUri(Uri.parse("https://example.com/mario-h-user/profile.jpg"))
                          .build();
    
                firebaseUser.updateProfile(profileUpdates)
                          .addOnCompleteListener(new OnCompleteListener() {
                              @Override
                              public void onComplete(@NonNull Task task) {
                                  if (task.isSuccessful()) {
                                      Log.d(TAG, "User profile updated.");
                                  }
                              }
                          });
    

    The variable mUser is already filled with the content from the fields. I used this piece of code inside the FirebaseAuth.AuthStateListener() -> onAuthStateChanged()

提交回复
热议问题