没有 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/