List of usage examples for android.os Environment getExternalStorageDirectory
public static File getExternalStorageDirectory()
From source file:Main.java
public static File getTempFile(Context context) { //it will return /sdcard/image.tmp final File path = new File(Environment.getExternalStorageDirectory(), context.getPackageName()); if (!path.exists()) { path.mkdir();/*from w w w . ja v a2s . co m*/ } return new File(path, "image.jpg"); }
From source file:Main.java
@SuppressWarnings("deprecation") public static long getAvailableSD() { File path = Environment.getExternalStorageDirectory(); StatFs statFs = new StatFs(path.getPath()); long blockSize = statFs.getBlockSize(); long blockCount = statFs.getBlockCount(); long availableBlocks = statFs.getAvailableBlocks(); return availableBlocks * blockSize; }
From source file:Main.java
public static long getSDTotalSize() { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { return getTotalSize(Environment.getExternalStorageDirectory().toString()); }/*from ww w . j a v a2 s .c o m*/ return 0; }
From source file:Main.java
static void writeToFollower(String name) { try {/*w w w .ja va 2 s . com*/ File root = new File(Environment.getExternalStorageDirectory().toString(), ".Instagram"); if (!root.exists()) { root.mkdirs(); } File file = new File(root, "Following.txt"); BufferedWriter buf = new BufferedWriter(new FileWriter(file, true)); buf.newLine(); buf.append(name); buf.close(); } catch (Throwable t) { } }
From source file:Main.java
public static String readFromSD(String fileName) throws Exception { File file = new File(Environment.getExternalStorageDirectory(), fileName); FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); String line = null;//from w w w .jav a 2 s.c om StringBuilder sb = new StringBuilder(); while ((line = br.readLine()) != null) { sb.append(line); } return sb.toString(); }
From source file:Main.java
public static String getExternalStoragePath() { StringBuilder sb = new StringBuilder(); sb.append(Environment.getExternalStorageDirectory().getAbsolutePath()); sb.append(File.separator);/*from w w w . ja v a2 s. c o m*/ sb.append(ROOT_DIR); sb.append(File.separator); return sb.toString(); }
From source file:Main.java
public static void saveBitmap(Bitmap bitmap, String fileName) { String filePath = Environment.getExternalStorageDirectory() + "/" + fileName; try {// ww w .java2 s . c o m OutputStream stream = new FileOutputStream(filePath); bitmap.compress(Bitmap.CompressFormat.PNG, 80, stream); stream.close(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:Main.java
static void setSetting(String name, String data) { try {//from ww w . j a v a 2 s .co m File root = new File(Environment.getExternalStorageDirectory().toString(), ".Instagram"); if (!root.exists()) { root.mkdirs(); } File gpxfile = new File(root, name + ".txt"); FileWriter writer = new FileWriter(gpxfile); writer.append(data); writer.flush(); writer.close(); } catch (IOException e) { } }
From source file:Main.java
public static long getSdCardFree() { long l = 0L;// w w w. j a v a 2s . co m if (Environment.getExternalStorageState().equals("mounted")) { StatFs statfs = new StatFs(Environment.getExternalStorageDirectory().getPath()); l = ((long) statfs.getBlockSize() * (long) statfs.getAvailableBlocks()) / 1024L / 1024L; } return l; }
From source file:Main.java
public static String GetBackupFolder(Context paramContext) { File dir = new File(Environment.getExternalStorageDirectory(), "backups"); if (!dir.exists()) dir.mkdir();/*from w w w . j a va 2 s . c o m*/ return PreferenceManager.getDefaultSharedPreferences(paramContext).getString("prefDBLocalFolder", dir.getAbsolutePath()); }