我正在尝试学习Android Firebase。当我编写Register用户代码时,它成功运行。但是当我打电话给#34; userProfileChangeRequest"方法 更改用户名或个人资料图片uri它已成功运行,但新用户在注销并再次登录之前无法查看该数据。
为什么呢?有什么问题?
这是我的代码:
private void getUriPicture() {
if(uriImage == null){
//user didn't select profile picture
return;
}
else if(!App.isOnline(this)) {
Toast.makeText(this, getResources().getString(R.string.checkInternetConnection), Toast.LENGTH_SHORT).show();
return;
}else{
mStorage = FirebaseStorage.getInstance().getReference();
//upload picture to get Path
Log.e(TAG,"test3");
StorageReference path = mStorage.child("ProfilePicture").child(uriImage.getLastPathSegment()
+ "_"
+ App.randomNumber()
+ "_"
+ App.randomNumber());
Log.e(TAG,"test4"+path);
path.putFile(uriImage).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Log.e(TAG,"Upload success");
@SuppressWarnings("VisibleForTests") Uri downloadUrl= taskSnapshot.getDownloadUrl();
//Preview profile picture before set it to user
Picasso.with(Setting.this).load(downloadUrl).into(profilePicture);
setUserProfilePicture(downloadUrl);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
TF=false;
Toast.makeText(Setting.this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
private void setUserProfilePicture(Uri downloadUrl) {
//mProgress.setMessage(getResources().getString(R.string.updateProfile));
FirebaseUser user = mAuth.getCurrentUser();
if(user != null) {
Log.e(TAG,"test6");
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setPhotoUri(downloadUrl)
.build();
user.updateProfile(profileUpdates)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.e(TAG, "Update Profile Successful");
Toast.makeText(Setting.this, getResources().getString(R.string.updateSuccessful), Toast.LENGTH_SHORT).show();
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "Update Failure");
Toast.makeText(Setting.this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
});
}
}
答案 0 :(得分:0)
也许您可以尝试在onCompleteListener中的UI中更新用户图像?由于在UserProfileChangeRequest之后没有完成视图更新操作。