首页 > 解决方案 > 检查 SD 卡是否可用

问题描述

我正在使用以下代码检查 SD 卡是否可用。但即使卡存在于我的 android 模拟器上,它也会返回 false。我可以通过手动进入设置来看到这一点。

public static final boolean isSDCardPresent(){
        Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
        Boolean isSDSupportedDevice = Environment.isExternalStorageRemovable();

        if(isSDSupportedDevice && isSDPresent) {
            return true;
        } else {
            return false;
        }
    }

为了提供更大的图景,我想做的是将文件下载到手机上的某个地方。我认为外部存储是正确的地方。

File soundDir = new File(Environment.getExternalStorageDirectory(), SOUND_DOWNLOAD_DIR);

但是当我这样做时 soudDir 不存在soundDir.exists()。为什么?

标签: androidandroid-external-storage

解决方案


您是否尝试过更改模拟器的 config.ini?检查你安装模拟器的位置,看看 hw.sdCard 是否设置为 yes,所以:

 hw.sdCard=yes

推荐阅读