I want to load all the pictures from the galley to my app by using MediaStore.MediaColumns.DATA , but it is deprecated. So, what is the other way to load them?
I use this code now, but it is deprecated as I said:
fun getAllShownImagesPath(activity: Activity): MutableList<String> {
val uri: Uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI
val cursor: Cursor?
val columnIndexData: Int
val listOfAllImages: MutableList<String> = mutableListOf()
val projection = arrayOf(MediaStore.MediaColumns.DATA)
var absolutePathOfImage: String
cursor = activity.contentResolver.query(uri, projection, null, null, null)
if (cursor != null) {
columnIndexData = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA)
while (cursor.moveToNext()) {
absolutePathOfImage = cursor.getString(columnIndexData)
listOfAllImages.add(absolutePathOfImage)
}
cursor.close()
}
return listOfAllImages
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…