gpt4 book ai didi

android - 未挂载 SD 卡时,Environment.getExternalStorageDirectory() 是否返回可用的数据文件夹?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:28:45 25 4
gpt4 key购买 nike

想象一下没有插入 SD 内存的 Android 设备。只有它自己的内部存储器。

我不确定在这种情况下 Environment.getExternalStorageDirectory() 会返回什么。

对于永久数据存储有效的空内存位置还是内部内存位置?

最佳答案

public static File getExternalStorageDirectory()

Added in API level 1

Gets the Android external storage directory. This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened. You can determine its current state with getExternalStorageState().

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.

我认为因设备而异。

我有一个 Samsung Galaxy S3 Environment.getExternalStorageDirectory() 返回 sdCard0 这是内部存储内存的路径。

更多信息@

http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()

我不会推荐以下内容。我与 Commonsware 就此进行了讨论,建议不要使用以下内容。但您可以使用以下内容进行测试。

String externalpath = new String();
String internalpath = new String();

public void getExternalMounts() {
Runtime runtime = Runtime.getRuntime();
try {
Process proc = runtime.exec("mount");
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
String line;

BufferedReader br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
if (line.contains("secure")) continue;
if (line.contains("asec")) continue;

if (line.contains("fat")) {//external card
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
externalpath = externalpath.concat("*" + columns[1] + "\n");
}
}
else if (line.contains("fuse")) {//internal storage
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
internalpath = internalpath.concat(columns[1] + "\n");
}
}
}
}
catch(Exception e) {
e.printStackTrace();
}
System.out.println("Path of sd card external............"+externalpath);
System.out.println("Path of internal memory............"+internalpath);
}

关于android - 未挂载 SD 卡时,Environment.getExternalStorageDirectory() 是否返回可用的数据文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17594212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com