How to search all .pdf and .doc file present in the Android device through programmatic way?
public void Search_Dir(File dir) { String pdfPattern = ". pdf"; File FileList[] = dir. listFiles(); if (FileList !=
By default, if you open Adobe Reader and press CTRL + F, you'll get the normal search box. It is located at the top right in the menu bar. To use the advanced PDF search option, you can choose Open Full Reader Search in the drop down menu of the search box or press SHIFT + CTRL + F.
Try using the below code, This will work for u.
public void walkdir(File dir) {
String pdfPattern = ".pdf";
File listFile[] = dir.listFiles();
if (listFile != null) {
for (int i = 0; i < listFile.length; i++) {
if (listFile[i].isDirectory()) {
walkdir(listFile[i]);
} else {
if (listFile[i].getName().endsWith(pdfPattern)){
//Do what ever u want
}
}
}
}
}
EDIT
To search on the whole sdcard call this function using
walkdir(Environment.getExternalStorageDirectory());
Have a look here
Basicly get a starting Directory and then call "list" with a filter(FilenameFilter) and then traverse sub directories. Not sure if there is a one function that does all this for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With