1

I am getting an occasional (quite rare) exception from MediaStore.Images.Thumbnails.getThumbnail (see below). Similar questions were advised to always close the cursor, but I am not performing an explicit query.

I call it like this:

a private function reading the thumbnails.. (

      private Bitmap getThumbnail(long imageId) { return MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(), imageId,
      MediaStore.Images.Thumbnails.MINI_KIND, null); }

It is called from here:

Cursor cursor = null;
int numProcessed = 0, numFaceDetected = 0;
try {
  dirtyFile.createNewFile();

  String[] projection = {
      MediaStore.Images.Media._ID,
      MediaStore.Images.Media.DATA,
      MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
      MediaStore.Images.Media.ORIENTATION
  };

  cursor = getContentResolver().query(
      MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
      projection,
      null,
      null,
      MediaStore.Images.Media.DATE_ADDED + " desc");

  if (cursor == null) {
    return;
  }

  cursor.moveToFirst();
  final int columnIndexId = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
  final int columnIndexData = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
  final int columnIndexOrientation = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.ORIENTATION);
  final int columnIndexBucketName = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);

  while (!cursor.isAfterLast()) {
    final long imageId = cursor.getLong(columnIndexId);
    final String imagePath = cursor.getString(columnIndexData);
    final int imageOrientation = cursor.getInt(columnIndexOrientation);

    Bitmap bitmap = getThumbnail(imageId);
    faceDetect(bitmap); 

    cursor.moveToNext();
    numProcessed++;

  }

Here is the exception:

android.database.CursorWindowAllocationException: Cursor window could not be created from binder.
       at android.database.CursorWindow.(CursorWindow.java:137)
       at android.database.CursorWindow.(CursorWindow.java:42)
       at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:685)
       at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:683)
       at android.database.BulkCursorDescriptor.readFromParcel(BulkCursorDescriptor.java:75)
       at android.database.BulkCursorDescriptor$1.createFromParcel(BulkCursorDescriptor.java:34)
       at android.database.BulkCursorDescriptor$1.createFromParcel(BulkCursorDescriptor.java:30)
       at android.content.ContentProviderProxy.query(ContentProviderNative.java:423)
       at android.content.ContentResolver.query(ContentResolver.java:478)
       at android.content.ContentResolver.query(ContentResolver.java:422)
       at android.provider.MediaStore$InternalThumbnails.getThumbnail(MediaStore.java:680)
       at android.provider.MediaStore$Images$Thumbnails.getThumbnail(MediaStore.java:1060)
Gili Garibi
  • 416
  • 2
  • 13

1 Answers1

0
Could you try replacing your thumb nail code with this

    Cursor cursor = MediaStore.Images.Thumbnails.queryMiniThumbnail(
                                 getContentResolver(), selectedImageUri,
                                 MediaStore.Images.Thumbnails.MINI_KIND,
                                 null );
    if( cursor != null && cursor.getCount() > 0 ) {
         cursor.moveToFirst();//**EDIT**
         String uri = cursor.getString( cursor.getColumnIndex( MediaStore.Images.Thumbnails.DATA ) );
    }

Reference of this answer is taken from [here][1]


  [1]: http://stackoverflow.com/questions/5548645/get-thumbnail-uri-path-of-the-image-stored-in-sd-card-android
dex
  • 5,182
  • 1
  • 23
  • 41
  • I am trying to verify that this is equivalent to calling the getThumbnail method, but it appears that on some of the photos, the cursor returns empty. Investigating.. – Gili Garibi Oct 20 '15 at 04:50
  • can you share those cases too, because I am not able to re-produce them at my end. – dex Oct 20 '15 at 19:57
  • I can't send you the problematic image. What I did is check if the cursor.getCount is 0, I'm defaulting back to the old call. For some images, the cursor can't read the thumbnail while the getThumbnail can. – Gili Garibi Oct 28 '15 at 06:12