Example usage for android.os Environment MEDIA_UNMOUNTABLE

List of usage examples for android.os Environment MEDIA_UNMOUNTABLE

Introduction

In this page you can find the example usage for android.os Environment MEDIA_UNMOUNTABLE.

Prototype

String MEDIA_UNMOUNTABLE

To view the source code for android.os Environment MEDIA_UNMOUNTABLE.

Click Source Link

Document

Storage state if the media is present but cannot be mounted.

Usage

From source file:Main.java

public static boolean storageReady() {
    String cardstatus = Environment.getExternalStorageState();
    if (cardstatus.equals(Environment.MEDIA_REMOVED) || cardstatus.equals(Environment.MEDIA_UNMOUNTABLE)
            || cardstatus.equals(Environment.MEDIA_UNMOUNTED)
            || cardstatus.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
        return false;
    } else {/*from   ww w.  j  a  v a  2s .  c om*/
        return true;
    }
}

From source file:Main.java

public static void verifyExternalStorageAvailability() {
    String cardstatus = Environment.getExternalStorageState();
    if (cardstatus.equals(Environment.MEDIA_REMOVED) || cardstatus.equals(Environment.MEDIA_UNMOUNTABLE)
            || cardstatus.equals(Environment.MEDIA_UNMOUNTED)
            || cardstatus.equals(Environment.MEDIA_MOUNTED_READ_ONLY)
            || cardstatus.equals(Environment.MEDIA_SHARED)) {
        RuntimeException e = new RuntimeException(
                "ODK reports :: SDCard error: " + Environment.getExternalStorageState());
        throw e;//  ww w  . j  ava  2  s  .  com
    }
}

From source file:Main.java

private static boolean isStorageReady() {
    String cardstatus = Environment.getExternalStorageState();
    if (cardstatus.equals(Environment.MEDIA_REMOVED) || cardstatus.equals(Environment.MEDIA_UNMOUNTED)
            || cardstatus.equals(Environment.MEDIA_UNMOUNTABLE)
            || cardstatus.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
        return false;
    } else {//from   w w  w.  java2 s  .c  om
        if (cardstatus.equals(Environment.MEDIA_MOUNTED)) {
            return true;
        } else {
            return false;
        }
    }
}

From source file:Main.java

/**
 * Returns the current state of the storage device that provides the given path.
 * @param state "getExternalStorageState()"
 *//*w w  w.j a  v  a2 s  .  c om*/
public static String getExternalStorageState(String state) {
    if (TextUtils.isEmpty(state)) {
        return UNKNOWN;
    }

    switch (state) {
    case Environment.MEDIA_BAD_REMOVAL://bad_removal
        return "MEDIA_BAD_REMOVAL";
    case Environment.MEDIA_CHECKING://checking
        return "MEDIA_CHECKING";
    case Environment.MEDIA_EJECTING://ejecting
        return "MEDIA_EJECTING";
    case Environment.MEDIA_MOUNTED://mounted
        return "MEDIA_MOUNTED";
    case Environment.MEDIA_MOUNTED_READ_ONLY://mounted_read_only
        return "MEDIA_MOUNTED_READ_ONLY";
    case Environment.MEDIA_NOFS://nofs
        return "MEDIA_NOFS";
    case Environment.MEDIA_REMOVED://removed
        return "MEDIA_REMOVED";
    case Environment.MEDIA_SHARED://shared
        return "MEDIA_SHARED";
    case Environment.MEDIA_UNKNOWN://unknown
        return "MEDIA_UNKNOWN";
    case Environment.MEDIA_UNMOUNTABLE://unmountable
        return "MEDIA_UNMOUNTABLE";
    case Environment.MEDIA_UNMOUNTED://unmounted
        return "MEDIA_UNMOUNTED";
    default:
        return UNKNOWN;
    }
}

From source file:org.digitalcampus.oppia.utils.FileUtils.java

public static boolean createDirs(Context ctx) {
    String cardstatus = Environment.getExternalStorageState();
    if (cardstatus.equals(Environment.MEDIA_REMOVED) || cardstatus.equals(Environment.MEDIA_UNMOUNTABLE)
            || cardstatus.equals(Environment.MEDIA_UNMOUNTED)
            || cardstatus.equals(Environment.MEDIA_MOUNTED_READ_ONLY)
            || cardstatus.equals(Environment.MEDIA_SHARED)) {
        Log.d(TAG, "card status: " + cardstatus);
        return false;
    }// ww  w  .j  ava 2s. co  m

    String[] dirs = { FileUtils.getCoursesPath(ctx), FileUtils.getMediaPath(ctx),
            FileUtils.getDownloadPath(ctx) };

    for (String dirName : dirs) {
        File dir = new File(dirName);
        if (!dir.exists()) {
            if (!dir.mkdirs()) {
                Log.d(TAG, "can't mkdirs");
                return false;
            }
        } else {
            if (!dir.isDirectory()) {
                Log.d(TAG, "not a directory");
                return false;
            }
        }
    }

    return true;
}

From source file:com.mpower.mintel.android.application.MIntel.java

/**
 * Creates required directories on the SDCard (or other external storage)
 * //from ww  w  .  j a  v a  2s. c o m
 * @throws RuntimeException
 *             if there is no SDCard or the directory exists as a non
 *             directory
 */
