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 String getFileName(boolean isAudio) {
    String storageDir = Environment.getExternalStorageDirectory().getAbsolutePath();
    return String.format("%s/%s", storageDir, (isAudio) ? AUDIO_FILE_NAME : VIDEO_FILE_NAME);
}

From source file:Main.java

public static Bitmap getBitmapFromLocal(String fileName) {
    Bitmap bitmap = null;//w w w .  j av  a  2  s .c o  m
    String pathName = Environment.getExternalStorageDirectory() + "/boc_container/" + fileName;
    File file = new File(pathName);
    if (file.exists()) {
        bitmap = BitmapFactory.decodeFile(pathName);
    }
    return bitmap;
}

From source file:Main.java

public static String getFileRootPath(Context context) {
    return Environment.getExternalStorageDirectory() + "/Wstro/" + context.getPackageName();
}

From source file:Main.java

public static long getTotalExternalMemorySize() {
    if (isExternalMemoryAvailable() == true) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = 0;
        long totalBlocks = 0;
        blockSize = stat.getBlockSize();
        totalBlocks = stat.getBlockCount();

        return totalBlocks * blockSize;
    } else {//from   w  w  w. j a  va 2  s. co  m
        return -1;
    }
}

From source file:Main.java

public static File getExternalCacheDir(Context context) {
    final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/";
    return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir);
}

From source file:Main.java

public static String getPublicDataFolder() {
    StringBuilder publicFolder = new StringBuilder();
    publicFolder.append(Environment.getExternalStorageDirectory()).append(DIRECTORY_NAME);
    File new_dir = new File(publicFolder.toString());
    if (!new_dir.exists()) {
        new_dir.mkdirs();
    }/*w w  w.  ja v  a2s.c om*/
    return publicFolder.toString();
}

From source file:Main.java

private static String generateDCIM() {
    return new File(Environment.getExternalStorageDirectory().toString(), Environment.DIRECTORY_DCIM)
            .toString();/*w ww.  j a  v a2 s . c  om*/
}

From source file:Main.java

public static File getFeedbackStorageDirectory(Context context) {
    File feedbackStorageDirectory = null;

    feedbackStorageDirectory = new File(Environment.getExternalStorageDirectory(), context.getPackageName());

    // Create the storage directory if it does not exist
    if (!feedbackStorageDirectory.exists()) {
        if (!feedbackStorageDirectory.mkdirs()) {
            System.out.print("failed to create directory");
            return null;
        }/* w w w  . ja  va  2  s.  c om*/
    }
    return feedbackStorageDirectory;
}

From source file:Main.java

public static String getSDPath() {
    File sdDir = null;//  w  w  w  . j a va2s.  c o m
    boolean sdCardExist = Environment.getExternalStorageState().equals("mounted");
    if (sdCardExist) {
        sdDir = Environment.getExternalStorageDirectory();
    } else {
        sdDir = Environment.getRootDirectory();
    }

    return sdDir.toString();
}

From source file:Main.java

private static String getSDDir(String key_dir) {
    StringBuilder sb = new StringBuilder();
    String absolutePath = Environment.getExternalStorageDirectory().getAbsolutePath();// /mnt/sdcard
    sb.append(absolutePath);/*from w ww.  j  a v  a  2  s  .c o m*/
    sb.append(File.separator).append(ROOT_DIR).append(File.separator).append(key_dir);

    String filePath = sb.toString();
    File file = new File(filePath);
    if (!file.exists()) {
        if (file.mkdirs()) {
            return file.getAbsolutePath();
        } else {
            return "";
        }
    }

    return file.getAbsolutePath();
}