1
我正在使用Firebase的自定義身份驗證。Firebase setDisplayName無效
我想設置一個用戶與用戶名:
UserProfileChangeRequest userProfileChangeRequest = new UserProfileChangeRequest.Builder()
.setDisplayName("Hello")
.build();
assert currentUser != null;
currentUser.updateProfile(userProfileChangeRequest).addOnCompleteListener(new OnCompleteListener<Void>() {
@SuppressWarnings("ConstantConditions")
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()){
Toast.makeText(UsernameAndProfilePictureChooserActivity.this, "Success. Username: " + getUsername(), Toast.LENGTH_SHORT).show();
}
else {
throw new Error(task.getException().getMessage(),task.getException().getCause());
}
}
});
但它沒有任何效果。
敬酒消息(Toast.makeText(UsernameAndProfilePictureChooserActivity.this, "Success. Username: " + getUsername(), Toast.LENGTH_SHORT).show();
被調用,但getUsername(),這是FirebaseAuth.getInstance().getCurrentUser().getDisplayName()
返回null。
關閉應用程序,然後重新打開它不起作用。
這究竟是爲什麼?
Firebase中存在一個錯誤,請關閉應用程序並重新打開它。它工作正常 –
@MuhammadFarrukhFaizy nope。它不適合我。 –
剛剛嘗試過您的代碼,它適用於我。我正在使用'com.google.firebase:firebase-auth:10.2.0'。我會說檢查你的'currentUser'對象和''getUsername()'方法。 – Distwo