List of usage examples for android.os Environment getExternalStorageState
public static String getExternalStorageState()
From source file:Main.java
/** * Check is SD card is ready for write// w w w .ja va2s.co m * * @return */ public static boolean isSDWritable() { String state = Environment.getExternalStorageState(); return Environment.MEDIA_MOUNTED.equals(state); }
From source file:Main.java
public static void WriteStringToSD(String fileName, String content) { Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); File file = new File(Environment.getExternalStorageDirectory(), fileName); try {/*from w w w . j a v a 2 s . c o m*/ FileOutputStream fos = new FileOutputStream(file, true); fos.write(content.getBytes()); fos.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static boolean isCanUseSD() { try {/*from w ww.j a v a2 s. c o m*/ return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:Main.java
/** * @return True if the external storage is writable. False otherwise. *///from www. ja va 2 s. co m public static boolean isWritable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } return false; }
From source file:Main.java
public static boolean existExternalStorageDirectory() { if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && Environment.getExternalStorageDirectory().canWrite()) { return true; }//from www . j a va2 s . co m return false; }
From source file:Main.java
public static String dstPath(Context context) { String cachePath;/* w w w. j a va2 s. co m*/ if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { cachePath = context.getExternalCacheDir().getPath(); } else { cachePath = context.getCacheDir().getPath(); } return cachePath; }
From source file:Main.java
public static File getDiskCacheDir(Context context) { if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) { return context.getExternalCacheDir(); } else {/* w w w .j a v a2s . c om*/ return context.getCacheDir(); } }
From source file:Main.java
public static boolean isExternalStorageMounted() { boolean canRead = Environment.getExternalStorageDirectory().canRead(); boolean onlyRead = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED_READ_ONLY); boolean unMounted = Environment.getExternalStorageState().equals(Environment.MEDIA_UNMOUNTED); return !(!canRead || onlyRead || unMounted); }
From source file:Main.java
private static String createDir(String path) { boolean isHaveSDCard = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); if (!isHaveSDCard) { return null; }/* w w w . j a va 2 s . c o m*/ File directory = Environment.getExternalStorageDirectory(); File file = new File(directory.getAbsolutePath() + path); if (!file.exists()) { boolean isSuccess = file.mkdirs(); if (isSuccess) { return file.getPath() + File.separator; } else { return null; } } return file.getPath() + File.separator; }
From source file:Main.java
/** * Checks if external storage is available for read and write *///w w w. j a va 2 s. c o m public static boolean isExternalStorageWritable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } return false; }