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唯一标识(唯一序列号)
- Android arm64(aarch64)中的so注入(inject) - 兼容x86 and arm
- Multiple annotations found at this line: ---关于android string.xml %问题。
- Mars老师的Android学习基本路线
- android 静音与振动
- 教你用电脑从 Google Play 下载 Android 程序 apk 文件
- Android各种控件的事件监听
- Android Camera Subsystem 架构(Binder机制)及显示分析(3)
- Android串口通信(基于Tiny6410平台)
- 解决Android中Fragment调用startactivityforresult不能返回结果的问题
- Java URI 和 android Uri 中的 getSchemeSpecificPart() 方法
- android开源中国社区
- Android EditText总结
- Android计时器Chronometer-android学习之旅(二十一)
- Android GPS —— Location定位
- AndroidManifest.xml文件解析
- Android 动态设置TextView drawableLeft的方式
- Android之EventBus概述及源码解析(雷惊风)
- Android rom ram sd卡 区别
- android调试时apk可运行,导出签名的apk后闪退,报找不到class