【问题标题】:Retrieve the path to the external SD card on android在android上检索外部SD卡的路径
【发布时间】:2014-06-21 06:44:26
【问题描述】:

我的应用需要在手机存储中保存一些数据。用户可以选择数据保存的位置。我遇到了一个 HTC EVO 用户的问题,他没有看到我的应用程序中列出的外部卡。

我正在使用Environment.getExternalStorageDirectory().getAbsolutePath(),但这会导致内部 SD 卡,而不是外部 SD 卡。请告诉我我应该遵循什么路径(即使它是硬编码的)来列出他手机上的 ext sd?我想列出两张 SD 卡...1 个已列出,但另一张未显示...

【问题讨论】:

标签: android


【解决方案1】:

我不确定 HTC Evo,但不幸的是,当存在“/mnt/sdcard(内部)和 /mnt/sdcard-ext(外部)”等两张卡时,Android 无法处理这种情况。 getExternalStorageDirectory() 只会返回 /mnt/sdcard。

您可以使用 isExternalStorageRemovable() 检查它是内部存储还是外部存储。下面是这个方法的说明:

返回主“外部”存储设备是否可移动。如果返回 true,则此设备是例如用户可以移除的 SD 卡。如果返回 false,则表示存储在设备中,无法物理移除。

参考:http://developer.android.com/reference/android/os/Environment.html#isExternalStorageRemovable()

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    这应该可行:

    public static File getRemovableStorage() {
        final String value = System.getenv("SECONDARY_STORAGE");
        if (!TextUtils.isEmpty(value)) {
            final String[] paths = value.split(":");
            for (String path : paths) {
                File file = new File(path);
                if (file.isDirectory()) {
                    return file;
                }
            }
        }
        return null;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-15
      • 1970-01-01
      • 2012-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多