0

I'm targeting now android 11 and all of us know about scoped storage,

my case is that I need to access all pdfs files on the phone it's working for any android less than android 11.

I've tried to grant permission android.permission.MANAGE_EXTERNAL_STORAGE but, I don't know why it fails with me, I'm able to read jpg patter files but, the pdf files I can't.

this is my code:

public ArrayList<PdfData> Search_Dir(File dir) {

        String pdfPattern = ".pdf";
        File[] FileList = dir.listFiles();

        if (FileList != null) {
            for (int i = 0; i < FileList.length; i++) {
                File file = FileList[i];

                if (file.isDirectory()) {
                    Search_Dir(file);
                } else {
                    if (file.getName().endsWith(pdfPattern)) {
                        Log.v("fileNameIs ", " " + i + file.getName());
                        String file_size = Formatter.formatShortFileSize(getApplicationContext(), file.length());
                        PdfData pdfData = new PdfData();
                        pdfData.setFile(file);
                        pdfData.setFileName(file.getName());
                        pdfData.setFileSize(file_size);
                        pdfDataList.add(pdfData);

                        Log.v("fileSize is : ", ": " + file_size);
                    }
                }
            }
        }

        return pdfDataList;
}

i call the method like that

list = Search_Dir(Environment.getExternalStorageDirectory());

Moustafa EL-Saghier
  • 1,721
  • 1
  • 13
  • 43

0 Answers0