在android中获取pdf的路径

时间:2012-07-23 12:19:58

标签: android android-layout pdf android-intent file-browser

朋友我想为我的应用程序获取pdf的路径。 假设你的Android手机中有n个pdf(可能是root目录或sdcard)那么你怎么能到达那里 以编程方式?有人可以给我一些提示吗?

先谢谢

Karan

3 个答案:

答案 0 :(得分: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();
}

另请参阅此链接Assistance required for scanning the .mp3 files in sdcard

答案 1 :(得分:0)

用于SD卡检查

    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();
    }

答案 2 :(得分:0)

我能够通过递归搜索项目来获取它们。

Recursively list files in Java