Example usage for android.os Environment MEDIA_REMOVED

List of usage examples for android.os Environment MEDIA_REMOVED

Introduction

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

Prototype

String MEDIA_REMOVED

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

Click Source Link

Document

Storage state if the media is not present.

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 {// ww  w.j av a2  s  .  c o  m
        return true;
    }
}

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 {// w  w  w .ja v a 2s  . c o m
        if (cardstatus.equals(Environment.MEDIA_MOUNTED)) {
            return true;
        } else {
            return false;
        }
    }
}

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;/*from   w w  w  .  ja  va 2 s  .c  o  m*/
    }
}

From source file:Main.java

/**
 * Returns the current state of the storage device that provides the given path.
 * @param state "getExternalStorageState()"
 *///  ww  w .  ja  va  2  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;
    }/*  w  w w.  ja va  2s  .  c o  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)
 * /*  w w  w  . j  a  v  a2s .com*/
 * @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 {/*from  w ww  .j a va  2s .c om*/
        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
 *///from  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 ava 2  s .c  o  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 = { 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:com.att.android.arodatacollector.utils.AROCollectorUtils.java

/**
 * Returns a value indicating whether or not the device SD card is mounted.
 * /*from  w w w  .j  a  v a  2s  . c o  m*/
 * @return A boolean value that is "true" if the SD card is mounted, and
 *         "false" if it is not.
 */
public boolean checkSDCardMounted() {
    final String state = Environment.getExternalStorageState();
    if (state.equals(Environment.MEDIA_REMOVED) || !state.equals(Environment.MEDIA_MOUNTED)
            || state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
        return true;
    } else {
        return false;
    }
}