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

private static boolean checkFsWritable() {
    String directoryName = Environment.getExternalStorageDirectory().toString() + "/DCIM";
    File directory = new File(directoryName);
    if (!directory.isDirectory()) {
        if (!directory.mkdirs()) {
            return false;
        }//from   w w  w.ja v  a 2 s.  c om
    }
    File f = new File(directoryName, ".probe");
    try {
        if (f.exists()) {
            f.delete();
        }
        if (!f.createNewFile()) {
            return false;
        }
        f.delete();
        return true;
    } catch (IOException ex) {
        return false;
    }
}

From source file:Main.java

public static int freeSpaceOnSD() {
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    double sdFreeMB = ((double) stat.getAvailableBlocks() * (double) stat.getBlockSize()) / 1024 * 1024;
    return (int) sdFreeMB;
}

From source file:Main.java

public static File getTempDir() {
    File ext = Environment.getExternalStorageDirectory();
    File tempDir = new File(ext, "aquery/temp");
    tempDir.mkdirs();//from w w  w  .j av  a  2 s .co  m
    if (!tempDir.exists() || !tempDir.canWrite()) {
        return null;
    }
    return tempDir;
}

From source file:Main.java

public static String getSDPath() {
    String result = "";
    File sdDir = null;//www . j av  a 2 s .  c o m
    if (isSdCardExist()) {
        sdDir = Environment.getExternalStorageDirectory();
    }

    if (sdDir != null) {
        result = sdDir.getPath();
    }
    return result;
}

From source file:Main.java

public static String getExternalCacheDirectory() {
    //TODO should get it from application context

    return Environment.getExternalStorageDirectory().getPath();
}

From source file:Main.java

public static String unzip(String filename) throws IOException {
    BufferedOutputStream origin = null;
    String path = null;//from  w  w w. j a  v  a2  s  . c o m
    Integer BUFFER_SIZE = 20480;
    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);
        String compressedFile = flockedFilesFolder.toString() + "/" + filename;
        System.out.println("compressed File name:" + compressedFile);
        //String uncompressedFile = flockedFilesFolder.toString()+"/"+"flockUnZip";
        File purgeFile = new File(compressedFile);

        try {
            ZipInputStream zin = new ZipInputStream(new FileInputStream(compressedFile));
            BufferedInputStream bis = new BufferedInputStream(zin);
            try {
                ZipEntry ze = null;
                while ((ze = zin.getNextEntry()) != null) {
                    byte data[] = new byte[BUFFER_SIZE];
                    path = flockedFilesFolder.toString() + "/" + ze.getName();
                    System.out.println("path is:" + path);
                    if (ze.isDirectory()) {
                        File unzipFile = new File(path);
                        if (!unzipFile.isDirectory()) {
                            unzipFile.mkdirs();
                        }
                    } else {
                        FileOutputStream fout = new FileOutputStream(path, false);
                        origin = new BufferedOutputStream(fout, BUFFER_SIZE);
                        try {
                            /* for (int c = bis.read(data, 0, BUFFER_SIZE); c != -1; c = bis.read(data)) {
                            origin.write(c);
                             }
                             */
                            int count;
                            while ((count = bis.read(data, 0, BUFFER_SIZE)) != -1) {
                                origin.write(data, 0, count);
                            }
                            zin.closeEntry();
                        } finally {
                            origin.close();
                            fout.close();

                        }
                    }
                }
            } finally {
                bis.close();
                zin.close();
                purgeFile.delete();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return path;
    }
    return null;
}

From source file:Main.java

protected static void setStorageDir(String path) {
    File sdDir = Environment.getExternalStorageDirectory();
    storageDir = new File(sdDir + path);
    if (!storageDir.exists()) {
        storageDir.mkdirs();//  ww  w  .j  av  a  2 s. c  om
    }
}

From source file:Main.java

public static String getExtraPath(String folder) {
    String storagePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + folder;
    File file = new File(storagePath);
    if (!file.exists()) {
        file.mkdir();//from  w ww.ja  v  a2  s. c o m
    }
    return storagePath;
}

From source file:Main.java

public static File getSaveFile(String folder, String fileNmae) {
    File file = new File(Environment.getExternalStorageDirectory().getAbsoluteFile() + File.separator + folder
            + File.separator + fileNmae);
    return file.exists() ? file : null;
}

From source file:Main.java

public static Bitmap drawTextToBitmap(Bitmap bitmap, String gText) {
    OutputStream outStream = null;
    Bitmap.Config bitmapConfig = bitmap.getConfig();
    // set default bitmap config if none
    if (bitmapConfig == null) {
        bitmapConfig = Bitmap.Config.ARGB_8888;
    }//from  ww w.  j a  v a2 s .co m
    String dataPath = Environment.getExternalStorageDirectory().toString() + "/SignChat/Temp/temp" + "0"
            + pictureNum + ".jpg";

    try {

        FileOutputStream out = new FileOutputStream(dataPath);

        // NEWLY ADDED CODE STARTS HERE [
        Canvas canvas = new Canvas(bitmap);

        Paint paint = new Paint();
        paint.setColor(Color.WHITE); // Text Color
        paint.setStrokeWidth(12); // Text Size
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); // Text
        // Overlapping
        // Pattern
        // some more settings...

        canvas.drawBitmap(bitmap, 0, 0, paint);
        canvas.drawText("Testing...", 10, 10, paint);
        // NEWLY ADDED CODE ENDS HERE ]

        bitmap.compress(CompressFormat.JPEG, 90, out);
        out.flush();
        out.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return bitmap;
}