Closed Sayed-Shalan closed 2 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.
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.
Just built a library to support Android 11. Tested on Android 10 (device) and Android 11 (Simulator): https://github.com/ming-xi/MXMediaPicker
@Sayed-Shalan Check v1.5.0 now. Hope you enjoy it!
@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
@frared358 v1.5.3 just has been released. Check it out!
android:requestLegacyExternalStorage="true" is a workaround. so can we migrate to scoped storage ASAP ?. Thank you.