0

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);
    
            }
        }
    }
  • Have you tried adding a listener to listen for error messages? – jbmcle Jan 17 '23 at 15:11
  • i usually inspect the logcat for errorrs . But there's no error displaying and my app doesnt crash too . I just tried to load the image using Picasso but the image doesn't display – Patrick Renaud Jan 17 '23 at 15:16
  • You have to explicitly set a listener for Picasso to listen for events. See this answer: https://stackoverflow.com/questions/26548660/how-to-listen-for-picasso-android-load-complete-events#26548894 – jbmcle Jan 17 '23 at 15:20

1 Answers1

0

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)
Sohaib Ahmed
  • 1,990
  • 1
  • 5
  • 23
  • thanks , it works for me but i had to use the java version ( am coding in java) : Glide.with(this).load(path).into(binding.imageContainer); – Patrick Renaud Jan 17 '23 at 15:33