蓝牙文件夹,在不同的手机不同的路径 [英] Bluetooth folder, different path on different phones

查看:236
本文介绍了蓝牙文件夹,在不同的手机不同的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现不同的Andr​​oid版本把不同的文件夹中接收到的蓝牙文件。例如,我的测试手机之一运行的Andr​​oid 2.2 将文件保存到该路径:

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

和我的第二次​​测试的手机,运行的Andr​​oid 4.0 这里保存文件

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?

如果第一个说法是正确的,我可以检查Android操作系统的版本,并点到蓝牙文件夹?或者是有一个更简单的方式做到这一点?

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?

谢谢!

推荐答案

某些小时后我做了两种方法来这样做。你应该把这些方法在的AsyncTask 。因此,这里是我的两个方法:

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;
}

这是这将增加所有文件夹中的的src 参数到列表的递归方法。

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!

这篇关于蓝牙文件夹,在不同的手机不同的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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