1

Friends I am trying to get path of the pdf's for my app. Suppose there are n number of pdf's in your android phone(may be in root dir or sdcard) then how could you get there path programmatically ? Could some one please suggest me some hints ?

Thanks in Advance

Karan

karansingh1487
  • 105
  • 1
  • 2
  • 11

3 Answers3

1
File images = Environment.getExternalStorageDirectory();
imagelist = images.listFiles(new FilenameFilter()
{
public boolean accept(File dir, String name)
{
return ((name.endsWith(".pdf")));
}
});
pdflist = new String[imagelist.length];
for(int i = 0;i<imagelist.length;i++)
{
pdflist[i] = imagelist[i].getName();
}

also see this link Assistance required for scanning the .mp3 files in sdcard

Community
  • 1
  • 1
Nitin
  • 1,966
  • 4
  • 22
  • 53
  • hey man one thing it does scans the pdf bt nt all the pdf's in the phone ...like if some pdf is dere in some other folders then wht ? – karansingh1487 Jul 24 '12 at 09:30
  • use the path of the phone you have to search path of phone and then all the work will be done by the code ok and just use google for getting path of phone thats it. – Nitin Jul 24 '12 at 09:35
  • i was able to get them by recursively search the items ....like see this link http://stackoverflow.com/questions/2056221/recursively-list-files-in-java – karansingh1487 Jul 24 '12 at 10:05
0

For SD Card check

    if (android.os.Environment.getExternalStorageState().equals(
            android.os.Environment.MEDIA_MOUNTED)) {
         File f = new File(Environment.getExternalStorageDirectory());

         File[] files = f.listFiles();
         File file;
         for (int i = 0; i < files.length; i++) {
                file = files[i];
         }
    }

    //For Internal Memory

    else {
            /* save the folder in internal memory of phone */

        File f = new File("/data/data/com.your.package/");
        File[] files = f.listFiles();
    }
Nirali
  • 13,571
  • 6
  • 40
  • 53
0

I was able to get them by recursively searching the items ....

Recursively list files in Java

Community
  • 1
  • 1
karansingh1487
  • 105
  • 1
  • 2
  • 11