Android 中的Storage state

查看源码可知,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;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android ,如果你想发送 AT 指令,可以通过串口通信的方式来实现。具体步骤如下: 1. 获取串口通信的权限。 在 AndroidManifest.xml 文件添加以下权限: ``` <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <uses-permission android:name="android.permission.SET_DEBUG_APP"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/> <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.WRITE_SETTINGS"/> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> <uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.WAKE_LOCK"/> ``` 2. 打开串口。 使用 Android 的 SerialPort 类打开串口,具体代码如下: ``` SerialPort mSerialPort = new SerialPort(new File("/dev/ttyS0"), 115200, 0); OutputStream mOutputStream = mSerialPort.getOutputStream(); InputStream mInputStream = mSerialPort.getInputStream(); ``` 3. 发送 AT 指令。 在获取到串口的输入输出流后,就可以通过输出流发送 AT 指令,具体代码如下: ``` String atCommand = "AT\r\n"; mOutputStream.write(atCommand.getBytes()); mOutputStream.flush(); ``` 4. 接收 AT 指令的响应。 在发送完 AT 指令后,可以通过输入流接收 AT 指令的响应,具体代码如下: ``` byte[] buffer = new byte[1024]; int size = mInputStream.read(buffer); if (size > 0) { String response = new String(buffer, 0, size); Log.d(TAG, "AT response: " + response); } ``` 以上就是在 Android 发送 AT 指令的基本步骤。当然,在实际的开发,可能还需要根据具体的需求进行一些调整和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值