Java 将用户图像从云存储检索到Imageview中

Java 将用户图像从云存储检索到Imageview中,java,android,firebase,google-cloud-firestore,google-cloud-storage,Java,Android,Firebase,Google Cloud Firestore,Google Cloud Storage,我正在使用java开发一个android应用程序,我正在使用CloudFireStore和firebase存储来存储用户的个人资料图片。 当用户登录时,他/她可以上传个人资料图片并将其加载到imageView中, 图像已成功上载到存储器并成功加载到imageView 但是,当我重新运行应用程序并登录我上传图片的帐户时,图片无法像以前那样加载到imageView中 这是我上传图片的代码: if (mImageUri != null){ file = mStorageRef.

我正在使用java开发一个android应用程序,我正在使用CloudFireStore和firebase存储来存储用户的个人资料图片。 当用户登录时,他/她可以上传个人资料图片并将其加载到imageView中, 图像已成功上载到存储器并成功加载到imageView

但是,当我重新运行应用程序并登录我上传图片的帐户时,图片无法像以前那样加载到imageView中

这是我上传图片的代码:

 if (mImageUri != null){
           file = mStorageRef.child(userId+".png");
            UploadTask = file.putFile(mImageUri).addOnSuccessListener(newOnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
 Toast.makeText(EditDonatorProfile.this,"Image uploaded successfully",Toast.LENGTH_SHORT).show();
                  String Link = mImageUri.toString(); 
                    Upload upload = new Upload(userId,Link);
                    db.collection("profilePicture").document(userId).set(upload);
                }
            });
        }
        else
        {
            Toast.makeText(this,"Choose a file first",Toast.LENGTH_SHORT).show();
        }
DocumentReference documentReference1 =db.collection("profilePicture").document(userId);
        documentReference1.addSnapshotListener(this, new EventListener<DocumentSnapshot>() {
            @Override
public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
               String uri = documentSnapshot.getString("link");
          StorageReference storageReference = StorageReference.getReference("Images/"+userId+".png");
                if(uri == null)
                  return;
                       Uri link = Uri.parse(String.valueOf(uri));
                       Picasso.with(DonatorProfile.this).load(link).into(Photo);
            }
        });
if(mimageri!=null){
file=mStorageRef.child(userId+“.png”);
UploadTask=file.putFile(mimageri).addOnSuccessListener(newOnSuccessListener()){
@凌驾
成功时公共无效(UploadTask.TaskSnapshot TaskSnapshot){
Toast.makeText(EditDonatorProfile.this,“图像上传成功”,Toast.LENGTH_SHORT.show();
String Link=mimageri.toString();
上传=新上传(用户ID、链接);
db.collection(“profilePicture”).document(userId).set(上传);
}
});
}
其他的
{
Toast.makeText(这是“首先选择文件”,Toast.LENGTH_SHORT.show();
}
这是我的检索代码:

 if (mImageUri != null){
           file = mStorageRef.child(userId+".png");
            UploadTask = file.putFile(mImageUri).addOnSuccessListener(newOnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
 Toast.makeText(EditDonatorProfile.this,"Image uploaded successfully",Toast.LENGTH_SHORT).show();
                  String Link = mImageUri.toString(); 
                    Upload upload = new Upload(userId,Link);
                    db.collection("profilePicture").document(userId).set(upload);
                }
            });
        }
        else
        {
            Toast.makeText(this,"Choose a file first",Toast.LENGTH_SHORT).show();
        }
DocumentReference documentReference1 =db.collection("profilePicture").document(userId);
        documentReference1.addSnapshotListener(this, new EventListener<DocumentSnapshot>() {
            @Override
public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
               String uri = documentSnapshot.getString("link");
          StorageReference storageReference = StorageReference.getReference("Images/"+userId+".png");
                if(uri == null)
                  return;
                       Uri link = Uri.parse(String.valueOf(uri));
                       Picasso.with(DonatorProfile.this).load(link).into(Photo);
            }
        });
documentReference1=db.collection(“profilePicture”).document(userId);
documentReference1.addSnapshotListener(这是新的EventListener(){
@凌驾
public void OneEvent(@Nullable DocumentSnapshot DocumentSnapshot,@Nullable FirebaseFirestoreException e){
字符串uri=documentSnapshot.getString(“链接”);
StorageReference-StorageReference=StorageReference.getReference(“Images/”+userId+“.png”);
if(uri==null)
返回;
urilink=Uri.parse(String.valueOf(Uri));
毕加索.with(DonatorProfile.this).load(link).into(照片);
}
});
getCurrentUser().updateProfile(新的UserProfileChangeRequest.Builder())
.setPhotoUri().build())

请编辑该问题,以更详细地解释什么东西没有按您期望的方式工作。有什么东西失败了吗?有错误吗?你做了什么来调试这个?我要注意的是,这不会给你一个可以用毕加索加载的URL:
String Link=mimageri.toString()没有错误也没有例外,我会给你一个场景来理解1-2-用户上传配置文件图片中的用户日志3-用户图像加载到imageView 4-(Me开发者)重新运行应用程序5-2-用户图像中的用户日志为空(无法加载)。