I found this code about how to get all my Images.
Can someone tell me how can I get only .pdf files in internal storage and external storage?
final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID };
final String orderBy = MediaStore.Images.Media._ID;
//Stores all the images from the gallery in Cursor
Cursor cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
null, orderBy);
//Total number of images
int count = cursor.getCount();
//Create an array to store path to all the images
String[] arrPath = new String[count];
for (int i = 0; i < count; i++) {
cursor.moveToPosition(i);
int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
//Store the path of the image
arrPath[i]= cursor.getString(dataColumnIndex);
Log.i("PATH", arrPath[i]);
}
possible solution can be go to every folder and check if .pdf exists or not if yes the you can do whaterver you want to do with that file
public void Search_Dir(File dir) {
String pdfPattern = ".pdf";
File FileList[] = dir.listFiles();
if (FileList != null) {
for (int i = 0; i < FileList.length; i++) {
if (FileList[i].isDirectory()) {
Search_Dir(FileList[i]);
} else {
if (FileList[i].getName().endsWith(pdfPattern)){
//here you have that file.
}
}
}
}
}
and function call will be
Search_Dir(Environment.getExternalStorageDirectory());