0

Currently developing an app which loads images from SD card. In the emulator the following works fine and finds images to display. However, on the Galaxy S2 and S3 - no images are ever displayed. Any ideas?

Cursor cursor = getContentResolver().query(
    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
    { MediaStore.Images.Thumbnails._ID }, 
    null, 
    null, 
    MediaStore.Images.Media._ID
);

int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
int size        = cursor.getCount();
int imageId     = 0;

for (int i = 0; i < size; i++) {
     if(cursor.isClosed()) {
         continue;
     }
     cursor.moveToPosition(i);
     imageId = cursor.getInt(columnIndex);
     uri     = Uri.withAppendedPath(
         MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, 
         Integer.toString(imageId)
     );

try {
    bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));

        if (bitmap != null) {
            newBitmap = Bitmap.createScaledBitmap(bitmap, 70, 70,true);
            bitmap.recycle();

            if (newBitmap != null) {
                publishProgress(newBitmap);
            }
        }
} catch (IOException e) {}
}
cursor.close();
return null;
James
  • 117
  • 1
  • 4
  • Log exceptions in `catch (IOException e) {}` maybe there is one. – zapl Nov 29 '12 at 00:49
  • Yeah, I thought that but I don't have the device available. I am guessing if I launch a dialog at least the end user will be able to see the message before we publish it to the store. – James Nov 29 '12 at 09:36

1 Answers1

0

After testing on device found the following resolved the issue:

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.outHeight = 70;
    options.outWidth = 70;
    Bitmap bitmap = null;

    Cursor cursor = getContentResolver().query(
        MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
        PROJECTION, 
        null, 
        null, 
        MediaStore.Images.Media._ID
    );
    int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
    int size        = cursor.getCount();

    for (int i = 0; i < size; i++) {
        if(cursor.isClosed()) {
            break;
        }
        cursor.moveToPosition(i);

        bitmap = MediaStore.Images.Thumbnails.getThumbnail(
            getContentResolver(), 
            cursor.getInt(columnIndex), 
            MediaStore.Images.Thumbnails.MICRO_KIND,  
            options
        );
        publishProgress(new LoadedImage(bitmap));
    }
    cursor.close();
James
  • 117
  • 1
  • 4