List of usage examples for android.os Environment getExternalStorageDirectory
public static File getExternalStorageDirectory()
From source file:Main.java
public static File getDataDir(Context context) { File file = new File(Environment.getExternalStorageDirectory(), context.getPackageName() + "/data"); if (!file.exists()) { file.mkdirs();/*from w w w. j av a 2s. c o m*/ } return file; }
From source file:Main.java
public static String getStoragePath(Context context) { String path = null;/*from w w w .j a v a 2 s . c o m*/ if (hasSDCard(context)) { path = Environment.getExternalStorageDirectory().getAbsolutePath(); } else { path = context.getFilesDir().getAbsolutePath(); } return path; }
From source file:Main.java
public static File createImageFile() throws IOException { // Create an image file name File storageDir = Environment.getExternalStorageDirectory(); File image = File.createTempFile("temp", /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ );//ww w .j a va2s . c o m return image; }
From source file:Main.java
public static String getSDPath() { boolean hasSDCard = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); if (hasSDCard) { return Environment.getExternalStorageDirectory().toString(); } else//from www . ja v a2 s . co m return Environment.getDownloadCacheDirectory().toString(); }
From source file:Main.java
public static boolean createDirectory(String directoryName) { boolean status; if (!directoryName.equals("")) { File path = Environment.getExternalStorageDirectory(); File newPath = new File(path.toString() + directoryName); //status = newPath.mkdir(); status = true;/*from w ww . ja va2 s.c o m*/ } else status = false; return status; }
From source file:Main.java
public static String getSDPath() { boolean hasSDCard = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); if (hasSDCard) { return Environment.getExternalStorageDirectory().toString() + "/mvpDemo"; } else {// w ww. j a va2s . c o m return null; } }
From source file:Main.java
public static boolean createDirectory(String directoryName) { boolean status; if (!directoryName.equals("")) { File path = Environment.getExternalStorageDirectory(); File newPath = new File(path.toString() + directoryName); status = newPath.mkdir();/*from ww w. ja v a2s. c om*/ status = true; } else status = false; return status; }
From source file:Main.java
/** * get the space is left over on sdcard/*ww w . j a va 2s.c o m*/ */ public static long getRealSizeOnSdcard() { File path = new File(Environment.getExternalStorageDirectory().getAbsolutePath()); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize; }
From source file:Main.java
public static int fileSize(String dir, String fileName) { File sdLien = Environment.getExternalStorageDirectory(); File inFile = new File(sdLien + File.separator + dir + File.separator + fileName); Log.d(TAG, "path of file : " + inFile); if (!inFile.exists()) { throw new RuntimeException("File doesn't exist"); }//w w w.j a v a 2 s . co m return ((int) inFile.length()); }
From source file:Main.java
public static void copyToSD(InputStream in, String fileName) { String path = Environment.getExternalStorageDirectory() + File.separator + fileName; File file = new File(path); try {//w w w . j a v a 2s .c om FileOutputStream fos = new FileOutputStream(file); byte[] buffer = new byte[1024]; int len = 0; while ((len = in.read(buffer)) != -1) { fos.write(buffer, 0, len); } fos.close(); } catch (Exception e) { e.printStackTrace(); } }