how to check internal and external storage if exist

oczdref picture oczdref · Oct 1, 2011 · Viewed 30k times · Source

How do i know if there are internal and external storage in android pragmatically? does anyone how to know how to check both internal and external storage

thanks in advance

Answer

ariefbayu picture ariefbayu · Oct 1, 2011

it's already explained in android documentation.

Code taken from documentation

boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {
    // We can read and write the media
    mExternalStorageAvailable = mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
    // We can only read the media
    mExternalStorageAvailable = true;
    mExternalStorageWriteable = false;
} else {
    // Something else is wrong. It may be one of many other states, but all we need
    //  to know is we can neither read nor write
    mExternalStorageAvailable = mExternalStorageWriteable = false;
}