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 getStorePath() {
    if (mStorePath == null) {
        String path = Environment.getExternalStorageDirectory().getPath();
        if (path == null || !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            path = mContext.getFilesDir().getPath();
        }/*ww w .ja  v a 2s.c o  m*/
        if (!path.endsWith("/")) {
            path = path + "/";
        }
        mStorePath = path;
    }
    return mStorePath;
}

From source file:Main.java

@SuppressLint("NewApi")
public static long getSDCardAvailableSize() {
    if (isSDCardEnable()) {
        StatFs statFs = new StatFs(
                Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator);
        if (android.os.Build.VERSION.SDK_INT < 18) {
            int blockSize = statFs.getBlockSize();
            int blockCount = statFs.getAvailableBlocks();
            return blockCount * blockSize;
        } else {//from  www. jav a 2s.c o m
            long blockSize = statFs.getBlockSizeLong();
            long blockCount = statFs.getAvailableBlocksLong();
            return blockCount * blockSize;
        }
    }
    return -1;
}

From source file:Main.java

public static boolean deleteFile(String fileName) {
    boolean status;
    SecurityManager checker = new SecurityManager();

    if (!fileName.equals("")) {

        File path = Environment.getExternalStorageDirectory();
        File newPath = new File(path.toString() + fileName);
        checker.checkDelete(newPath.toString());
        if (newPath.isFile()) {
            try {
                Log.i("DirectoryManager deleteFile", fileName);
                newPath.delete();//from w  ww  .  j  av a2s .  c o  m
                status = true;
            } catch (SecurityException se) {
                se.printStackTrace();
                status = false;
            }
        } else
            status = false;
    } else
        status = false;
    return status;
}

From source file:Main.java

public static File createFolders() {
    File baseDir;/*from   w  w w.j ava 2  s .  co  m*/
    if (android.os.Build.VERSION.SDK_INT < 8) {
        baseDir = Environment.getExternalStorageDirectory();
    } else {
        baseDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    }
    if (baseDir == null)
        return Environment.getExternalStorageDirectory();
    File aviaryFolder = new File(baseDir, FOLDER_NAME);
    if (aviaryFolder.exists())
        return aviaryFolder;
    if (aviaryFolder.isFile())
        aviaryFolder.delete();
    if (aviaryFolder.mkdirs())
        return aviaryFolder;
    return Environment.getExternalStorageDirectory();
}

From source file:Main.java

public static void writeCSV(String phoneNo, String Message) {
    File root = Environment.getExternalStorageDirectory();
    File csvFile = new File(root, "/adspammer/log.csv");
    FileWriter writer = null;//from w w  w . ja  va  2 s  . co  m
    try {
        writer = new FileWriter(csvFile, true);

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd @ HH:mm:ss");
        Date date = new Date();
        System.out.println(dateFormat.format(date));

        writer.append(dateFormat.format(date).toString());
        writer.append(',');
        writer.append(phoneNo);
        writer.append(',');
        writer.append(Message);
        writer.append('\n');

        writer.flush();
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static boolean canImport() {
    String itemsFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + APP_PATH + '/'
            + ITEMS_CSVFILENAME;// w w w. j  a v a  2  s  .  c o m
    File itemsFile = new File(itemsFilePath);

    String placesFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + APP_PATH + '/'
            + PLACES_CSVFILENAME;
    File placesFile = new File(placesFilePath);

    return (itemsFile.canRead() && placesFile.canRead());
}

From source file:Main.java

private static void decompressGzipFile(String gzipFile) {
    try {/*from  www .ja v a2 s. c  o  m*/
        File newFile = new File(Environment.getExternalStorageDirectory() + File.separator + "FlockLoad");
        FileInputStream fis = new FileInputStream(gzipFile);
        GZIPInputStream gis = new GZIPInputStream(fis);
        FileOutputStream fos = new FileOutputStream(newFile);
        byte[] buffer = new byte[1024];
        int len;
        while ((len = gis.read(buffer)) != -1) {
            fos.write(buffer, 0, len);
        }
        //close resources
        fos.close();
        gis.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static String getPathForSharedStorage() {
    String storage = Environment.getExternalStorageDirectory().toString();
    //String storage = "/storage/emulated/0/"; // this is what my device is seeing for above call
    //String storage = "/sdcard"; // because gmail can't read it, as the file must be in a 'sharable' location
    return storage;
}

From source file:Main.java

public static String getImageSavePath(String fileName) {

    if (TextUtils.isEmpty(fileName)) {
        return null;
    }//  w w w .  j a  v a 2 s.c o  m

    final File folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator
            + "MGJ-IM" + File.separator + "images");
    if (!folder.exists()) {
        folder.mkdirs();
    }

    return folder.getAbsolutePath() + File.separator + fileName;
}

From source file:Main.java

public static File getExternalStorageAppDir() {
    return new File(Environment.getExternalStorageDirectory(), "TowerCollector");
}