public static void createMIntelDirs() throws RuntimeException {
    String cardstatus = Environment.getExternalStorageState();
    if (cardstatus.equals(Environment.MEDIA_REMOVED) || cardstatus.equals(Environment.MEDIA_UNMOUNTABLE)
            || cardstatus.equals(Environment.MEDIA_UNMOUNTED)
            || cardstatus.equals(Environment.MEDIA_MOUNTED_READ_ONLY)
            || cardstatus.equals(Environment.MEDIA_SHARED)) {
        RuntimeException e = new RuntimeException(
                "mIntel reports :: SDCard error: " + Environment.getExternalStorageState());
        throw e;
    }

    String[] dirs = { MINTEL_ROOT, FORMS_PATH, INSTANCES_PATH, CACHE_PATH, METADATA_PATH, PRESCRIPTION_PATH };

    for (String dirName : dirs) {
        File dir = new File(dirName);
        if (!dir.exists()) {
            if (!dir.mkdirs()) {
                RuntimeException e = new RuntimeException(
                        "mIntel reports :: Cannot create directory: " + dirName);
                throw e;
            }
        } else {
            if (!dir.isDirectory()) {
                RuntimeException e = new RuntimeException(
                        "mIntel reports :: " + dirName + " exists, but is not a directory");
                throw e;
            }
        }
    }

    String[] fileNames = { "pres_n.ogg", "call_n.ogg" };
    copyAudioFiles(fileNames);
}

From source file:org.digitalcampus.oppia.utils.storage.ExternalStorageStrategy.java

public boolean isStorageAvailable(Context ctx) {
    String cardStatus = Environment.getExternalStorageState();
    if (cardStatus.equals(Environment.MEDIA_REMOVED) || cardStatus.equals(Environment.MEDIA_UNMOUNTABLE)
            || cardStatus.equals(Environment.MEDIA_UNMOUNTED)
            || cardStatus.equals(Environment.MEDIA_MOUNTED_READ_ONLY)
            || cardStatus.equals(Environment.MEDIA_SHARED)) {
        Log.d(TAG, "card status: " + cardStatus);
        return false;
    } else {/*  w w  w.  j a v a 2 s  .  c  o  m*/
        return true;
    }
}

From source file:com.radicaldynamic.groupinform.application.Collect.java

/**
 * Creates required directories on the SDCard (or other external storage)
 * @throws RuntimeException if there is no SDCard or the directory exists as a non directory
 */// www  .  ja v a 2  s .co m
public static void createODKDirs() throws RuntimeException {
    String cardstatus = Environment.getExternalStorageState();
    if (cardstatus.equals(Environment.MEDIA_REMOVED) || cardstatus.equals(Environment.MEDIA_UNMOUNTABLE)
            || cardstatus.equals(Environment.MEDIA_UNMOUNTED)
            || cardstatus.equals(Environment.MEDIA_MOUNTED_READ_ONLY)
            || cardstatus.equals(Environment.MEDIA_SHARED)) {
        RuntimeException e = new RuntimeException(
                "ODK reports :: SDCard error: " + Environment.getExternalStorageState());
        throw e;
    }

    String[] dirs = { ODK_ROOT, FORMS_PATH, INSTANCES_PATH, CACHE_PATH, METADATA_PATH };

    for (String dirName : dirs) {
        File dir = new File(dirName);
        if (!dir.exists()) {
            if (!dir.mkdirs()) {
                RuntimeException e = new RuntimeException("ODK reports :: Cannot create directory: " + dirName);
                throw e;
            }
        } else {
            if (!dir.isDirectory()) {
                RuntimeException e = new RuntimeException(
                        "ODK reports :: " + dirName + " exists, but is not a directory");
                throw e;
            }
        }
    }
}

From source file:it.fabaris.wfp.application.Collect.java

/**
 * Creates required directories on the SDCard (or other external storage)
 * @throws RuntimeException if there is no SDCard or the directory exists as a non directory
 *//*from   w w  w.  j  av a  2 s. c  om*/
public static void createODKDirs() throws RuntimeException {
    String cardstatus = Environment.getExternalStorageState();

    if (cardstatus.equals(Environment.MEDIA_REMOVED) || cardstatus.equals(Environment.MEDIA_UNMOUNTABLE)
            || cardstatus.equals(Environment.MEDIA_UNMOUNTED)
            || cardstatus.equals(Environment.MEDIA_MOUNTED_READ_ONLY)
            || cardstatus.equals(Environment.MEDIA_SHARED)) {
        RuntimeException e = new RuntimeException(
                "ODK reports :: SDCard error: " + Environment.getExternalStorageState());
        throw e;
    }

    String[] dirs = { FABARISODK_ROOT, FORMS_PATH, INSTANCES_PATH, CACHE_PATH, METADATA_PATH };
    //        String[] dirs_Ext = {FABARISODK_ROOT_Ext, FORMS_PATH_Ext, INSTANCES_PATH_Ext, CACHE_PATH_Ext, METADATA_PATH_Ext};

    for (String dirName : dirs) {
        File dir = new File(dirName);

        if (!dir.exists()) {
            if (!dir.mkdirs()) {
                RuntimeException e = new RuntimeException("ODK reports :: Cannot create directory: " + dirName);
                throw e;
            }
        } else {
            if (!dir.isDirectory()) {
                RuntimeException e = new RuntimeException(
                        "ODK reports :: " + dirName + " exists, but is not a directory");
                throw e;
            }
        }
    }
}

From source file:org.opendatakit.utilities.ODKFileUtils.java

public static void verifyExternalStorageAvailability() {
    String cardstatus = Environment.getExternalStorageState();
    if (cardstatus.equals(Environment.MEDIA_REMOVED) || cardstatus.equals(Environment.MEDIA_UNMOUNTABLE)
            || cardstatus.equals(Environment.MEDIA_UNMOUNTED)
            || cardstatus.equals(Environment.MEDIA_MOUNTED_READ_ONLY)
            || cardstatus.equals(Environment.MEDIA_SHARED)) {
        throw new RuntimeException("ODK reports :: SDCard error: " + Environment.getExternalStorageState());
    }/*from  ww w . j  a va2 s.  co m*/
}