Bluetooth folder, different path on different phones

android, bluetooth

Solution

After some hours I made two methods for doing this. You should put the methods in a `AsyncTask` or a `Thread`. So here is my two methods:

public List<File> folderSearchBT(File src, String folder)
        throws FileNotFoundException {

    List<File> result = new ArrayList<File>();

    File[] filesAndDirs = src.listFiles();
    List<File> filesDirs = Arrays.asList(filesAndDirs);

    for (File file : filesDirs) {
        result.add(file); // always add, even if directory
        if (!file.isFile()) {
            List<File> deeperList = folderSearchBT(file, folder);
            result.addAll(deeperList);
        }
    }
    return result;
}

This is a recursive method which will add all folders in the `src` parameter into a List.

I use this method in this method here:

public String searchForBluetoothFolder() {

    String splitchar = "/";
    File root = Environment.getExternalStorageDirectory();
    List<File> btFolder = null;
    String bt = "bluetooth";
    try {
        btFolder = folderSearchBT(root, bt);
    } catch (FileNotFoundException e) {
        Log.e("FILE: ", e.getMessage());
    }

    for (int i = 0; i < btFolder.size(); i++) {

        String g = btFolder.get(i).toString();

        String[] subf = g.split(splitchar);

        String s = subf[subf.length - 1].toUpperCase();

        boolean equals = s.equalsIgnoreCase(bt);

        if (equals)
            return g;
    }
    return null; // not found
}

Hope this helps, guys!

Problem

I found out that different versions of android puts the received bluetooth files in different folder. For instance, one of my test phones running `android 2.2` saves the files to this path: ``` /mnt/sdcard/Downloads/Bluetooth ``` and my second test phone, running `android 4.0` saves the files here ``` /mnt/sdcard/Bluetooth ``` Is this operating system "issue" or is it set from the manufacture of the phone? If the first statement is the correct can I check which version of android running, and the point to the bluetooth folder? Or is there a much simpler way to do this? Thanks!

Original source