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() {
    String storageDirectory = null;
    storageDirectory = Environment.getExternalStorageDirectory().toString();

    try {//from w w w.  ja  v a 2s . c  om
        StatFs stat = new StatFs(storageDirectory);
        long avaliableSize = ((long) stat.getAvailableBlocks() * (long) stat.getBlockSize());
        return avaliableSize;
    } catch (RuntimeException ex) {
        return 0;
    }
}

From source file:Main.java

public static File setOutPutImage(String name) {
    File outputimage = new File(Environment.getExternalStorageDirectory(), name + ".jpg");
    if (outputimage.exists()) {
        outputimage.delete();//from   www  . j av  a2 s . c  om
    }
    try {
        outputimage.createNewFile();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return outputimage;
}

From source file:Main.java

public static void initFolderName(String fName) {
    folderName = Environment.getExternalStorageDirectory() + "/" + fName;
}

From source file:Main.java

static public String prepareFilePath(String fileName, String dir) throws IOException {
    File dictionaryRoot = new File(Environment.getExternalStorageDirectory(), dir);
    File dictionaryDirFile = new File(dictionaryRoot, fileName.substring(0, 1));
    if (!dictionaryDirFile.exists()) {
        if (!dictionaryDirFile.mkdirs()) {
            throw new IOException("Cannot create directory: " + dictionaryDirFile);
        }/*from   w w w .  jav  a2  s  .c  om*/
    }
    return new File(dictionaryDirFile, fileName + ".mp3").getCanonicalPath();
}

From source file:Main.java

public static String getSdcardDir() {
    if (Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) {
        return Environment.getExternalStorageDirectory().toString();
    }/*ww w .  j  a  va  2  s  .  co m*/
    return null;
}

From source file:Main.java

static private File getAlbumStorageDir(String albumName) {
    return new File(Environment.getExternalStorageDirectory() + CAMERA_DIR + albumName);
}

From source file:Main.java

public static String getSdPath() {
    if (Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) {
        return Environment.getExternalStorageDirectory().toString();
    }/*from   w ww  .  j ava2  s .  c o  m*/
    return null;
}

From source file:Main.java

private static String getRootFolder() {
    File oRoot = Environment.getExternalStorageDirectory();
    return oRoot.getAbsolutePath() + "/" + FOLDER_PERSONAL_TRAINER;
}

From source file:Main.java

public static long getExternalStorageSpace() {

    long space = 0;
    try {//from  w  w w.ja  v  a 2  s  .  co  m
        StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
        space = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return space;
}

From source file:Main.java

public static File getTempFile(String packageName) {
    final File path = new File(Environment.getExternalStorageDirectory(), packageName);
    if (!path.exists()) {
        path.mkdir();//from w ww  . j a  va  2 s .  c o m
    }
    return new File(path, "image.tmp");
}