List of usage examples for android.os Environment getExternalStorageState
public static String getExternalStorageState()
From source file:Main.java
/** * Returns application files directory. Files directory will be created on SD card * <i>("/Android/data/[app_package_name]/files")</i> if card is mounted. Else - Android defines files directory on * device's file system./*from ww w .j a v a 2 s .c o m*/ * * @param context Application context * @return Files {@link File directory} */ public static File getFilesDirectory(Context context) { File appFilesDir = null; if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { appFilesDir = getExternalFilesDir(context); } if (appFilesDir == null) { appFilesDir = context.getFilesDir(); } return appFilesDir; }
From source file:Main.java
public static boolean isSdCardAvailable() { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); }
From source file:Main.java
/** * if sdcard available return true ,else return false * *//*from w ww. j a v a 2 s . com*/ public static boolean isSdcardAvailable() { String sdcardStatus = Environment.getExternalStorageState(); return sdcardStatus.equals(Environment.MEDIA_MOUNTED) ? true : false; }
From source file:Main.java
public static File createSDDir(String dirName) throws IOException { File dir = new File(SDPATH + dirName); if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { System.out.println("createSDDir:" + dir.getAbsolutePath()); System.out.println("createSDDir:" + dir.mkdir()); }// www.ja v a2s .c o m return dir; }
From source file:Main.java
/** * @return true if the data path is currently available. However, it can vanish at any time so * normally you should just try to use it and rely on the exceptions. *//* w w w. java 2 s. c om*/ public static boolean isDataPathAvailable() { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); }
From source file:Main.java
/** * Checks if the external media (SD Card) is writable * * @return boolean True if Writable//from w w w . jav a2 s .c om */ public static boolean isSdWritable() { boolean mExternalStorageAvailable = false; try { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { // We can read and write the media mExternalStorageAvailable = true; Log.i(TAG, mTAG + ": External storage card is readable."); } else { mExternalStorageAvailable = false; } } catch (Exception ex) { Log.e(TAG, mTAG + ":isSdWritable - " + ex.getMessage()); } return mExternalStorageAvailable; }
From source file:Main.java
public static File getCacheDirectory(Context context) { File appCacheDir = null;//www.ja v a 2 s .co m if (MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && hasExternalStoragePermission(context)) { appCacheDir = getExternalCacheDir(context); } if (appCacheDir == null) { appCacheDir = context.getCacheDir(); } if (appCacheDir == null) { Log.w(TAG, "Can't define system cache directory! The app should be re-installed."); } return appCacheDir; }
From source file:Main.java
public static boolean checkExternalDispose() { boolean mExternalStorageAvailable = false; boolean mExternalStorageWriteable = false; final String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { mExternalStorageAvailable = mExternalStorageWriteable = true; } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { mExternalStorageAvailable = true; mExternalStorageWriteable = false; } else {/* ww w .j a v a2s . c o m*/ mExternalStorageAvailable = mExternalStorageWriteable = false; } return mExternalStorageAvailable && mExternalStorageWriteable; }
From source file:Main.java
public static File getSDPath(Context context) { File sdDir = context.getCacheDir(); boolean sdCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); if (sdCardExist) { sdDir = Environment.getExternalStorageDirectory(); }//from w ww. j a va2s .c om return sdDir; }
From source file:Main.java
/** * Returns specified application cache directory. Cache directory will be created on SD card by defined path if card * is mounted. Else - Android defines cache directory on device's file system. * // w ww. j a v a 2s . c o m * @param context Application context * @param cacheDir Cache directory path (e.g.: "AppCacheDir", "AppDir/cache/images") * @return Cache {@link File directory} */ public static File getOwnCacheDirectory(Context context, String cacheDir) { File appCacheDir = null; if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { appCacheDir = new File(Environment.getExternalStorageDirectory(), cacheDir); } if (appCacheDir == null || (!appCacheDir.exists() && !appCacheDir.mkdirs())) { appCacheDir = context.getCacheDir(); } return appCacheDir; }