3

我是android的初学者。如何找到内部sd卡的路径,然后如何找到它们的已用空间和可用空间。请回复您的意见和答案对我很有价值。

4

5 回答 5

4

Environment.getExternalStorageDirectory().getAbsolutePath()给你 SD 卡路径。

要获得外部 SD 卡的可用“可用”空间,请使用以下代码段。

StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
double sdAvailSize = (double)stat.getAvailableBlocks()
                   * (double)stat.getBlockSize();
//One binary gigabyte equals 1,073,741,824 bytes.
double gigaAvailable = sdAvailSize / 1073741824;
于 2012-06-17T09:06:46.170 回答
2

如何查找内部 SD 卡路径和外部 SD 卡路径

你没有。

此时,从 Android SDK 的角度来看,没有“内部 SD 卡路径”或“外部 SD 卡路径”。有到外部存储的路径,它由Environment(例如,getExternalStorageDirectory())上的各种方法返回。这将是设备制造商为此目的指定的任何存储。

没有可靠的方法来确定 Android 设备上任何其他潜在的“SD 卡路径”。

于 2012-06-17T10:38:01.343 回答
1

查看有关访问 sd 卡的 android 文档:http: //developer.android.com/guide/topics/data/data-storage.html#filesExternal

于 2012-06-17T09:06:14.783 回答
0

使用下面的代码,它将为您返回具有内部和外部存储设备的内部目录路径和 sdcard 路径的列表。

File dir = new File(Environment.getExternalStorageDirectory().getParent());
            File[] f = dir.listFiles();
            for(File file:f)
        {
            if(file.getName().equals("sdacard0"))//check name of sdcard from  file manager.
            {
                if(file.isDirectory())
                {
                    f = file.listFiles();
                }
            }
        }
于 2014-03-12T12:26:56.303 回答
0

There's always System.getenv(ENV_EXTERNAL_STORAGE) from android.os:

Other Examples from source code:

public static File getExternalStorageDirectory() {
    throwIfUserRequired();
    return sCurrentUser.getExternalDirs()[0];
}

/** {@hide} */
public static File getLegacyExternalStorageDirectory() {
    return new File(System.getenv(ENV_EXTERNAL_STORAGE));
}

/** {@hide} */
public static File getLegacyExternalStorageObbDirectory() {
    return buildPath(getLegacyExternalStorageDirectory(), DIR_ANDROID, DIR_OBB);
}

Environment.java

private static final String ENV_EXTERNAL_STORAGE = "EXTERNAL_STORAGE";
private static final String ENV_ANDROID_ROOT = "ANDROID_ROOT";
private static final String ENV_ANDROID_DATA = "ANDROID_DATA";
private static final String ENV_ANDROID_EXPAND = "ANDROID_EXPAND";
private static final String ENV_ANDROID_STORAGE = "ANDROID_STORAGE";
private static final String ENV_DOWNLOAD_CACHE = "DOWNLOAD_CACHE";
private static final String ENV_OEM_ROOT = "OEM_ROOT";
private static final String ENV_ODM_ROOT = "ODM_ROOT";
private static final String ENV_VENDOR_ROOT = "VENDOR_ROOT";

/** {@hide} */
public static final String DIR_ANDROID = "Android";
private static final String DIR_DATA = "data";
private static final String DIR_MEDIA = "media";
private static final String DIR_OBB = "obb";
private static final String DIR_FILES = "files";
private static final String DIR_CACHE = "cache";

/** {@hide} */
@Deprecated
public static final String DIRECTORY_ANDROID = DIR_ANDROID;

private static final File DIR_ANDROID_ROOT = getDirectory(ENV_ANDROID_ROOT, "/system");
private static final File DIR_ANDROID_DATA = getDirectory(ENV_ANDROID_DATA, "/data");
private static final File DIR_ANDROID_EXPAND = getDirectory(ENV_ANDROID_EXPAND, "/mnt/expand");
private static final File DIR_ANDROID_STORAGE = getDirectory(ENV_ANDROID_STORAGE, "/storage");
private static final File DIR_DOWNLOAD_CACHE = getDirectory(ENV_DOWNLOAD_CACHE, "/cache");
private static final File DIR_OEM_ROOT = getDirectory(ENV_OEM_ROOT, "/oem");
private static final File DIR_ODM_ROOT = getDirectory(ENV_ODM_ROOT, "/odm");
private static final File DIR_VENDOR_ROOT = getDirectory(ENV_VENDOR_ROOT, "/vendor");

Source

sources\android-25\android\os\Environment.java

于 2018-11-15T19:40:38.733 回答