所以我偶然发现了一些东西......文件扫描媒体扫描仪连接

时间:2013-04-01 19:15:06

标签: java android createfile

如何使用媒体扫描程序连接使文件传输可见文件。 在这里提到一个问题(Android File Transfer cannot see a folder created by app

目前即时编写应用程序,只是想确保文件夹在那里,如果没有创建它。最终,文件夹中的数据将需要从文件夹中取出或添加更多数据。

感谢您对这款扫描仪的帮助有点困惑。

    File internalMemory = new File("/mnt/sdcard/FMCW File Archive");
    if(internalMemory.exists() && internalMemory.isDirectory()) {
        mFileList = internalMemory.listFiles();
    }else{
        createDirIfNotExist("/FMCW File Archive");
    }

以下是方法

    public static boolean createDirIfNotExist(String path) {
    boolean ret = true;
    File file = new File(Environment.getExternalStorageDirectory() + path);
    if (!file.exists()) {
        if (!file.mkdirs()) {
            Log.e("TravellerLog :: ", "Problem creating Image folder");
            ret = false;
        }
    }
    return ret;
}

-Evan

1 个答案:

答案 0 :(得分:1)

看一下如何使用MediaScannerConnection的这个例子:

http://www.java2s.com/Code/Android/Media/UsingMediaScannerConnection.htm

另请参阅其他问题答案中提供的CommonsWare链接:the MediaScannerConnection's static scanFile method

只是一个小注意事项:不要在名称中使用带有空格的文件夹名称...