蓝牙文件夹,不同手机路径不同 [英] Bluetooth folder, different path on different phones
问题描述
我发现不同版本的android将接收到的蓝牙文件放在不同的文件夹中.例如,我的一部运行 android 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
和我的第二个测试手机,运行 android 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
或 Thread
中.所以这是我的两种方法:
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屋!