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

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

From source file:Main.java

public static long getFreeDiskSpace() {
    String status = Environment.getExternalStorageState();
    long freeSpace = 0;
    if (status.equals(Environment.MEDIA_MOUNTED)) {
        try {//from w w  w  .  j a v  a 2 s.c  o  m
            File path = Environment.getExternalStorageDirectory();
            StatFs stat = new StatFs(path.getPath());
            long blockSize = stat.getBlockSize();
            long availableBlocks = stat.getAvailableBlocks();
            freeSpace = availableBlocks * blockSize / 1024;
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        return -1;
    }
    return (freeSpace);
}

From source file:Main.java

public static final File getDownloadDir(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        return new File(context.getExternalCacheDir(), DOWNLOAD_DIR);
    }//ww w. j a v a2 s.  c om
    return new File(context.getCacheDir(), DOWNLOAD_DIR);
}

From source file:Main.java

public static File getDiskCacheDir(Context context, String uniqueName) {
    String cachePath;/*from   w w  w .  j ava2 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();
    }
    File file = new File(cachePath + File.separator + uniqueName);
    if (!file.exists() && !file.isDirectory()) {
        file.mkdir();
    }
    return file;
}

From source file:Main.java

@SuppressLint("SdCardPath")
public static String getSDPath() {
    File sdDir = null;// w w  w. j av  a2  s  . c  o m
    boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
    if (sdCardExist) {
        sdDir = Environment.getExternalStorageDirectory();
    }
    return sdDir.toString();
}

From source file:Main.java

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

From source file:Main.java

public static File getDiskCacheDir(Context context, String fileName) {
    String cachePath;/*from   w w  w.  j  a v a  2  s .c o m*/
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)
            && !Environment.isExternalStorageRemovable()) {
        cachePath = context.getExternalCacheDir().getPath();
    } else {
        cachePath = context.getCacheDir().getPath();
    }
    Log.d("bonus", "cachePath = " + cachePath);
    return new File(cachePath + File.separator + fileName);
}

From source file:Main.java

public static File getDiskCacheDir(Context context, String uniqueName) {
    String cachePath;//from  w ww  .j  a  v  a  2  s  .co  m
    if ((Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) && context.getExternalCacheDir() != null
            && !TextUtils.isEmpty(context.getExternalCacheDir().getPath())) {
        cachePath = context.getExternalCacheDir().getPath();
    } else {
        cachePath = context.getCacheDir().getPath();
    }
    return new File(cachePath + File.separator + uniqueName);
}

From source file:Main.java

public static String getQuranBaseDirectory() {
    String state = Environment.getExternalStorageState();
    if (state.equals(Environment.MEDIA_MOUNTED))
        return Environment.getExternalStorageDirectory() + QURAN_BASE;
    else//from w w  w  . j a  v a 2s.  c o  m
        return null;
}

From source file:Main.java

public static boolean hasSDCard(Context context) {
    if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
        String dir = Environment.getExternalStorageDirectory() + FILE_DIR;
        File f = new File(dir);
        if (!f.exists()) {
            f.mkdir();/*  ww  w. j  a v  a 2s.  c om*/
        } else {
            try {
                for (File t : f.listFiles()) {
                    t.delete();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return true;
    }
    return false;
}