String selection = MediaStore.Files.FileColumns.MIME_TYPE + “=?”;
String[] selectionArgs = new String[]{“application/pdf”};
String[] projection = new String[]{MediaStore.Files.FileColumns.DATA, MediaStore.Files.FileColumns.DATE_TAKEN, MediaStore.Files.FileColumns.SIZE, MediaStore.Files.FileColumns.DATE_MODIFIED}; // Get file paths
String sortOrder = MediaStore.MediaColumns.DATE_ADDED + ” DESC”;
Cursor cursor = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
cursor = activity.getContentResolver().query(MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL), projection, selection, selectionArgs, sortOrder);
}
Log.e(TAG, "Cursor Lenght : ---> "+cursor.getCount() );
if (cursor != null) {
try {
while (cursor.moveToNext()) {
String filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DATA));
String fileDate = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DATE_TAKEN));
String fileSize = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.SIZE));
String fileModified = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DATE_MODIFIED));
Log.e(TAG, "filePath: -----------> " + filePath);
Log.e(TAG, "fileDate: -----------> " + fileDate);
Log.e(TAG, "fileSize: -----------> " + fileSize);
Log.e(TAG, "fileModified: -----------> " + fileModified);
PC_PDFModel pcPdfModel = new PC_PDFModel();
File pdfFile = new File(filePath);
pcPdfModel.setPdfname(filePath);
pcPdfModel.setPdffile(pdfFile);
pcPdfModel.setDate(fileDate);
pcPdfModel.setDatelastmodi(new Date(fileModified));
pcPdfModel.setSize(fileSize);
pdfList.add(this.pdfModel);
}
} finally {
cursor.close();
}
}
here my Code but i m trying to fetch .pdf files from storage but get cursor count == 0 so please provide me how to get all pdf files
please help me somebody provide me latest soluation of this problem
Rashik Goriya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.