Hi I am loading images to grid from android MediaStore like this
private ArrayList<ImageItem> loadImageData() {
Cursor cursor;
int columnIndex;
// Set up an array of the Thumbnail Image ID column we want
String[] projection = {MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Thumbnails._ID, MediaStore.Images.Media.DATA, MediaStore.Images.Thumbnails.DATA};
// Create the cursor pointing to the SDCard
cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection, // Which columns to return
null, // Return all rows
null,
null);
// Get the column index of the Thumbnails Image ID
int imageID;
cursor.moveToFirst();
final ArrayList<ImageItem> imageItems = new ArrayList<>();
for (int i = 0; i < cursor.getCount(); i++) {
columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
imageID = cursor.getInt(columnIndex);
int nameIndex = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME);
int fullImageIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
String uri = "file://" + cursor.getString(fullImageIndex);
int thumbIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA);
String TbUri = "file://" + cursor.getString(thumbIndex);
imageItems.add(new ImageItem(TbUri, cursor.getString(nameIndex), uri));
cursor.moveToNext();
}
cursor.close();
return imageItems;
}
then I add the thumbs to grid
Picasso.with(gridContext).load(item.getImage()).fit().centerCrop().into(Holder.image);
on on android 4.0.1 device this code works fine.
but on android 7.1 I get few images loaded to grid an rest are missing. images that don't show are JPEG taken with the device camera. images from download folder or whatsApp are shown correctly.
In logcat I get error below:
e: Invalid image: ExifInterface got an unsupported image format file(ExifInterface supports JPEG and some RAW image formats only) or a corrupted JPEG file to ExifInterface. java.io.IOException: Invalid marker: 89
could this be related to thumbnails? because I use:
int thumbIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA);
String TbUri = "file://" + cursor.getString(thumbIndex);
downgrading to Picasso version 2.4.0 seems to fix the issue. Might be device related too. My device is onePlus 3 7.1.1 hope this helps someone else.