Example usage for android.os Environment getExternalStorageDirectory

List of usage examples for android.os Environment getExternalStorageDirectory

Introduction

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

Prototype

public static File getExternalStorageDirectory() 

Source Link

Document

Return the primary shared/external storage directory.

Usage

From source file:Main.java

/**
 * Returns the number of total bytes on the storage.
 *//*from w w  w .  jav a 2 s.  c  om*/
public static long getTotalSpaceInBytes() {
    return Environment.getExternalStorageDirectory().getTotalSpace();
}

From source file:Main.java

public static File getConfigFile(final String filename) {
    final File configFolder = new File(Environment.getExternalStorageDirectory(), CARDBOARD_CONFIG_FOLDER);
    if (!configFolder.exists()) {
        configFolder.mkdirs();//from   ww w.j  av  a 2  s  .  com
    } else if (!configFolder.isDirectory()) {
        final String value = String.valueOf(String.valueOf(configFolder));
        throw new IllegalStateException(
                new StringBuilder().append("Folder ").append(value).append(" already exists").toString());
    }
    return new File(configFolder, filename);
}

From source file:Main.java

/**
 * Get the file write directory (Mostly used on APIs KitKat+)
 * @return// w  ww.j a  v  a2s  . c  om
 */
public static String getFileWriteDirectory() {
    String str = Environment.getExternalStorageDirectory().getPath();
    return str;
}

From source file:Main.java

public static File getProperApplicationExternalDirectory(Context c) {

    File ret = new File(Environment.getExternalStorageDirectory().toString() + "/Android/data/"
            + c.getPackageName() + "/files/");

    ret.mkdirs();//from ww  w.java  2 s . c  om

    return ret;
}

From source file:Main.java

static String getSetting(String name) {
    File file = new File(Environment.getExternalStorageDirectory().toString() + "/.Instagram/" + name + ".txt");
    StringBuilder text = new StringBuilder();

    try {/*  w  w w  .ja v  a  2 s. c o m*/
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line;

        while ((line = br.readLine()) != null) {
            text.append(line);
        }
        br.close();
    } catch (IOException e) {
        text.append("Instagram");
    }

    return text.toString();
}

From source file:Main.java

public static void writeStringAsFile(final String fileContents, String fileName) {
    try {/*from  www . jav a 2  s.  com*/
        String path = Environment.getExternalStorageDirectory().getAbsolutePath();
        FileWriter out = new FileWriter(new File(path, fileName));
        out.write(fileContents);
        out.close();
    } catch (IOException e) {
        //!TODO
    }
}

From source file:Main.java

public static List<String> ListFile() {

    File file = new File(Environment.getExternalStorageDirectory() + "/rectPhoto/");
    File[] f = file.listFiles();/*from  www.  j  a v a 2 s. c  o m*/
    List<String> datas = new ArrayList<String>();
    //      String Path[] = new String[f.length];
    for (int i = 0; i < f.length; i++) {

        //         Path[i] = f[i].getPath();
        datas.add(f[i].getPath());
    }

    return datas;

}

From source file:Main.java

public static boolean existExternalStorageDirectory() {
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            && Environment.getExternalStorageDirectory().canWrite()) {

        return true;
    }//from w  w w  .  ja v a 2 s.c om

    return false;
}

From source file:Main.java

public static boolean GetSdCardFile() {
    String str = Environment.getExternalStorageState();
    return (!IsEmpty(str)) && ((str.equals("mounted")) || (str.equals("mounted_ro")))
            && (Environment.getExternalStorageDirectory() != null);
}

From source file:Main.java

public static long getSDCardAvailableAtKB() {
    StatFs sfs = new StatFs(Environment.getExternalStorageDirectory().getPath());
    long availableCount = sfs.getAvailableBlocks();
    long blockSizea = sfs.getBlockSize();
    return (availableCount * blockSizea) / 1024;
}