String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { // External storage is available } else { // External storage not available }
String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // External storage is writable or read-only } else { // External storage not available or not writable }Package library: This code requires the `android.os` package that is included in the Android SDK.