title: How can I get all .pdf files from Internal as well as External storage using MediaStore.Files in Android
body: <pre><code>  private List&lt;PDFFileDetails&gt; getPdfFilesFromDevice(Context context) {
      List&lt;PDFFileDetails&gt; listOfDirectories = new ArrayList&lt;&gt;();
      ContentResolver cr = context.getContentResolver();
      Uri uriExternal = MediaStore.Files.getContentUri("external");
      Uri uriInternal = MediaStore.Files.getContentUri("internal");
  
      String[] projection = null;
  
      String sortOrder = null; // unordered
  
      // only pdf
      String selectionMimeType = MediaStore.Files.FileColumns.MIME_TYPE + "=?";
      String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension("pdf");
      String[] selectionArgsPdf = new String[]{mimeType};
  </code></pre>
  
  <p>Here I am getting all pdf from my internal storage and not from external sdcard
  First i tried without sdcard and after that I inserted sdcard but no result is coming from sdcard</p>
  
  <pre><code>    Cursor allPdfFilesCursor = cr.query(uriExternal, projection, selectionMimeType, selectionArgsPdf, sortOrder);
      if (allPdfFilesCursor != null &amp;&amp; allPdfFilesCursor.getCount() != 0) {
          allPdfFilesCursor.moveToFirst();
          do {
              int dataColumn = allPdfFilesCursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
              String filePath=allPdfFilesCursor.getString(dataColumn);              
          } while (allPdfFilesCursor.moveToNext());
      }
  </code></pre>
  
  <p>No result is coming from internal or external storage </p>
  
  <pre><code>    allPdfFilesCursor = cr.query(uriInternal, projection, selectionMimeType, selectionArgsPdf, sortOrder);
      if (allPdfFilesCursor != null &amp;&amp; allPdfFilesCursor.getCount() != 0) {
          allPdfFilesCursor.moveToFirst();
          do {
              int dataColumn = allPdfFilesCursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
              String filePath=allPdfFilesCursor.getString(dataColumn);
          } while (allPdfFilesCursor.moveToNext());
      }
  
      if (allPdfFilesCursor != null &amp;&amp; !allPdfFilesCursor.isClosed()) {
          allPdfFilesCursor.close();
      }
  
      return listOfDirectories;
  }
  </code></pre>