سؤال

I'm a little confused about the difference between getExternalStorageDirectory () and getExternalStorageState ().

For getExternalStorageState () the Android docs say:

public static String getExternalStorageState ()

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

getExternalStorageDirectory()

I would read this as to whether or not "external" storage is available, but it returns a string. So what string is it? If it is the path to the storage then how is it different than getExternalStorageDirectory() which returns the path to what is considered the "external" storage? What is the "state" if it isn't the path?

Can someone please clarify what the difference is, and why you would use one over the other?

هل كانت مفيدة؟

المحلول

From the documentation at http://developer.android.com/reference/android/os/Environment.html (see the Constants section at the top):

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.

It returns one of those constants.

getExternalStorageDirectory() returns the path name to the device.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top