List of usage examples for android.os Environment getExternalStorageDirectory
public static File getExternalStorageDirectory()
From source file:Main.java
public static String getQuranBaseDirectory() { String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) return Environment.getExternalStorageDirectory() + QURAN_BASE; else// w w w . j a v a 2 s . c om return null; }
From source file:Main.java
public static boolean deleteDirectory(String fileName) { boolean status; SecurityManager checker = new SecurityManager(); if (!fileName.equals("")) { File path = Environment.getExternalStorageDirectory(); File newPath = new File(path.toString() + fileName); checker.checkDelete(newPath.toString()); if (newPath.isDirectory()) { String[] listfile = newPath.list(); // delete all files within the specified directory and then // delete the directory try { for (int i = 0; i < listfile.length; i++) { File deletedFile = new File(newPath.toString() + "/" + listfile[i].toString()); deletedFile.delete(); }//from ww w . j a va 2 s . c o m newPath.delete(); Log.i("DirectoryManager deleteDirectory", fileName); status = true; } catch (Exception e) { e.printStackTrace(); status = false; } } else status = false; } else status = false; return status; }
From source file:Main.java
public static Bitmap readImageFile(String fileName) { if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { return null; }// w w w .ja v a 2 s . co m File file = new File(Environment.getExternalStorageDirectory().toString() + File.separator + fileName); if (!file.exists()) { return null; } return BitmapFactory.decodeFile(fileName); }
From source file:Main.java
private static boolean checkFsWritable() { // Create a temporary file to see whether a volume is really writeable. // It's important not to put it in the root directory which may have a // limit on the number of files. String directoryName = Environment.getExternalStorageDirectory().toString() + "/DCIM"; File directory = new File(directoryName); if (!directory.isDirectory()) { if (!directory.mkdirs()) { return false; }/*from ww w. j av a 2 s .c o m*/ } return directory.canWrite(); }
From source file:Main.java
public static long getFreeDiskSpace() { String status = Environment.getExternalStorageState(); long freeSpace = 0; if (status.equals(Environment.MEDIA_MOUNTED)) { try {//from www . j a v a 2 s . c om File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); freeSpace = availableBlocks * blockSize / 1024; } catch (Exception e) { e.printStackTrace(); } } else { return -1; } return (freeSpace); }
From source file:Main.java
public static File savebitmap(Bitmap bitmap) { OutputStream outStream = null; File folder = new File(Environment.getExternalStorageDirectory().toString() + "/InSyte"); folder.mkdirs();/* w ww .ja v a 2 s . co m*/ String mDirectory = folder.toString(); File file = new File(mDirectory, "IMG_" + System.currentTimeMillis() + ".jpg"); try { outStream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream); outStream.flush(); outStream.close(); } catch (Exception e) { e.printStackTrace(); } return file; }
From source file:Main.java
public static List grabFiles() { List<String> tFileList = new ArrayList<String>(); String p = Environment.getExternalStorageDirectory().getAbsolutePath() + "/nexsight/"; File f = new File(p); Log.d(TAG, "Read from " + p); File[] files = f.listFiles(); files = flipArray(files);/*from w w w . j a va 2 s .co m*/ if (files != null) { for (int i = 0; i < files.length; i++) { File file = files[i]; tFileList.add(file.getPath()); } } else { Log.w(TAG, "nothing found in " + p); } return tFileList; }
From source file:Main.java
/** * Get the left size of the SDCard in Bytes. * // w ww.j av a2 s . com * @return the left size */ @SuppressWarnings("deprecation") public static long getSDCardLeftSize() { File sdcard = Environment.getExternalStorageDirectory(); if (sdcard.exists()) { StatFs statFs = new StatFs(sdcard.getAbsolutePath()); long blockSize = statFs.getBlockSize(); long availableBlocks = statFs.getAvailableBlocks(); return blockSize * availableBlocks; } return 0; }
From source file:Main.java
public static File getDiskDir(String uniqueName) { if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) { File storageDirectory = Environment.getExternalStorageDirectory(); if (storageDirectory != null) { File file = new File(storageDirectory + File.separator + uniqueName); if (!file.exists() && !file.isDirectory()) { file.mkdir();/*from w w w. j a v a2 s . c o m*/ } return file; } } return null; }
From source file:Main.java
public static void saveImage(Bitmap bmp, String name) { if (bmp != null) { File appDir = new File(Environment.getExternalStorageDirectory(), name); if (!appDir.exists()) { try { appDir.createNewFile();/* w ww . j a v a 2 s . com*/ } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { FileOutputStream fos = new FileOutputStream(appDir); bmp.compress(Bitmap.CompressFormat.JPEG, 90, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { } }