【问题标题】:Getting path of a pdf in android在android中获取pdf的路径
【发布时间】:2012-07-23 12:19:57
【问题描述】:

朋友们,我正在尝试为我的应用获取 pdf 的路径。 假设您的 android 手机中有 n 个 pdf(可能在根目录或 sdcard 中),那么您怎么能到达那里 以编程方式?有人可以给我一些提示吗?

提前致谢

卡兰

【问题讨论】:

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


【解决方案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

【讨论】:

  • 嘿,伙计,它会扫描 pdf bt nt 手机中的所有 pdf 文件......就像如果某些 pdf 文件在其他文件夹中,那么它会做什么?
  • 使用你必须的手机路径搜索手机路径,然后所有的工作都将由代码完成,只需使用谷歌获取手机路径即可。
  • 我能够通过递归搜索项目来获得它们......就像看到这个链接stackoverflow.com/questions/2056221/…
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    我能够通过递归搜索项目来获得它们......

    Recursively list files in Java

    【讨论】:

      猜你喜欢
      • 2021-03-25
      • 1970-01-01
      • 2019-08-15
      • 1970-01-01
      • 2015-07-17
      • 2011-12-27
      • 1970-01-01
      • 2014-09-05
      • 1970-01-01
      相关资源
      最近更新 更多