Getting path of a pdf in android
-
22-06-2021 - |
Question
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
Solution
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
OTHER TIPS
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();
}
I was able to get them by recursively searching the items ....
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow