1

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

对于getExternalStorageState ()Android 文档说:

公共静态字符串getExternalStorageState()

获取主要“外部”存储设备的当前状态。也可以看看

getExternalStorageDirectory()

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

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

4

1 回答 1

4

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()返回设备的路径名。

于 2013-08-16T19:05:16.397 回答