getExternalStorageDirectory()和getExternalStorageState()之间的区别

时间:2013-08-16 19:01:48

标签: java android android-external-storage

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

对于getExternalStorageState () Android文档说:

  

public static String getExternalStorageState()

     

获取主“外部”存储设备的当前状态。看到   还

getExternalStorageDirectory()

我会读到“外部”存储是否可用,但它会返回一个字符串。那是什么字符串呢?如果它是存储路径,那么它与getExternalStorageDirectory()的不同之处是什么,它将路径返回到被认为是“外部”存储的路径?如果它不是路径,那么“状态”是什么?

有人可以澄清区别是什么,以及为什么要使用其中一个?

1 个答案:

答案 0 :(得分: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()返回设备的路径名。