Q: FInd image size of an selected image in Custom Gallery I am developing a custom gallery.There are certain images with size 0Bytes , my gallery should not allow images with size equal to 0. Is there any possible way to find the size of image?Or avoid loading such images.
This my code
    Uri uri;
    Cursor cursor;
    int column_index_data;
    long sizeIndex;
    ArrayList<String> listOfAllImages = new ArrayList<>();
    String absolutePathOfImage;
    uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    String[] projection = {MediaStore.MediaColumns.DATA,
            MediaStore.Images.Media.BUCKET_DISPLAY_NAME};

    cursor = activity.getContentResolver().query(uri, projection, null,
            null, MediaStore.MediaColumns.DATE_ADDED + " DESC");

    if (cursor != null) {
        column_index_data = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
        sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);

        while (cursor.moveToNext()) {
            if (sizeIndex != 0) {
                Log.e("sizeimage", "" + sizeIndex);
                absolutePathOfImage = cursor.getString(column_index_data);
                listOfAllImages.add(absolutePathOfImage);
            }
        }
        thumbnailsselection = new boolean[cursor.getCount()];
        cursor.close();
    }

PS I don't want to convert them to bitmap while finding the size.

A: Finally I found the solution , we need to add  MediaStore.MediaColumns.SIZE as on the element to my projection array.Now i can get the value from cursor .
    Uri uri;
    Cursor cursor;
    int column_index_data;
    long sizeIndex;
    ArrayList<String> listOfAllImages = new ArrayList<>();
    String absolutePathOfImage;
    uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    // added size to my string array
    String[] projection = {MediaStore.MediaColumns.DATA,
            MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.MediaColumns.SIZE};

    cursor = activity.getContentResolver().query(uri, projection, null,
            null, MediaStore.MediaColumns.DATE_ADDED + " DESC");

    if (cursor != null) {
        column_index_data = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
        int imageSize = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE);


        while (cursor.moveToNext()) {
            absolutePathOfImage = cursor.getString(column_index_data);
            // I got the image size from my cursor.Now i can validate it whether it equals to 0 Or not
            long si = cursor.getLong(imageSize);
            if (si != 0)
                listOfAllImages.add(absolutePathOfImage);

        }
        thumbnailsselection = new boolean[cursor.getCount()];
        cursor.close();
    }

