This is what I did and it works in sdk 29, it will return all files regardless of type.
val uri = MediaStore.Files.getContentUri("external")
val projection = arrayOf(
MediaStore.Images.Media.DATA,
MediaStore.Files.FileColumns.MIME_TYPE,
)
val cursor = this.contentResolver.query(
uri,
projection,
null,
null,
MediaStore.Images.Media.DATE_ADDED " DESC"
)
But after forced to raise targetSdk to at least 30 (Playstore required), it only returns image/video/audio files, is there any way to solve this problem, or is there any other way to read all files (or at least document files)?
CodePudding user response:
I found the problem, since Android 11 we distinguish between read media files and all files, so the app needs to be allowed to read all files
see workaround here:
How to access permission allow management of all file in android studio
After allow this permission, the above code will work!
CodePudding user response:
This should be related to Android.permissions (READ/WRITE_EXTERNAL_STORAGE)
