How to load a photo with Picasso

35 views Asked by At

I am implementing an app and i'm trying to load the photo using picasso but i am not getting any result . How can i figure it out ? Here 's what i've done :

    public class FullScreenPhoto extends AppCompatActivity {
    ActivityFullScreenPhotoBinding binding;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            binding=ActivityFullScreenPhotoBinding.inflate(getLayoutInflater());
            setContentView(binding.getRoot());
    //Retrieving image path
            Intent intent = getIntent();
            String path =intent.getStringExtra("image_path");
//value of path=/storage/emulated/0/Android/data/com.ticanalyse.mheath.bf/files/Pictures/AH144644_7972289747179568715.jpg
            if (Objects.equals(path, "no_image")) {
                binding.imageContainer.setVisibility(View.GONE);
                binding.textView.setVisibility(View.VISIBLE);
            }else{
                Log.d("path",path);
                binding.imageContainer.setVisibility(View.VISIBLE);
                Picasso.get()
                        .load(path)
                        .into(binding.imageContainer);
    
            }
        }
    }
1

There are 1 answers

1
Sohaib Ahmed On BEST ANSWER

I'm not sure about picasso that it shows image from filePath or not. But glide can do that.

Using glide with listener, you can surely achieve image

Glide
    .with(context)
    .load(path)
    .listener(object : RequestListener<Drawable> {
        override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
            //TODO handle error images while loading photo
            return true
        }

        override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
            //TODO use "resource" as the photo for your ImageView
            return true
        }

    })
    .into(binding.imageContainer)