title: Get list of pdf files in storage - Mediastore android
body: <p>Can someone help me with this issue, I am trting to get list of pdf files from external storage but the array always empty, this is my code:</p>
  <p>Thank you in advance.</p>
  <p>This is my code:</p>
  <pre><code>public static ArrayList&lt;String&gt; getPdfFiles(Context context) {
          ArrayList&lt;String&gt; listOfAllFiles = new ArrayList&lt;&gt;();
  
          Uri uri = MediaStore.Files.getContentUri(&quot;external&quot;);
          ContentResolver cr = context.getContentResolver();
          String[] projection = {MediaStore.MediaColumns.DATA};
          // only pdf
          String selectionMimeType = MediaStore.Files.FileColumns.MIME_TYPE + &quot;=?&quot;;
          String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(&quot;pdf&quot;);
          String[] selectionArgsPdf = new String[]{ mimeType };
          Cursor allPdfFiles = cr.query(uri, projection, selectionMimeType, selectionArgsPdf, null);
  
          while (allPdfFiles.moveToNext()) {
              int nameIndex= allPdfFiles.getColumnIndex(MediaStore.Files.FileColumns.TITLE);
              String name= allPdfFiles.getString(nameIndex);
              listOfAllFiles.add(name);
          }
          return listOfAllFiles;
      }
  </code></pre>