android - 设备要求外部存储,但我没有 SD 卡

标签 android android-sdcard

没有 SD 卡的三星 galaxy S3,我正在使用此代码检查存储状态。

使用这段代码:

boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {
    // We can read and write the media
    mExternalStorageAvailable = mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
    // We can only read the media
    mExternalStorageAvailable = true;
    mExternalStorageWriteable = false;
} else {
    // Something else is wrong. It may be one of many other states, but all we need
    //  to know is we can neither read nor write
    mExternalStorageAvailable = mExternalStorageWriteable = false;
}

所以如果这部手机出于某种原因将其内部存储器视为外部存储器,也许有人可以向我解释一下?或者什么?

最佳答案

getExternalStorageDirectory 并不总是返回 SDCard。

谷歌文档说:

"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."

“/mnt/sdcard”可能指的是您手机的内置存储空间。

最好检查getExternalStorageDirectory方法的返回路径是否是外部可移动存储。

您可以使用 Environment.isExternalStorageRemovable()用于检查它。

关于android - 设备要求外部存储,但我没有 SD 卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14556902/

相关文章:

Android ImageSwitcher - 切换图片时OutOfMemory(非常小)

android - 打包与其他应用程序共享的多个组件

android - fragment 中的 ViewModel 清除屏幕旋转时的值

java - 如何摆脱 "Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f01005e a=-1}"

Android 外部写入允许但文件未找到异常

android-5.0-lollipop - 如何通过为 Lollipop 提供的 API 随机访问 SD 卡上的文件?

android - 复杂的android多线程问题,寻找一些指导

android - 如何将Android SQLite数据库存储在sdcard中

android - ImageView:填充水平保持纵横比

android - 没有权限写入/mnt/extsd