List of usage examples for android.os Environment getExternalStorageDirectory
public static File getExternalStorageDirectory()
From source file:Main.java
public static String getSDTotalSize(Context context) { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long totalBlocks = stat.getBlockCount(); return Formatter.formatFileSize(context, blockSize * totalBlocks); }
From source file:Main.java
public static void writeFile(byte[] bytes) throws IOException { String apkDir = Environment.getExternalStorageDirectory() + "/download/" + "app.apk"; java.io.File file = new java.io.File(apkDir); FileOutputStream fop = new FileOutputStream(file); fop.write(bytes);//from w w w . j a v a 2 s. c om fop.flush(); fop.close(); }
From source file:Main.java
public static File getDataRoot() { try {//www .j ava2 s. com if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) || (Environment.getExternalStorageDirectory().exists() && Environment.getExternalStorageDirectory().canWrite())) { return Environment.getExternalStorageDirectory(); } else { return Environment.getDataDirectory(); } } catch (Exception e) { return null; } }
From source file:Main.java
public static File getStoragePath() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return Environment.getExternalStorageDirectory(); } else {//w w w.jav a2s .c om return null; } }
From source file:Main.java
/*** * delete all logs//from www . j a v a2 s .c o m */ public static void deleteAllFiles() { File directory = new File(Environment.getExternalStorageDirectory() + File.separator + folderName); if (directory.exists()) { for (File file : directory.listFiles()) file.delete(); } }
From source file:Main.java
private static File getExternalCacheDir(Context context) { File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data"); File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache"); if (!appCacheDir.exists()) { if (!appCacheDir.mkdirs()) { return null; }/*from ww w .ja v a 2s. c o m*/ try { new File(appCacheDir, ".nomedia").createNewFile(); } catch (IOException e) { } } return appCacheDir; }
From source file:Main.java
/** * Returns the number of free bytes on the storage. *//*from w ww . ja va 2 s .c o m*/ public static long getFreeSpaceInBytes() { return Environment.getExternalStorageDirectory().getUsableSpace(); }
From source file:Main.java
private static File getExternalCacheDir(Context context) { File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data"); File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache"); if (!appCacheDir.exists()) { if (!appCacheDir.mkdirs()) { //L.w("Unable to create external cache directory"); return null; }//from w w w . j a va 2 s . co m try { new File(appCacheDir, ".nomedia").createNewFile(); } catch (IOException e) { //L.i("Can't create \".nomedia\" file in application external cache directory"); return null; } } return appCacheDir; }
From source file:Main.java
private static String getAppDir() { return Environment.getExternalStorageDirectory() + "/PonyMusic"; }
From source file:Main.java
public static boolean isSettingsFileExist() { File dir = new File(Environment.getExternalStorageDirectory(), DIRNAME); File file = new File(dir, FILENAME); return file.exists(); }