android / storage-samples

Multiple samples showing the best practices in storage APIs on Android.
Apache License 2.0
1.51k stars 571 forks source link

MediaStore sample load photos failed (most blank images) #96

Open skquo opened 3 years ago

skquo commented 3 years ago

I tested the MediaStore sample on the Redmi Note 9 device, Android Q. Only several photos are loaded, other leave as blank.

Screenshot_2021-04-30-12-22-50-664_com android samples mediastore

It only works normal with requestLegacyExternalStorage.

anik-kucse commented 3 years ago

Check the size for each media object whether it is zero or not. I fixed my problem like that.

` val projection = arrayOf( MediaStore.Files.FileColumns.SIZE, ................................................ )

.................................................... .................................................... val fileSizeColumn = cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.SIZE)

            while (cursor.moveToNext()) {
                val fileSize = cursor.getLong(fileSizeColumn)
                if (fileSize == 0L) {
                    continue
                }

               ...............................
               ........................
            }

`

basurahan commented 2 years ago

Check the size for each media object whether it is zero or not. I fixed my problem like that.

` val projection = arrayOf( MediaStore.Files.FileColumns.SIZE, ................................................ )

.................................................... .................................................... val fileSizeColumn = cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.SIZE)

            while (cursor.moveToNext()) {
                val fileSize = cursor.getLong(fileSizeColumn)
                if (fileSize == 0L) {
                    continue
                }

               ...............................
               ........................
            }

`

Yes this will work on your own app but on the default gallery of the phone it will show those blank images. How can we fix that?