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

public static long getAvailableStorage() {
    try {//from w w  w .  java2s .  com
        String storageDirectory = Environment.getExternalStorageDirectory().toString();
        StatFs stat = new StatFs(storageDirectory);
        return (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
    } catch (Exception e) {
        // if we can't stat the filesystem then we don't know how many
        // pictures are remaining. it might be zero but just leave it
        // blank since we really don't know.
        return 0;
    }
}

From source file:Main.java

public static File getExternalStorageDir(String dir) {
    File result = new File(Environment.getExternalStorageDirectory(), dir);

    if (!isExternalStorageWritable()) {
        return null;
    }//w  w  w.j a v a  2s. c o m

    if (!result.exists() && !result.mkdirs()) {
        return null;
    }

    return result;
}

From source file:Main.java

public static File getSDCardSoPath() {
    String fileStr = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator;
    File f = new File(fileStr);
    if (!f.exists()) {
        f.mkdirs();/*from  w w  w  .  j  a  va  2s .c om*/
    }
    return f;
}

From source file:Main.java

public static void createDirectoryIfNotExists(String directoryName) {
    File recordingsDirectory = new File(Environment.getExternalStorageDirectory(), directoryName);
    if (!recordingsDirectory.exists()) {
        recordingsDirectory.mkdir();/*w  ww  . j  a  v a 2s .c  om*/
    }
}

From source file:Main.java

public static int freeSpaceOnSd() {
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    double sdFreeMB = ((double) stat.getAvailableBlocks() * (double) stat.getBlockSize()) / MB;

    return (int) sdFreeMB;
}

From source file:Main.java

public static void createCSV() {
    File folder = new File(Environment.getExternalStorageDirectory() + "/adspammer");
    if (!folder.exists())
        folder.mkdir();// w w w . ja  va 2s . c  o  m

    String filename = folder.toString() + "/" + "log.csv";

    File csvFile = new File(filename);
    if (!csvFile.exists())
        try {
            csvFile.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }

}

From source file:Main.java

public static String GetSdcardPath() {
    return Environment.getExternalStorageDirectory() + CACHE_FILE;
}

From source file:Main.java

public static String getAvaibleSDCardPath() {
    String str = Environment.getExternalStorageDirectory().getAbsolutePath();
    if (!Environment.getExternalStorageState().equals("mounted")) {
        str = INTERNAL_CARD;/*from   www. j  av a  2s  .co m*/
    }
    return str;
}

From source file:Main.java

public static String getDataDirectory(Context context) {
    File sdRoot = Environment.getExternalStorageDirectory();
    String path = sdRoot.getPath();
    String packageName = context.getPackageName();
    path = path + File.separator + "Android" + File.separator + "data" + File.separator + packageName
            + File.separator + "files" + File.separator;
    return path;/*  w ww. j a  va  2  s .com*/
}

From source file:Main.java

public static Bitmap getBitmap(String name) {
    String path = Environment.getExternalStorageDirectory().getPath() + "/Chaoke/" + name;
    System.out.println(Environment.getExternalStorageDirectory().getPath() + "/Chaoke/" + name);
    return BitmapFactory.decodeFile(path);
}