搜索所有.pdf文件present在Android设备 [英] Search all .pdf file present in the Android device

查看:96
本文介绍了搜索所有.pdf文件present在Android设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过编程的方式搜索所有.PDF和.doc文件present在Android设备?

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

推荐答案

尝试使用下面的code,这将工作妳。

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

              }
            }
        }
    }    
}

修改

要使用对整个SD卡调用搜索这个功能

To search on the whole sdcard call this function using

walkdir(Environment.getExternalStorageDirectory());

这篇关于搜索所有.pdf文件present在Android设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