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 getInstrumentalDirectory() {
    return Environment.getExternalStorageDirectory() + File.separator + "MicDroid" + File.separator
            + "instrumental";
}

From source file:Main.java

public static void put(String s, String name) {
    try {/*ww  w .ja  v a  2 s .  c  o  m*/
        File saveFile = new File(Environment.getExternalStorageDirectory() + "/hhtlog/" + name + ".txt");
        if (!saveFile.exists()) {
            File dir = new File(saveFile.getParent());
            dir.mkdirs();
            saveFile.createNewFile();
        }

        FileOutputStream outStream = new FileOutputStream(saveFile);
        outStream.write(s.getBytes());
        outStream.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void saveDBInSdcard(Context pContext, String pDatabaseName) {
    try {/*from  w ww. j av a2s.  c  o  m*/
        File sd = Environment.getExternalStorageDirectory();
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            String currentDBPath = "//data//" + pContext.getPackageName() + "//databases//" + pDatabaseName;
            String backupDBPath = pDatabaseName;
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, backupDBPath);

            FileChannel src = new FileInputStream(currentDB).getChannel();
            FileChannel dst = new FileOutputStream(backupDB).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();
            Toast.makeText(pContext, backupDB.toString(), Toast.LENGTH_LONG).show();
        }
    } catch (Exception e) {
        Toast.makeText(pContext, e.toString(), Toast.LENGTH_LONG).show();
    }
}

From source file:Main.java

public static String getExternalStoragePath() {
    return Environment.getExternalStorageDirectory().getPath();
}

From source file:Main.java

public static File getExternalDataDir() {
    File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data");
    return dataDir;
}

From source file:Main.java

public static File getDefaultDirectory(@NonNull Context context) {
    return new File(Environment.getExternalStorageDirectory(),
            DIRECTORY_BACKUP + "/" + context.getPackageName());
}

From source file:Main.java

public static File getFileForCrypt(String hash, Context context) {
    File externalCacheDir = new File(
            new File(new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data"),
                    context.getPackageName()),
            "cypher");
    externalCacheDir.mkdirs();//from  w  w w. j a  v  a  2  s .c o  m

    // clear old items
    String[] files = externalCacheDir.list();
    long th = new Date().getTime() - 24 * 60 * 60 * 1000; // expire one day
    for (int i = 0; i < files.length; i++) {
        File tmp = new File(externalCacheDir, files[i]);
        if (tmp.lastModified() < th) {
            tmp.delete();
        }
    }

    // add new file
    File dst = new File(externalCacheDir, hash + ".tmp");
    if (dst.exists()) {
        dst.delete();
    }
    //      dst.deleteOnExit();
    return dst;
}

From source file:Main.java

private static File getBackupFile() {
    File file = new File(Environment.getExternalStorageDirectory() + BACKUP_DIRECTORY_PATH);

    if (!file.exists() && !file.mkdirs()) {
        return null;
    }//www .j  av a 2  s .c  o  m

    file = new File(Environment.getExternalStorageDirectory() + BACKUP_DIRECTORY_PATH, BACKUP_FILE);

    return file;
}

From source file:Main.java

public static String getSDCardPath() {
    return Environment.getExternalStorageDirectory().getAbsolutePath();
}

From source file:Main.java

/**
 * @return Available external memory//  w ww. j  av a 2s .c o m
 */
public static int getAvailableExternalMemorySize() {
    if (isExternalStorageAvailable()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        int blockSize = stat.getBlockSize();
        int availableBlocks = stat.getAvailableBlocks();
        return availableBlocks * blockSize;
    } else {
        return 0;
    }
}