getExternalStorageDirectory

getExternalStorageDirectory

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

对于getExternalStorageState (),Android文档说:


  公共静态字符串getExternalStorageState()
  
  获取主“外部”存储设备的当前状态。看到
  也

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

09-11 18:23