无法在firebase android中更新用户配置文件

无法在firebase android中更新用户配置文件,firebase,firebase-authentication,user-profile,Firebase,Firebase Authentication,User Profile,我试图更新我的用户配置文件(特别是照片),方法是让choosepicker从我的图库中选择图像并将其上载到我的firebase认证存储。它几乎工作正常:图片被上传到我描述的路径 问题是我无法按我的意愿取回它。我想更新用户配置文件pic并使用UpdateProfileRequest但它没有更新任何内容,也无法检索任何内容 代码如下: final ImageView photo = (ImageView) findViewById(R.id.photoURI); if (photo

我试图更新我的用户配置文件(特别是照片),方法是让choosepicker从我的图库中选择图像并将其上载到我的firebase认证存储。它几乎工作正常:图片被上传到我描述的路径

问题是我无法按我的意愿取回它。我想更新用户配置文件pic并使用
UpdateProfileRequest
但它没有更新任何内容,也无法检索任何内容

代码如下:

final ImageView photo = (ImageView) findViewById(R.id.photoURI);

        if (photoUri == null) {
            photo.setImageResource(R.drawable.user);
            Toast.makeText(LoginActivity.this,"DP is Empty",Toast.LENGTH_SHORT).show();
        } else {
            photo.setImageURI(photoUri);
        }

        Button editPhoto = (Button) findViewById(R.id.edit_photo);
        editPhoto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("image/jpeg");
                intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
                startActivityForResult(Intent.createChooser(intent, "Complete action using"), RC_PHOTO_PICKER);
            }
        });
这是我的活动结果代码

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK) {
        final Uri selectedImageUri = data.getData();

        // Get a reference to store file at User_photos/<FILENAME>
        StorageReference photoRef = storageReference.child(userID).child(selectedImageUri.getLastPathSegment());

        // Upload file to firebase Storage
        photoRef.putFile(selectedImageUri).addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                Uri downloadUrl = taskSnapshot.getDownloadUrl();
                String imageUrl = downloadUrl.toString();
                User user = new User(imageUrl);
                databaseReferencenew.child(userID).child("Profile_Pic_URL").setValue(user);
                FirebaseUser user2 = FirebaseAuth.getInstance().getCurrentUser();
                UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
                        .setDisplayName(mName)
                        .setPhotoUri(selectedImageUri)
                        .build();

                user2.updateProfile(profileUpdates).addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        Log.d(TAG, "User profile updated.");
                        Toast.makeText(LoginActivity.this,"User profile updated.",Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });
    }
}
@覆盖
ActivityResult上的公共void(int请求代码、int结果代码、意图数据){
super.onActivityResult(请求代码、结果代码、数据);
if(requestCode==RC\u PHOTO\u PICKER&&resultCode==RESULT\u OK){
最终Uri selectedImageUri=data.getData();
//获取在用户处存储文件的引用/
StorageReference photoRef=StorageReference.child(userID).child(selectedImageUri.getLastPathSegment());
//将文件上载到firebase存储
photoRef.putFile(selectedImageUri).addOnSuccessListener(这是新的OnSuccessListener()){
@凌驾
成功时公共无效(UploadTask.TaskSnapshot TaskSnapshot){
Uri downloadUrl=taskSnapshot.getDownloadUrl();
字符串imageUrl=downloadUrl.toString();
用户用户=新用户(imageUrl);
databaseReferencenew.child(userID).child(“Profile\u Pic\u URL”).setValue(user);
FirebaseUser user2=FirebaseAuth.getInstance().getCurrentUser();
UserProfileChangeRequest profileUpdates=新建UserProfileChangeRequest.Builder()
.setDisplayName(mName)
.setPhotoUri(selectedImageUri)
.build();
user2.updateProfile(profileUpdates).addOnCompleteListener(新的OnCompleteListener(){
@凌驾
未完成的公共void(@NonNull任务){
Log.d(标签“用户配置文件更新”);
Toast.makeText(LoginActivity.this,“用户配置文件更新”,Toast.LENGTH_SHORT.show();
}
});
}
});
}
}

如果您记录selectedImageUri的字符串值会显示什么?我是android新手,不知道如何记录值。请告诉我这将是grwt帮助。另外,我不知道是怎么回事,但代码第二天开始工作,当我注销帐户并使用新帐户登录时。现在唯一剩下的问题是,当我从旧帐户更新新帐户时,图片不会立即显示在图像视图中。它在我注销并再次登录后显示。如果您记录selectedImageUri的字符串值,它会显示什么?我是新手android我不知道如何记录值,请告诉我这将是一个grwt帮助。我也不知道,但代码第二天开始工作,当我注销帐户并使用新帐户登录时。现在唯一的问题是,当我从旧帐户更新新帐户时,图片没有立即显示在图像视图中。在我注销并再次登录后,它会显示出来。