Question

How would i use the media scanner connection to make files visible to Android file transfer. referring to a question here (Android File Transfer cannot see a folder created by app)

currently im writing an app and just want to make sure the folder is there and if not create it. And ultimately the data in the folder will either need to be take out of the folder or more data added to it.

Thanks for the help a little confused with this scanner stuff.

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

Below is the method

    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

Was it helpful?

Solution

Have a look at this example on how to use the MediaScannerConnection:

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

Also have a look at the link CommonsWare provided in the answer from the other question: the MediaScannerConnection's static scanFile method

Just a small note: don't use folder names with whitespace in the names...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top