nguyenhoanglam / ImagePicker

A customizable library for selecting images on the device.
Apache License 2.0
599 stars 156 forks source link

We need to support Android 11 #124

Closed Sayed-Shalan closed 2 years ago

Sayed-Shalan commented 4 years ago

android:requestLegacyExternalStorage="true" is a workaround. so can we migrate to scoped storage ASAP ?. Thank you.

nguyenhoanglam commented 4 years ago

I've tested on the Android 11 emulator and it works!

If you have an Android 11 device, please test it and let me know the result.

mrNoolas commented 3 years ago

For my emulator it seems to only work with albums that are owned by this app. Pictures in the gallery or elsewhere cannot be opened in Android 11 for me.

ArchangelXu commented 3 years ago

Just built a library to support Android 11. Tested on Android 10 (device) and Android 11 (Simulator): https://github.com/ming-xi/MXMediaPicker

nguyenhoanglam commented 2 years ago

@Sayed-Shalan Check v1.5.0 now. Hope you enjoy it!

frared358 commented 2 years ago

@nguyenhoanglam it is working on emulator Android11 but not working on RealMe and Oneplus7 of Android11 devices.. can you please help me with this

Error : one of the bucket name was null so all the folder where not visible

Issued Solved

private suspend fun fetchImagesFromExternalStorage(): ArrayList<Image> {
        if (contextRef.get() == null) return arrayListOf()

        return withContext(Dispatchers.IO) {
            val projection = arrayOf(
                MediaStore.Images.Media._ID,
                MediaStore.Images.Media.DISPLAY_NAME,
                MediaStore.Images.Media.BUCKET_ID,
                MediaStore.Images.Media.BUCKET_DISPLAY_NAME
            )

            val imageCollectionUri = ImageHelper.getImageCollectionUri()

            contextRef.get()!!.contentResolver.query(
                imageCollectionUri,
                projection,
                null,
                null,
                MediaStore.Images.Media.DATE_ADDED + " DESC"
            )?.use { cursor ->
                val images = arrayListOf<Image>()

                val idColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID)
                val nameColumn =
                    cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME)
                val bucketIdColumn =
                    cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_ID)
                val bucketNameColumn =
                    cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME)

                while (cursor.moveToNext()) {
                    val id = cursor.getLong(idColumn)
                    val name = cursor.getString(nameColumn)
                    val bucketId = cursor.getLong(bucketIdColumn)
                    val bucketName = cursor.getString(bucketNameColumn)

                    /*Added this line*/
                    if (bucketName != null) {
                        val uri = ContentUris.withAppendedId(imageCollectionUri, id)
                        val image = Image(uri, name, bucketId, bucketName)
                        images.add(image)
                    }
                }
                cursor.close()
                images
            } ?: throw IOException()
        }
    }

Please correct me if I am wrong

nguyenhoanglam commented 2 years ago

@frared358 v1.5.3 just has been released. Check it out!