android - 检查 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()
。为什么?
解决方案
您是否尝试过更改模拟器的 config.ini?检查你安装模拟器的位置,看看 hw.sdCard 是否设置为 yes,所以:
hw.sdCard=yes
推荐阅读
- android - 根据 Android 中的微调器选择删除 Firebase 子项
- php - PHP:反序列化 Java 的 BigInteger
- kotlin - 实体的主构造函数中的非空关系
- sql - 如何转入生成的列?
- javascript - 淘汰赛中的hasfocus事件在第一次点击时不起作用
- python - 缩放并在 iPython 中为 matplotlib 绘图设置光标
- python - 如何将参数分组为程序帮助消息的部分
- php - 有人可以帮我清理/合并代码吗
- c++ - c ++释放包含自定义类的向量的内存
- javascript - 如何在jquery中使用accounting.js从表中获取总价格?