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 getAndroidObbFolder(String packageName) {
    String path = Environment.getExternalStorageDirectory() + File.separator + "Android" + File.separator
            + "obb" + File.separator + packageName;
    return path;/*from ww  w.j a v  a2 s  .  c  o m*/
}

From source file:Main.java

public static long getUsableSpace(File path) {
    final StatFs stats = new StatFs(Environment.getExternalStorageDirectory().getPath());
    return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
}

From source file:Main.java

public static long getAvailaleSDCardSize() {
    File path = Environment.getExternalStorageDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();

    long asize = availableBlocks * blockSize;
    LOG("getAvailaleSDCardSize asize: " + asize);
    return asize;
}

From source file:Main.java

public static void getSDCardPath(String retValue) {
    retValue = Environment.getExternalStorageDirectory().getAbsolutePath();
}

From source file:Main.java

/**
 * Get the external app cache directory.
 *
 * @param context The context to use//from ww  w  . j  a  va2 s.  c o  m
 * @return The external cache dir
 */
@TargetApi(Build.VERSION_CODES.FROYO)
private static File getExternalCacheDir(Context context) {
    File f;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        f = context.getExternalCacheDir();
        if (f != null) {
            return f;
        }
    }

    // Before Froyo we need to construct the external cache dir ourselves
    final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/";
    f = new File(Environment.getExternalStorageDirectory().getPath() + cacheDir);
    return f;
}

From source file:Main.java

/**
 * Get the phone storage path/*from www . j ava 2 s  . co m*/
 *
 * @return The phone storage path
 */
public static String getDefaultStoragePath() {
    return Environment.getExternalStorageDirectory().getPath();
}

From source file:Main.java

private static File getDirectoryBoards() {
    File file = new File(Environment.getExternalStorageDirectory(),
            DIR_BOARDS_EXTERNAL);/*from ww w .  j av a  2  s  .c o  m*/
    if (!file.exists()) {
        file.mkdir();
    }

    return file;
}

From source file:Main.java

public static String mergeFlockedFiles(String FilePath) {

    String result = null;/*  w ww.ja  va  2  s .  c om*/
    try {
        result = java.net.URLDecoder.decode(FilePath, "UTF-8");
    } catch (UnsupportedEncodingException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
    String fileName = result.substring(result.lastIndexOf('/') + 1);
    if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {

        File flockedFilesFolder = new File(
                Environment.getExternalStorageDirectory() + File.separator + "FlockLoad");
        System.out.println("FlockedFileDir: " + flockedFilesFolder);
        long leninfile = 0, leng = 0;
        int count = 1, data = 0;
        int bytesRead = 0;
        try {
            File filename = new File(flockedFilesFolder.toString() + "/" + fileName);
            if (filename.exists())
                filename.delete();
            //BUFFER_SIZE = (int) filename.length();
            System.out.println("filename: " + filename);
            FileOutputStream fos = new FileOutputStream(filename, true);

            while (true) {
                File filepart = new File(filename + ".part" + count);
                System.out.println("part filename: " + filepart);
                if (filepart.exists()) {
                    FileInputStream fis = new FileInputStream(filepart);
                    byte fileBytes[] = new byte[(int) filepart.length()];
                    bytesRead = fis.read(fileBytes, 0, (int) filepart.length());
                    assert (bytesRead == fileBytes.length);
                    assert (bytesRead == (int) filepart.length());
                    fos.write(fileBytes);
                    fos.flush();
                    fileBytes = null;
                    fis.close();
                    fis = null;
                    count++;
                    filepart.delete();
                } else
                    break;
            }
            fos.close();
            fos = null;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return fileName;
}

From source file:Main.java

public static boolean sdCardIsAvailable() {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File sd = new File(Environment.getExternalStorageDirectory().getPath());
        return sd.canWrite();
    } else/*from www.j  av  a2 s.  co  m*/
        return false;
}

From source file:Main.java

public static String getLyricDir() {
    File file = Environment.getExternalStorageDirectory();
    if (file == null) {
        return null;
    }/*w  w w  .  ja  v  a 2  s.  c  o  m*/
    File f = new File(file.getAbsolutePath() + LYRICS_DIR);
    if (!f.exists()) {
        f.mkdirs();
    }

    return f.getAbsolutePath();
}