Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search all .pdf file present in the Android device

Tags:

android

How to search all .pdf and .doc file present in the Android device through programmatic way?

like image 242
Baba Avatar asked Aug 04 '11 10:08

Baba


People also ask

How do I list all PDF files on my Android phone?

public void Search_Dir(File dir) { String pdfPattern = ". pdf"; File FileList[] = dir. listFiles(); if (FileList !=

How do I search all PDFs?

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.


2 Answers

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());
like image 139
Hussain Avatar answered Oct 03 '22 00:10

Hussain


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.

like image 22
Pintac Avatar answered Oct 03 '22 02:10

Pintac