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 getAbsoluteFilePath(String fileName) {
    String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + fileName;
    return filePath;
}

From source file:Main.java

static File make_tmpdir(Context context, SQLiteDatabase db) throws Exception {

    File extdir = Environment.getExternalStorageDirectory();
    File tmp_top = new File(extdir, "tmp_LongText");
    if (!tmp_top.exists()) {
        if (!tmp_top.mkdir())
            throw new Exception("cannot create directory: " + tmp_top.getPath());
    }//from   w  w w  .ja va2 s . co  m
    if (!tmp_top.canWrite())
        throw new Exception("missing permission to write to " + tmp_top.getPath());

    File tmpdir;
    Random r = new Random();
    do {
        tmpdir = new File(tmp_top, String.format("%d", r.nextInt()));
    } while (tmpdir.exists());
    if (!tmpdir.mkdir())
        throw new Exception("cannot create directory: " + tmp_top.getPath());
    if (!tmpdir.canWrite())
        throw new Exception("missing permission to write to " + tmp_top.getPath());
    ContentValues v = new ContentValues();
    v.put("pid", Process.myPid());
    v.put("tmpdir", tmpdir.getPath());
    v.put("ctime", System.currentTimeMillis());
    db.insert("tmpdir", null, v);

    return tmpdir;
}

From source file:Main.java

public static File getDataDirectory(Context ctx) {
    File f;//from w w  w  .j  a  va  2  s.com

    if (Environment.getExternalStorageState().equals("mounted")) {
        //Has SD Card mounted
        f = Environment.getExternalStorageDirectory();
    } else {
        ContextWrapper c = new ContextWrapper(ctx);

        f = c.getFilesDir();
    }

    return f;
}

From source file:Main.java

@SuppressLint("NewApi")
public static long getFreeDiskSpace() {
    String status = Environment.getExternalStorageState();
    long freeSpace = 0;
    if (status.equals(Environment.MEDIA_MOUNTED)) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSizeLong();
        long availableBlock = stat.getAvailableBlocksLong();
        freeSpace = availableBlock * blockSize / 1024;
    } else {/*  ww w .j a v a2s. co  m*/
        return -1;
    }
    return freeSpace;
}

From source file:Main.java

public static void saveMyBitmap3(String bitName, Bitmap mBitmap) throws IOException {
    String myJpgPath = Environment.getExternalStorageDirectory() + "/pepper/" + "3.png";
    File tmp = new File("/sdcard/pepper/");
    if (!tmp.exists()) {
        tmp.mkdir();//from www  . j  av a2s  .  c  o m
    }
    File f = new File(myJpgPath);
    f.createNewFile();
    FileOutputStream fOut = null;
    try {
        fOut = new FileOutputStream(f);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
    try {
        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void saveMyBitmap2(String bitName, Bitmap mBitmap) throws IOException {
    String myJpgPath = Environment.getExternalStorageDirectory() + "/pepper/" + "2.png";
    File tmp = new File("/sdcard/pepper/");
    if (!tmp.exists()) {
        tmp.mkdir();//from w  ww  .ja va2s  . c o m
    }
    File f = new File(myJpgPath);
    f.createNewFile();
    FileOutputStream fOut = null;
    try {
        fOut = new FileOutputStream(f);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
    try {
        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void saveMyBitmap(String bitName, Bitmap mBitmap) throws IOException {
    String myJpgPath = Environment.getExternalStorageDirectory() + "/pepper/" + "1.png";
    File tmp = new File("/sdcard/pepper/");
    if (!tmp.exists()) {
        tmp.mkdir();/*from ww w. j ava2 s  .  co  m*/
    }
    File f = new File(myJpgPath);
    f.createNewFile();
    FileOutputStream fOut = null;
    try {
        fOut = new FileOutputStream(f);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
    try {
        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static String getFolioEpubFolderPath(String epubFileName) {
    return Environment.getExternalStorageDirectory().getAbsolutePath() + FOLIO_READER_ROOT + epubFileName;
}

From source file:Main.java

public static Bitmap GetSingleImg(String imgName, int requiredSize, String path) {

    Bitmap bmp = null;/*from  ww w  . j a va 2s.c o  m*/
    File root = Environment.getExternalStorageDirectory();
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 8;

    // will results in a much smaller image than the original

    options.inSampleSize = 8;

    File imgFile = new File(path + imgName);

    bmp = decodeFileImg(imgFile, requiredSize);

    // do something with bitmap } \

    return bmp;
}

From source file:Main.java

private static File getExternalCacheDir(Context context) {
    if (hasExternalCacheDir()) {
        return context.getExternalCacheDir();
    }// w  ww  .  j a  v a  2s. c om
    final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/";
    return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir);
}