0

I have a problem with my code, I try download a image from the Firebase Storage. And I´m trying to put the image in a ImageView.

 @Override
    public void onBindViewHolder(@NonNull final PostViewHolder postViewHolder, int i) {
        Resources resources = Home_Activity.getResources();
        StorageReference storageReference = FirebaseStorage.getInstance().getReference();
        storageReference.child("images/-LgXJiSUo44zOIzky-eZ.jpeg");
        storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
            @Override
            public void onSuccess(Uri uri) {
                postViewHolder.picture.setImageURI(uri);
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {

                Toast.makeText(Home_Activity, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
            }
        });


        postViewHolder.name.setText(posts.get(i).getPlace_name());
        postViewHolder.description.setText(posts.get(i).getPlace_detail());
    }

KENdi
  • 7,576
  • 2
  • 16
  • 31
Adrian Lagartera
  • 442
  • 1
  • 3
  • 17
  • 1
    That's not how you use setImageURI. It only accepts a local URI. It doesn't know how to download from an HTTP URL. You should use a library such as Glide to do that. https://stackoverflow.com/questions/3870638/how-to-use-setimageuri-on-android – Doug Stevenson Jun 05 '19 at 13:03

1 Answers1

0

Here's how you would load the image, i'm not sure you can just set the uri to image uri as it failed to decode it but i would use a image loading library like Glide,Fresco,Picasso to load the uri.

   FirebaseStorage.getInstance().getReference("images/-LgXJiSUo44zOIzky-eZ.jpeg").getDownloadUrl().addOnCompleteListener(new OnCompleteListener<Uri>() {
                        @Override
                        public void onComplete(@NonNull Task<Uri> task) {
                            if(task.isSuccessful()){
                                Uri uri = task.getResult();

                            }
                        }
                    });