Android Phone 的 SD 卡路径
Sd Card Path of Android Phone
我正在尝试制作一个文件浏览器应用程序。所以我想开始展示这样的东西。
但是我无法到达我的 SD 卡的路径。我用了这个方法
String path = Environment.getExternalStorageDirectory();
在文档中 here 它说:
Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.
问题是我可以访问设备存储,但无法访问我的 SD 卡路径。有谁知道如何获得那条路?
// Access the built-in SD card
private String getInnerSDCardPath() {
return Environment.getExternalStorageDirectory().getPath();
}
// Access to external SD card
private List<String> getExtSDCardPath() {
List<String> pathList = new ArrayList<String>();
try {
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("mount");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null) {
if (line.contains("extSdCard")) {
String[] arr = line.split(" ");
String path = arr[1];
File file = new File(path);
if (file.isDirectory()) {
pathList.add(path);
}
}
}
bufferedReader.close();
} catch (Exception e) {
e.printStackTrace();
}
return pathList;
}
希望对您有所帮助
我正在尝试制作一个文件浏览器应用程序。所以我想开始展示这样的东西。
但是我无法到达我的 SD 卡的路径。我用了这个方法
String path = Environment.getExternalStorageDirectory();
在文档中 here 它说:
Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.
问题是我可以访问设备存储,但无法访问我的 SD 卡路径。有谁知道如何获得那条路?
// Access the built-in SD card
private String getInnerSDCardPath() {
return Environment.getExternalStorageDirectory().getPath();
}
// Access to external SD card
private List<String> getExtSDCardPath() {
List<String> pathList = new ArrayList<String>();
try {
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("mount");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null) {
if (line.contains("extSdCard")) {
String[] arr = line.split(" ");
String path = arr[1];
File file = new File(path);
if (file.isDirectory()) {
pathList.add(path);
}
}
}
bufferedReader.close();
} catch (Exception e) {
e.printStackTrace();
}
return pathList;
}
希望对您有所帮助