gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 03:31:01 24 4
gpt4 key购买 nike

我对 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com