[英]Finding SD-Card Path in Android 4.4 Kitkat
在我的一个应用程序中,我正在访问 SD 卡中的一些文件。 我正在使用以下函数来确定安装的 SD 卡路径。
File file = new File("/system/etc/vold.fstab");
FileReader fr = null;
BufferedReader br = null;
String path = "";
try {
fr = new FileReader(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
if (fr != null) {
br = new BufferedReader(fr);
String s = br.readLine();
while (s != null) {
if (s.startsWith("dev_mount")) {
String[] tokens = s.split("\\s");
path = tokens[2]; //mount_point
}
s = br.readLine();
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fr != null) {
fr.close();
}
if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return path;
这适用于 Kitkat 之前的所有设备。 但是在 Kitkat 版本中,我在第 1 行收到FileNotFoundException ,
File file = new File("/system/etc/vold.fstab");
我发现了很多关于在 Android kitkat 版本中更新 sd 卡权限的文章。但仍然有点困惑......请谁能帮我整理一下??? 提前致谢...
4.3 中不再使用vold.fstab。 相反,fstab。 现在存在。
您必须致电:
File sdCardPath = Environment.getExternalStorageDirectory();
知道SD卡的路径。 该函数调用系统操作函数来确定SD卡的路径。 并了解您必须使用的外部存储的状态
Environment.getExternalStorageState()
功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.