Sagar
Sagar

Reputation: 405

MediaStore cursor not displaying non-media files in Android 10

I am trying to get files in the external storage and display in app. I am able to get the media files without any issues but I am not able to get non-media files in Android 10. Attached the snippet bellow for fetching pdf. When I see the count it is 0 even though I have pdf files in my external storage. This is happening for Android 10+

 Cursor cursor = getContext().getContentResolver().query(
                    MediaStore.Files.getContentUri("external"), // Table to query
                    new String[]{MediaStore.Files.FileColumns.DATA}, // file location
                    MediaStore.Files.FileColumns.MIME_TYPE + "=?", // selection clause
                    new String[]{ MimeTypeMap.getSingleton().getMimeTypeFromExtension("pdf") }, // selection arguments
                    MediaStore.Files.FileColumns.DATE_MODIFIED + " DESC" // ordering)
            ); 
  

Upvotes: 0

Views: 1035

Answers (1)

sdex
sdex

Reputation: 3743

Since Android 10 you cannot use MediaStore to load files other than media (audio, video, image).

The official way to open a document is to use ACTION_OPEN_DOCUMENT and let a user select a file from the file picker.
Check the docs: https://developer.android.com/training/data-storage/shared/media#other-file-types

Upvotes: 1

Related Questions