Example usage for android.os Environment getExternalStorageState

List of usage examples for android.os Environment getExternalStorageState

Introduction

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

Prototype

public static String getExternalStorageState() 

Source Link

Document

Returns the current state of the primary shared/external storage media.

Usage

From source file:Main.java

public static boolean hasExternalStorage() {
    Boolean externalStorage = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    return externalStorage;
}

From source file:Main.java

public static boolean hasExternalStorage() {
    Boolean externalStorage = Environment.getExternalStorageState()
            .equals(android.os.Environment.MEDIA_MOUNTED);
    return externalStorage;
}

From source file:Main.java

public static boolean checkSDcard() {
    return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}

From source file:Main.java

public static boolean isSDCardAvailable() {
    return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}

From source file:Main.java

public static File getCacheDir(Context context) {
    Log.i("getCacheDir", "cache sdcard state: " + Environment.getExternalStorageState());
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File cacheDir = context.getExternalCacheDir();
        if (cacheDir != null && (cacheDir.exists() || cacheDir.mkdirs())) {
            Log.i("getCacheDir", "cache dir: " + cacheDir.getAbsolutePath());
            return cacheDir;
        }//from   www  .jav  a2 s . c o m
    }

    File cacheDir = context.getCacheDir();
    Log.i("getCacheDir", "cache dir: " + cacheDir.getAbsolutePath());

    return cacheDir;
}

From source file:Main.java

private static boolean externalStorageAvailable() {
    return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}

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 va2s . co  m
    }
}

From source file:Main.java

/**
 * Creates a media file in the {@code Environment.DIRECTORY_PICTURES} directory. The directory
 * is persistent and available to other applications like gallery.
 *
 * @param type Media type. Can be video or image.
 * @return A file object pointing to the newly created file.
 *//*from   w w w.j  a v  a2  s . c om*/
public static File getOutputMediaFile(File myDir) {
    // To be safe, you should check that the SDCard is mounted
    // using Environment.getExternalStorageState() before doing this.
    Log.i("CameraSample", "about to check state of external storage");
    if (!Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) {
        Log.d("CameraSample", "externalstoragestate was " + Environment.getExternalStorageState());
        return null;
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    File mediaFile = new File(myDir + File.separator + "VID_" + timeStamp + ".mp4");

    return mediaFile;
}

From source file:Main.java

public static File getCacheDirectory(Context context, boolean preferExternal, String dirName) {
    File appCacheDir = null;/* w  w  w .  j a  v  a 2  s.c  o m*/
    if (preferExternal && MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            && hasExternalStoragePermission(context)) {
        appCacheDir = getExternalCacheDir(context, dirName);
        Log.e("appCacheDir", appCacheDir.toString());
    }
    if (appCacheDir == null) {
        appCacheDir = context.getCacheDir();
    }
    if (appCacheDir == null) {
        String cacheDirPath = "/data/data/" + context.getPackageName() + "/cache/";
        //Log.w("Can't define system cache directory! '%s' will be used.",cacheDirPath);
        appCacheDir = new File(cacheDirPath);
    }
    return appCacheDir;
}

From source file:Main.java

public static boolean isExtStorageAvailable() {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        return true;
    }/*from   w  w  w .  jav  a 2 s .  c om*/
    return false;
}