List of usage examples for android.os Environment getExternalStorageState
public static String getExternalStorageState()
From source file:Main.java
/**Check whether the sdcard is available * @return True if the sdcard is available, otherwise return false *///from ww w . j av a2 s .c o m public static boolean sdcardIsAvailable() { return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); }
From source file:Main.java
/** * obtain /sdcard/Android/data/[packagename]/files *//*from www . j a va2 s . com*/ public static String getSdFilesDir(Context context) { //TODO: check permission? if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { File filesDir = context.getExternalFilesDir(null); if (filesDir != null) { return filesDir.getAbsolutePath(); } else { return ""; } } else { return ""; } }
From source file:Main.java
public static File getDiskCacheDir(Context context, String uniqueName) { final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) ? getExternalCacheDir(context).getPath() : context.getCacheDir().getPath(); return new File(cachePath + File.separator + uniqueName); }
From source file:Main.java
public static String getFile(@NonNull Context context) { File savedir = null;/*from ww w . j a v a2 s.c o m*/ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { savedir = context.getExternalFilesDir(null); } if (savedir == null) { savedir = context.getFilesDir(); } if (!savedir.exists()) { savedir.mkdirs(); } return savedir.getAbsolutePath(); }
From source file:Main.java
public static boolean isSDCardPresent(final Activity a) { String storageState = Environment.getExternalStorageState(); return storageState.equals(Environment.MEDIA_MOUNTED); }
From source file:Main.java
@SuppressWarnings("WeakerAccess") public static File getAppCacheDir(Context context) { File appCacheDir = null;/*from w w w. jav a 2s . c om*/ if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { appCacheDir = context.getExternalCacheDir(); } if (appCacheDir == null) { appCacheDir = context.getCacheDir(); } return appCacheDir; }
From source file:Main.java
/** * @return {@code true} if external storage is available and writable. {@code false} otherwise. */// w w w . j av a 2 s .c o m public static boolean isExternalStorageAvailable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } return false; }
From source file:Main.java
public static String getRootFolder(@NonNull Context context) { String rootPath = null;/*w w w .j a v a2 s . c o m*/ if (android.os.Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { rootPath = Environment.getExternalStorageDirectory().getAbsolutePath(); } else { rootPath = context.getFilesDir().getAbsolutePath(); } return rootPath; }
From source file:Main.java
/** * clean external cache(/mnt/sdcard/android/data/com.xxx.xxx/cache) * * @param context/*from w ww . j a va2s .c o m*/ */ public static void cleanExternalCache(Context context) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { deleteFilesInDirectory(context.getExternalCacheDir()); } }
From source file:Main.java
public static File getCacheFile(@NonNull Context context, @NonNull String fileName) { File savedir = null;/* w ww . j ava 2s. c om*/ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { savedir = new File(context.getExternalCacheDir(), fileName); } if (savedir == null) { savedir = new File(context.getCacheDir(), fileName); } if (!savedir.exists()) { savedir.mkdirs(); } return savedir; }