Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list all pdf files on android 10?

Since the changes related to the authorizations of access to the shared storage, it does not seem any more possible to search all the documents of the type pdf by this approach (with requestLegacyExternalStorage = "false"):

ContentResolver cr = context.getContentResolver();
Uri uri = MediaStore.Files.getContentUri("external");
String[] projection = null;
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
                    + MediaStore.Files.FileColumns.MEDIA_TYPE_NONE;
String[] selectionArgs = null;
String sortOrder = null;
Cursor allNonMediaFiles = cr.query(uri, projection, selection, selectionArgs, sortOrder);

Check this link : Media data restrictions

The only solution I see is to scan in a recurcive way all the tree of the shared storage with SAF, which seems to me very expensive in resources and ridiculous.

Does anyone have another idea?

like image 328
Aristide13 Avatar asked Nov 04 '19 08:11

Aristide13


People also ask

How do I list all PDF files on my Android phone?

You can try this : 1.) private ListView mListView; private ArrayList<AttachmentModel> mAttachmentList = new ArrayList<>(); private ArrayList<File> fileList = new ArrayList<File>(); mListView = (ListView)findViewById(R. id.

Where are PDF files stored on my Android phone?

PDF files on your Android device are stored in the Downloads folder. However, some apps may send their PDF files to the Documents folder instead. You can access these through your File Manager, by going to internal storage and then "Downloads" or "Documents".

Where are my PDF files on my Samsung phone?

You can find almost all the files on your smartphone in the My Files app. By default, this will appear in the folder named Samsung. If you are having trouble finding the My Files app, you should try using the search feature.


1 Answers

The basic idea of scoped storage is exactly to avoid this kind of behavior, you can't know if there are or not some files somewhere in the user phone. You can just ask for permission to access to the storage tree and scan everything as you said. Even in this case the user could select a folder different from the root so your app will be limited to that folder. The idea could be perform a scan and then update your database keeping in sync using a job (job service) scheduled on the modification of tree URI and descendants.

like image 142
greywolf82 Avatar answered Sep 21 '22 07:09

greywolf82