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

/**
 * Check the external storage status//w w  w .  j a va  2s . c om
 * 
 * @return
 */
public static boolean isExternalStorageAvilable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    }
    return false;
}

From source file:Main.java

public static String getSdCacheDir(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {

        if (true) {
            Context appContext = context.getApplicationContext();

            File amap = appContext.getExternalFilesDir("offlineMap");
            return amap.getAbsolutePath() + "/";
        } else {// w w  w  .j  a  v a2  s  .c  om

            File fExternalStorageDirectory = Environment.getExternalStorageDirectory();
            File autonaviDir = new File(fExternalStorageDirectory, "amapsdk");
            boolean result = false;
            if (!autonaviDir.exists()) {
                result = autonaviDir.mkdir();
            }
            File minimapDir = new File(autonaviDir, "offlineMap");
            if (!minimapDir.exists()) {
                result = minimapDir.mkdir();
            }
            return minimapDir.toString() + "/";
        }

    } else {
        return "";
    }
}

From source file:Main.java

/**
 * check whether or not ExternalStorage is available
 *
 * @return true if externalStorage is available,false otherwise
 */// w w  w .j ava2  s.  c o  m
public static boolean isSDCARDMounted() {
    return Environment.getExternalStorageState().contentEquals(Environment.MEDIA_MOUNTED);
}

From source file:Main.java

public static boolean checkSdCard() {
    //        if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        isSdCard = true;/*from   www.j  a va 2s . co m*/
    } else {
        isSdCard = false;
    }
    return isSdCard;
}

From source file:Main.java

/**
 * Simple helper to ensure that we can write to Android filesystem.
 * @return//  www .j  av a 2s . c  o  m
 */
public static boolean isExternalStorageWritable() {
    try {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            return true;
        }
        return false;
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

/**
 * Checks if the external Storage is available
 * @return/* w w  w  . ja v a 2  s  .c om*/
 */
public static boolean isExternalStorageAvailable() {
    String state = Environment.getExternalStorageState();
    if (state.equals(Environment.MEDIA_MOUNTED)) {
        return true;
    } else {
        return false;
    }
}

From source file:Main.java

public static Uri createUri(String foldername) {
    String storageState = Environment.getExternalStorageState();
    if (storageState.equals(Environment.MEDIA_MOUNTED)) {
        final File root = new File(
                Environment.getExternalStorageDirectory() + File.separator + foldername + File.separator);
        root.mkdirs();/*ww w .  j av a 2 s.com*/
        final String fname = getUniqueImageFilename(foldername);
        final File sdImageMainDirectory = new File(root, fname);
        return Uri.fromFile(sdImageMainDirectory);
    }
    return null;
}

From source file:Main.java

public static String showFileAvailable() {
    String result = "";
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        StatFs sf = new StatFs(Environment.getExternalStorageDirectory().getPath());
        long blockSize = sf.getBlockSize();
        long blockCount = sf.getBlockCount();
        long availCount = sf.getAvailableBlocks();
        return showFileSize(availCount * blockSize) + " / " + showFileSize(blockSize * blockCount);
    }//from w  w  w  .  j a  v  a 2  s  . c o  m
    return result;
}

From source file:Main.java

public static boolean checkSDCard() {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        return true;
    } else {//from   w w w  .  jav  a  2  s.  com
        return false;
    }
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static File getDiskCacheDir(Context context, String uniqueName) {
    String cachePath;/*  w  ww .j  a v a 2s  .c  om*/
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageEmulated()) {
        cachePath = context.getExternalCacheDir().getPath();
    } else {
        cachePath = context.getCacheDir().getPath();
    }

    return new File(cachePath + File.separator + uniqueName);
}