我正在使用Java开发一个Android应用程序,正在使用Cloud Firestore和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);
}
});
最佳答案
getCurrentUser()。updateProfile(new UserProfileChangeRequest.Builder()
.setPhotoUri()。build());