I think you can get DISPLAY_NAME of the folder using OpenableColumns:
contentResolver.query(uri, null, null, null, null)?.use { cursor ->
val displayNameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME) cursor.moveToFirst()
val displayName = cursor.getString(displayNameIndex)
}
Then using this output you can start a new query on MediaStore.Files.EXTERNAL_CONTENT_URI and use a selection to get files
val selection = "${MediaStore.Files.FilesColumns.BUCKET_DISPLAY_NAME} = displayName"
...
For API < Q You can try to run the first query on MediaStore.Files.FilesColumns.DATA.
The run the second query comparing relative path of the files with the output of the first query
File(path).parentFile?.name
That's what I'd do.
Sorry for formatting, I'm on smartphone.