0

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)?

2 Answers2

0

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 enter image description here see workaround here: How to access permission allow management of all file in android studio

After allow this permission, the above code will work!

  • But it has nothing to do with your title: `Document files (word, pdf, excel,...) are no longer returned from MediaStore.Files.getContentUri("external")`. As nomedia files like pdf, doc or exel is not the cause but that your app is not the owner of files that were not found. Easy to test for your self. Let your app create a pdffile in Documents and you will see that you dont need MANAGE_EXTERNAL_STORAGE to see your file in media store. – blackapps Jan 27 '22 at 11:22
  • @blackapps That's not the reason, like I said, it was working fine in API 29, it just can't query document files when upgrading to API 30, and what I want to achieve is to be able to query all of them files included are not created by my app, so I don't understand what you mean by "nothing to do" – Kuroto Bazai Jan 28 '22 at 02:31
0

This should be related to Android.permissions (READ/WRITE_EXTERNAL_STORAGE)

Dan Dfg
  • 1
  • 2