Serena C
Serena C

Reputation: 1

How to display images from firebase into recyclerview?

My images unable to be displayed, no error but images not showing. pls help how to display these urls in my apps

screen shot

Upvotes: 0

Views: 750

Answers (2)

Rohit Maurya
Rohit Maurya

Reputation: 750

To get Full url of image from storage You can do as follow

    firebaseStorage.getReference().child("*Your storage path*").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
//Here Your Storage Path is path where you have uploaded your file/image.
        @Override
        public void onSuccess(Uri uri) {
            // Got the download URI for '*File/image*'
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {
            //handle error
        }
    });

as @Ronaldo Zoccaratto de Souza said you can use download uri to show image or save url in database.

Upvotes: 1

First, store the full uri in your database. It will be something like this:

gs://yourdatabasehere.appspot.com/IMG_9837.JPG

or

https://firebasestorage.googleapis.com/v0/b/yourdatabasehere/IMG%29837.JPG?alt=media&token=b6c9153f-7d7c-4b05-a60e-7c7d113733ae

In your code, once you retrieve full uri from database, just use Glide or Picasso to display the image:

Picasso.with(this)
        .load(photoUri)  // full uri retrieved from database
        .placeholder(R.mipmap.ic_no_image) //optional
        .error(R.mipmap.ic_no_image) //optional        
        .into(imageView1);

Upvotes: 3

Related Questions