List of usage examples for android.os Environment getExternalStorageDirectory
public static File getExternalStorageDirectory()
From source file:Main.java
public static long getAvailableExternalMemorySize() throws IllegalArgumentException { if (externalMemoryAvailable()) { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize; } else {/* w ww. j a v a 2 s . c o m*/ return -1; } }
From source file:Main.java
public static void saveBitmapToSD(Bitmap bitmap) { String root = Environment.getExternalStorageDirectory().toString(); File myDir = new File(root + "/Download"); myDir.mkdirs();// w w w. java2 s .co m Random generator = new Random(); String fname = "Image-" + System.currentTimeMillis() + ".jpg"; File file = new File(myDir, fname); if (file.exists()) file.delete(); try { FileOutputStream out = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void creatFile(String fileName) { if (sdState.equals(Environment.MEDIA_MOUNTED)) { File file = new File( Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + fileName); if (!file.exists()) { file.mkdir();/*from w w w . j a v a 2 s . c om*/ } } }
From source file:Main.java
private static String generateFileName() { // create a random file String name = String.valueOf(System.currentTimeMillis()); return Environment.getExternalStorageDirectory() + "/" + ALBUM_THUMB_FOLDER + "/" + name; }
From source file:Main.java
private static String getSavedPostsPath(Context context) { String dir = String.format("/Android/data/%s/files/", context.getPackageName()); File sd = Environment.getExternalStorageDirectory(); String filePath = sd.getPath() + dir + "savedPosts.txt"; new File(sd.getPath() + dir).mkdirs(); return filePath; }
From source file:Main.java
private static File getAlbumStorageDir(String albumName) { // Get the directory for the user's public pictures directory. File file = new File(Environment.getExternalStorageDirectory(), albumName); if (!file.mkdirs()) { Log.d(LOG_TAG, "Directory not created"); }/*from w ww .j a v a2 s .c om*/ return file; }
From source file:Main.java
public static File getFileName(String dirPath, String fileName, Context context) { File mLogDir;/* w ww .jav a2 s . co m*/ if (isSDCardAvailable()) { mLogDir = new File( Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + dirPath); } else { mLogDir = new File(context.getFilesDir().getAbsolutePath() + File.separator + dirPath); } if (!mLogDir.exists()) { mLogDir.mkdirs(); } return new File(mLogDir.getAbsolutePath() + File.separator + fileName); }
From source file:Main.java
public static long getTotalExternalMemorySize(Context context) { if (!isHaveSDCard()) { return -1; }/*from w w w . ja v a 2 s.co m*/ StatFs sFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath()); long blockSize = sFs.getBlockSize(); long totalBlocks = sFs.getBlockCount(); return blockSize * totalBlocks; }
From source file:Main.java
public static void init(final Context context) { //ContextWrapper cw = new ContextWrapper(context); contentPath = new File(Environment.getExternalStorageDirectory(), "ST_content");//cw.getDir("content", Context.MODE_PRIVATE); }
From source file:Main.java
public static String getTotalExternalMemorySize(Context context) { if (externalMemoryAvailable()) { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long totalBlocks = stat.getBlockCount(); return Formatter.formatFileSize(context, totalBlocks * blockSize); } else {/* ww w. ja v a2s. c o m*/ return "ERROR"; } }