private List<PDFFileDetails> getPdfFilesFromDevice(Context context) {
List<PDFFileDetails> listOfDirectories = new ArrayList<>();
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};
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
Cursor allPdfFilesCursor = cr.query(uriExternal, projection, selectionMimeType, selectionArgsPdf, sortOrder);
if (allPdfFilesCursor != null && allPdfFilesCursor.getCount() != 0) {
allPdfFilesCursor.moveToFirst();
do {
int dataColumn = allPdfFilesCursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
String filePath=allPdfFilesCursor.getString(dataColumn);
} while (allPdfFilesCursor.moveToNext());
}
No result is coming from internal or external storage
allPdfFilesCursor = cr.query(uriInternal, projection, selectionMimeType, selectionArgsPdf, sortOrder);
if (allPdfFilesCursor != null && 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 && !allPdfFilesCursor.isClosed()) {
allPdfFilesCursor.close();
}
return listOfDirectories;
}
May be it is late , but i finally get the solution for as you asked for multiple file extension like .doc, pdf , xls.