On some (all?) Samsung devices (Galaxy S5, S3) Picasso does not display Images from the Gallery.
This is the code:
File[] picFiles = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).listFiles();
File file = picFile[0];
I tried:
Picasso.with(getActivity()).load(Uri.fromFile(file)).into(imageView);
as well as
Picasso.with(getActivity()).load("file://" + file.getAbsolutePath()).into(imageView);
to no avail. On all non-samsung devices boths snippets work fine:
The path to the files do not look different from other devices, example:
/storage/emulated/0/Pictures/JPEG_20150706_112313_826588781.jpg
What could be the problem here?
EDIT: Yes I have added android.permission.READ_EXTERNAL_STORAGE
. The file exists and the Image is visible in the gallery app.
EDIT 2: This is the stracktrace from Picasso:
07-13 07:22:22.817 14648-14921/xy I/dalvikvm﹕ "Picasso-/storage/emulated/0/Pictures/JPEG_20150713_071858_-1853613631.jpg" prio=5 tid=51 RUNNABLE
07-13 07:22:22.817 14648-14921/xy I/dalvikvm﹕ at com.squareup.picasso.BitmapHunter.decodeStream(BitmapHunter.java:142)
07-13 07:22:22.817 14648-14921/xy I/dalvikvm﹕ at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:217)
07-13 07:22:22.817 14648-14921/xy I/dalvikvm﹕ at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
07-13 07:22:22.817 14648-14921/xy I/dalvikvm﹕ at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:411)
07-13 07:22:23.167 14648-14918/xy﹕ "Picasso-/storage/emulated/0/Pictures/JPEG_20150713_071858_-1853613631.jpg" prio=5 tid=49 RUNNABLE
07-13 07:22:23.167 14648-14918/xy﹕ at com.squareup.picasso.BitmapHunter.transformResult(BitmapHunter.java:558)
07-13 07:22:23.167 14648-14918/xy﹕ at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:232)
07-13 07:22:23.167 14648-14918/xy﹕ at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
07-13 07:22:23.167 14648-14918/xy﹕ at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:411)
It doesn't really seem to reveal the reason for the image not being displayed.
Picasso version is 2.5.2, I could reproduce the error on a Samsung S3 with Android 4.4.4 and a Samsung S5 with Android 5.0.
UIL is loading the same image just fine, so it's probably a bug in Picasso, I'll probably file a bug report at their github.
LAST EDIT: The problem actually was an OOM exception that eluded my attention because I filtered my LogCat for the wrong keywords. I'm quite ashamed of myself now.
picasso.load().fit().into()
works and the image is being displayed. Thanks for your help.
You are most likely loading very large images which can lead to an
OutOfMemoryError
. You can resize theBitmap
and keep the aspect ratio.Example of getting the width and height of a bitmap without loading it into memory:
Tell Picasso to resize the image to avoid an
OutOfMemoryError
: