0

I'm aware that people have had this problem before and there are solutions using Firebase Realtime Database, but I'm using Cloud Firestore and I'm trying to fix this. I do not want do downgrade my dependencies as that isn't a solution. But this is how I save my download url:

final String download_uri = uploadTask.getResult().getStorage().getDownloadUrl().toString();

And this is how I try to populate it to Glide:

Glide.with(ProfileActivity.this).load(user_image).into(profilePicture);

In firestore, user_image has the value com.google.android.gms.tasks.zzu@d1a2c07

How do I fix this for firestore?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
lape.bthe
  • 31
  • 6
  • This problem has nothing to do with Cloud Firestore or the Realtime Database, but with how you retrieve the download URL from Firebase Storage. `getDownloadUrl()` nowadays returns a `Task`, so you need to add a listener to that task to wait for its result. The answer by Krishna shows how to do that, but so do many previous questions from [this list](https://stackoverflow.com/search?q=%5Bfirebase-storage%5D%5Bandroid%5D+getdownloadurl). – Frank van Puffelen Oct 05 '19 at 13:37

1 Answers1

2

In your code user_image takes string representation of Task<Uri> object,

Here's how you can get download url from Cloud Firestore

uploadTask.getResult().getStorage().getDownloadUrl().addOnCompleteListener(new OnCompleteListener<Uri>() {
    @Override
    public void onComplete(@NonNull Task<Uri> task) {
         String url = String.valueOf(task.getResult()));//gives image or file string url
    }
});
Krishna Vyas
  • 1,009
  • 8
  • 25