Content resolver returns wrong size

I select an image from the gallery and request its size via the ContentResolverAPI, it returns 29kb.

However, when I check the file via adb with ls -al, it is 44kb

this is how i request image size:

    private fun getFileInfo(contentResolver: ContentResolver, fileUri: Uri): Pair<String, Long>? {
    val projection = arrayOf(MediaStore.MediaColumns.DISPLAY_NAME, MediaStore.MediaColumns.SIZE)
    val metaCursor = contentResolver.query(fileUri, projection, null, null, null)
        metaCursor?.use {
            if (it.moveToFirst()) {
                val displayNameIndex = it.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME)
                val sizeIndex = it.getColumnIndex(MediaStore.MediaColumns.SIZE)
                return Pair(it.getString(displayNameIndex), it.getLong(sizeIndex))
            }
    }
    return null
}

I am using an Oreo emulator. I also checked through the emulator tools, shows the file browser as 29kb, on the other hand, the file data shows 45kb. What's happening?

Here are the images from the file browser:

Summary

More details

Another remark, above the situation, can be played every time you use the camera application on an emulator with Android 26-Oreo emulator, however this is normal with Android 25-Nougat emulator.

I checked, the new Document API also returns 29kb

+2
1

Android 8.0 (Oreo) "SDCardFS", "FUSE" /​​sdcard.

, 29kb, 29kb, 44. * kb.

ls -al , , .

0

All Articles