您的位置:首页 > 移动开发 > Android开发

Android 中的Storage state

2017-10-20 17:53 127 查看
查看源码可知,android中的storage state 共有以下几种状态
/*** Unknown storage state, such as when a path isn't backed by known storage* media.** @see #getExternalStorageState(File)*/public static final String MEDIA_UNKNOWN = "unknown";    未知/*** Storage state if the media is not present.** @see #getExternalStorageState(File)*/public static final String MEDIA_REMOVED = "removed";/*** Storage state if the media is present but not mounted.** @see #getExternalStorageState(File)*/public static final String MEDIA_UNMOUNTED = "unmounted";/*** Storage state if the media is present and being disk-checked.** @see #getExternalStorageState(File)*/public static final String MEDIA_CHECKING = "checking";/*** Storage state if the media is present but is blank or is using an* unsupported filesystem.** @see #getExternalStorageState(File)*/public static final String MEDIA_NOFS = "nofs";/*** Storage state if the media is present and mounted at its mount point with* read/write access.** @see #getExternalStorageState(File)*/public static final String MEDIA_MOUNTED = "mounted";/*** Storage state if the media is present and mounted at its mount point with* read-only access.** @see #getExternalStorageState(File)*/public static final String MEDIA_MOUNTED_READ_ONLY = "mounted_ro";/*** Storage state if the media is present not mounted, and shared via USB* mass storage.** @see #getExternalStorageState(File)*/public static final String MEDIA_SHARED = "shared";/*** Storage state if the media was removed before it was unmounted.** @see #getExternalStorageState(File)*/public static final String MEDIA_BAD_REMOVAL = "bad_removal";/*** Storage state if the media is present but cannot be mounted. Typically* this happens if the file system on the media is corrupted.** @see #getExternalStorageState(File)*/public static final String MEDIA_UNMOUNTABLE = "unmountable";/*** Storage state if the media is in the process of being ejected.** @see #getExternalStorageState(File)*/public static final String MEDIA_EJECTING = "ejecting";  
以上这些状态中
/*** Storage state if the media is present and mounted at its mount point with* read/write access.** @see #getExternalStorageState(File)*/public static final String MEDIA_MOUNTED = "mounted";
以上的这些状态中只有mounted 状态是同时可读可写的
/*** Storage state if the media is present and mounted at its mount point with* read-only access.** @see #getExternalStorageState(File)*/public static final String MEDIA_MOUNTED_READ_ONLY = "mounted_ro";
mounted_ro 有读的权限,无写的权限。
结论:
因此,在文件读写的时候,通常会这么判断
if (
Environment.MEDIA_MOUNTED
.equals(
Environment.getExternalStorageState()
)){
}
else{
return null;
}

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android