/** * Get a usable cache directory (external if available, internal otherwise). * * @param context The context to use * @param uniqueName A unique directory name to append to the cache dir * @return The cache dir */ public static File getDiskCacheDir(Context context, String uniqueName) { // Check if media is mounted or storage is built-in, if so, try and use // external cache dir // otherwise use internal cache dir String cacheDirPath = ""; if (context != null && context.getCacheDir() != null) { cacheDirPath = context.getCacheDir().getPath(); } File externalCacheDir = CacheUtils.getExternalCacheDir(context); final String cachePath = (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !CacheUtils.isExternalStorageRemovable()) && externalCacheDir != null ? externalCacheDir.getPath() : cacheDirPath; return new File(cachePath + File.separator + uniqueName); }