val projection = arrayOf( //you only want to retrieve _ID and DISPLAY_NAME columns MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME) context.contentResolver.query( uri, projection, null, null, null, null)?.use { cursor -> //cache column indices val idColumn = cursor.getColumnIndex(MediaStore.Images.Media._ID) val nameColumn = cursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME) //iterating over all of the found images while (cursor.moveToNext()) { val imageId = cursor.getString(idColumn) val imageName = cursor.getString(nameColumn) } }