Example usage for android.os Environment MEDIA_MOUNTED

List of usage examples for android.os Environment MEDIA_MOUNTED

Introduction

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

Prototype

String MEDIA_MOUNTED

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

Click Source Link

Document

Storage state if the media is present and mounted at its mount point with read/write access.

Usage

From source file:Main.java

public static String getAppCachePath(Context context) {
    String cachePath;/* w  w w  .j a  v a 2  s  . c  o  m*/
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        File externalCacheDir = context.getExternalCacheDir();
        // context.getExternalCacheDir() maybe null
        if (externalCacheDir == null) {
            cachePath = context.getCacheDir().getPath();
        } else {
            cachePath = externalCacheDir.getPath();
        }
    } else {
        cachePath = context.getCacheDir().getPath();
    }
    return cachePath;
}

From source file:Main.java

/**
 * Checks if external storage is available for read and write
 *//* www .j a va  2  s  . com*/
public static boolean isExternalStorageWritable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    }
    return false;
}

From source file:Main.java

public static Bitmap readImageFile(String fileName) {
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        return null;
    }/*from  ww  w  . java2s . co  m*/
    File file = new File(Environment.getExternalStorageDirectory().toString() + File.separator + fileName);
    if (!file.exists()) {
        return null;
    }
    return BitmapFactory.decodeFile(fileName);
}

From source file:Main.java

/** Returns true if external storage is readable. */
public static boolean isExtStorageReadable() {
    String state = Environment.getExternalStorageState();
    return Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state);
}

From source file:Main.java

public static File getDiskCacheDir(Context context, String uniqueName) {
    String cachePath;/* ww w .  j a v  a2  s .c  om*/
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        cachePath = context.getExternalCacheDir().getPath();
    } else {
        cachePath = context.getCacheDir().getPath();
    }
    return new File(cachePath + File.separator + uniqueName);
}

From source file:Main.java

/**
 * Checks if external storage is available for read and write.
 * @return True if external storage is writable. False otherwise.
 *///from   www .  j  a  v a 2  s .co  m
public static boolean isExternalStorageMounted() {
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        return true;
    }
    return false;
}

From source file:Main.java

public static void clearAllCache(Context context) {
    deleteDir(context.getCacheDir());/*ww w  . j a  va  2  s  . c  o  m*/
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        deleteDir(context.getExternalCacheDir());
    }
}

From source file:Main.java

public static void cleanExternalCache(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        deleteFilesByDirectory(context.getExternalCacheDir());
    }/*from   w  ww.  java  2 s .co m*/
}

From source file:Main.java

public static boolean hasStorage(boolean requireWriteAccess) {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        if (requireWriteAccess) {
            boolean writable = checkFsWritable();
            return writable;
        } else {//from   w  w w.j av a2 s .c om
            return true;
        }
    } else if (!requireWriteAccess && Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        return true;
    }
    return false;
}

From source file:Main.java

/**
 * Return if the state of the media is Mounted
 * // w ww .  j a  v  a  2 s. c o m
 * @return boolean if a SD is mounted on the device
 */
public static boolean isMediaMounted() {
    return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
}