java - getExternalStorageDirectory()和getExternalStorageState()的区别

标签 java android android-external-storage

我对 getExternalStorageDirectory ()getExternalStorageState () 之间的区别有点困惑。

对于 getExternalStorageState (),Android 文档说:

public static String getExternalStorageState ()

Gets the current state of the primary "external" storage device. See Also

getExternalStorageDirectory()

我会阅读这篇关于“外部”存储是否可用的文章,但它返回一个字符串。那么它是什么字符串呢?如果它是存储路径,那么它与 getExternalStorageDirectory() 有何不同,后者返回被视为“外部”存储的路径?如果不是路径,“状态”是什么?

有人可以澄清一下区别是什么,为什么你会使用一个而不是另一个?

最佳答案

来自 http://developer.android.com/reference/android/os/Environment.html 处的文档(请参阅顶部的常量部分):

String  MEDIA_BAD_REMOVAL   getExternalStorageState() returns MEDIA_BAD_REMOVAL if the media was removed before it was unmounted.
String  MEDIA_CHECKING  getExternalStorageState() returns MEDIA_CHECKING if the media is present and being disk-checked
String  MEDIA_MOUNTED   getExternalStorageState() returns MEDIA_MOUNTED if the media is present and mounted at its mount point with read/write access.
String  MEDIA_MOUNTED_READ_ONLY     getExternalStorageState() returns MEDIA_MOUNTED_READ_ONLY if the media is present and mounted at its mount point with read only access.
String  MEDIA_NOFS  getExternalStorageState() returns MEDIA_NOFS if the media is present but is blank or is using an unsupported filesystem
String  MEDIA_REMOVED   getExternalStorageState() returns MEDIA_REMOVED if the media is not present.
String  MEDIA_SHARED    getExternalStorageState() returns MEDIA_SHARED if the media is present not mounted, and shared via USB mass storage.
String  MEDIA_UNMOUNTABLE   getExternalStorageState() returns MEDIA_UNMOUNTABLE if the media is present but cannot be mounted.
String  MEDIA_UNMOUNTED     getExternalStorageState() returns MEDIA_UNMOUNTED if the media is present but not mounted.

它返回这些常量之一。

getExternalStorageDirectory() 返回设备的路径名。

关于java - getExternalStorageDirectory()和getExternalStorageState()的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18280351/

相关文章:

java - android java.io.File.fixSlashes(File.java :185)

java - 我有一个使用 Netbeans 的 swing 应用程序。我正在尝试将用户对象插入到数据库表中。但我收到以下错误

java - 为什么只有拉丁字符的 Java 字体声称支持亚洲字符,即使它不支持?

android - float AppCompatActivity

Android - 外部存储中保存的图像不会出现在图库中

sqlite - Xamarin.forms 备份 SQLite 数据库

java - 从存储在 HashMap 中的类创建新实例

java - 范围求和多线程

java - Firebase 数据库检索值,这可能吗

android - 机器人 :ScrollView Jerky and animation list not work