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 boolean saveFile(Bitmap bitmap, String filename) {
    File sd = Environment.getExternalStorageDirectory();
    File dest = new File(sd, filename);
    try {//from w  w w.  j a  v a 2  s.c o  m
        FileOutputStream out = new FileOutputStream(dest);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
        out.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:Main.java

public static String setImBin(String fName) {
    FileInputStream fileInputStream = null;

    File file = new File(Environment.getExternalStorageDirectory().getPath(), "Pictures/" + fName);

    byte[] bFile = new byte[(int) file.length()];

    try {/* ww  w .  jav  a  2s .com*/
        fileInputStream = new FileInputStream(file);
        fileInputStream.read(bFile);
        fileInputStream.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return Base64.encodeToString(bFile, Base64.DEFAULT);
}

From source file:Main.java

public static String getImagePath(String imageUrl) {
    int lastSlashIndex = imageUrl.lastIndexOf("/");
    String imageName = imageUrl.substring(lastSlashIndex + 1);
    String imageDir = Environment.getExternalStorageDirectory().getPath() + "/university/pics";
    File file = new File(imageDir);
    if (!file.exists()) {
        file.mkdirs();/*from  www.  j  a v  a2 s .c  o  m*/
    }
    String imagePath = imageDir + "/" + imageName;
    return imagePath;
}

From source file:Main.java

public static String getOdkFolder() {
    String path = Environment.getExternalStorageDirectory() + File.separator + "opendatakit";
    return path;//from ww w.  j a va 2 s  .c o m
}

From source file:Main.java

public static File getSaveFolder(String folderName) {
    File file = new File(Environment.getExternalStorageDirectory().getAbsoluteFile() + File.separator
            + folderName + File.separator);
    file.mkdirs();/*  w  w w  .  ja  va  2  s  .co m*/
    return file;
}

From source file:Main.java

public static File getTempImage() throws IOException {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File tempFile = new File(Environment.getExternalStorageDirectory(), "temp.jpg");
        tempFile.createNewFile();/*from  w  ww  . ja v  a 2 s. co  m*/
        return tempFile;
    }
    throw new IOException("cannot find any sdcard.");
}

From source file:Main.java

public static Uri saveBitmapToSDCard(Bitmap bitmap, String title) {
    File appDir = new File(Environment.getExternalStorageDirectory(), "Gank");
    if (!appDir.exists()) {
        appDir.mkdirs();//from  w w w .j a v  a 2 s. c o  m
    }
    String fileName = title.replace("/", "-") + "-girl.jpg";
    File file = new File(appDir, fileName);
    FileOutputStream outputStream;
    try {
        outputStream = new FileOutputStream(file);
        assert bitmap != null;
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
        outputStream.flush();
        outputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return Uri.fromFile(file);
}

From source file:Main.java

public static void setCacheRoot(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        mCacheRoot = Environment.getExternalStorageDirectory().getPath() + "/";
    } else {// ww w .j  a v  a2s . c  o  m
        mCacheRoot = context.getCacheDir().getPath() + "/";
    }
}

From source file:Main.java

public static String getSDPath() {
    File sdDir = null;/*from  w ww.jav a  2 s  . c om*/
    boolean sdCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    if (sdCardExist) {
        sdDir = Environment.getExternalStorageDirectory(); // get root path
        return sdDir.toString();
    }
    return null;
}

From source file:Main.java

public static String getSDPath() {
    File sdDir = null;//from ww w  .j  a  va 2  s  .  com
    boolean sdCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    if (sdCardExist) {
        sdDir = Environment.getExternalStorageDirectory();
    }
    String dir = sdDir.toString();
    return dir;
}