List of usage examples for android.content Context getCacheDir
public abstract File getCacheDir();
From source file:fm.moe.android.util.JSONFileHelper.java
public static String getFilePath(final Context context, final String filename) { if (context == null || filename == null) return null; final File cache_dir; if (getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { cache_dir = new File(context.getExternalCacheDir(), JSON_CACHE_DIR); } else {/* ww w . j a va 2 s. c o m*/ cache_dir = new File(context.getCacheDir(), JSON_CACHE_DIR); } if (!cache_dir.exists()) { cache_dir.mkdirs(); } final File cache_file = new File(cache_dir, filename); return cache_file.getPath(); }
From source file:Main.java
/** * @param context//w w w . j a v a 2 s. co m * @param dirName Only the folder name, not full path. * @return app_cache_path/dirName */ public static String getDiskCacheDir(Context context, String dirName) { String cachePath = null; if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { File externalCacheDir = context.getExternalCacheDir(); if (externalCacheDir != null) { cachePath = externalCacheDir.getPath(); } } if (cachePath == null) { File cacheDir = context.getCacheDir(); if (cacheDir != null && cacheDir.exists()) { cachePath = cacheDir.getPath(); } } return cachePath + File.separator + dirName; }
From source file:Main.java
public static File getDiskCacheDir(Context context, String uniqueName) { String cachePath;//w w w.ja v a2 s .com if ((Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) && context.getExternalCacheDir() != null && !TextUtils.isEmpty(context.getExternalCacheDir().getPath())) { cachePath = context.getExternalCacheDir().getPath(); } else { cachePath = context.getCacheDir().getPath(); } return new File(cachePath + File.separator + uniqueName); }
From source file:com.github.chenxiaolong.dualbootpatcher.patcher.PatcherUtils.java
public static PatcherConfig newPatcherConfig(Context context) { PatcherConfig pc = new PatcherConfig(); pc.setDataDirectory(getTargetDirectory(context).getAbsolutePath()); pc.setTempDirectory(context.getCacheDir().getAbsolutePath()); return pc;/* w w w. ja va 2 s. c o m*/ }
From source file:Main.java
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 final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !isExternalStorageRemovable() ? getExternalCacheDir(context).getPath() : context.getCacheDir().getPath(); return new File(cachePath + File.separator + uniqueName); }
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 and app has appropriate permission. Else - Android defines cache directory on device's file system. * * @param context Application context//from w ww . j av a 2 s. c om * @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 (MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && hasExternalStoragePermission(context)) { appCacheDir = new File(Environment.getExternalStorageDirectory(), cacheDir); } if (appCacheDir == null || (!appCacheDir.exists() && !appCacheDir.mkdirs())) { appCacheDir = context.getCacheDir(); } return appCacheDir; }
From source file:org.envirocar.app.util.Util.java
public static File resolveCacheFolder(Context ctx) { return ctx.getCacheDir(); }
From source file:Main.java
/** * Helper method to initiate cache directory. It will return the cache directory in File format, * or NULL if the directory path is invalid or not accessible. *//*from www. j a v a 2 s .com*/ public static File getCacheDirectory(final Context context, final String path) { File cacheDir = null; if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { try { cacheDir = context.getExternalCacheDir(); } catch (NullPointerException e) { // Fallback to use internal storage if external storage isn't available. } } if (cacheDir == null) { cacheDir = context.getCacheDir(); } return (cacheDir != null && path != null) ? new File(cacheDir, path) : null; }
From source file:net.gree.asdk.core.imageloader.cache.ImageCache.java
public static File getDiskCacheDir(Context context, String uniqueName) { String cachePath = getExternalCacheDir(context).getPath(); if (TextUtils.isEmpty(cachePath)) { cachePath = context.getCacheDir().getPath(); }/*w w w . java 2 s .c o m*/ return new File(cachePath + File.separator + uniqueName); }
From source file:org.mariotaku.twidere.loader.Twitter4JActivitiesLoader.java
public static void writeSerializableStatuses(final Object instance, final Context context, final List<Activity> data, final Bundle args) { if (instance == null || context == null || data == null || args == null) return;//from w w w . j a va 2 s . co m final long account_id = args.getLong(INTENT_KEY_ACCOUNT_ID, -1); try { final FileOutputStream fos = new FileOutputStream( new File(context.getCacheDir(), instance.getClass().getSimpleName() + "." + account_id)); final ObjectOutputStream os = new ObjectOutputStream(fos); os.writeObject(data); os.close(); fos.close(); } catch (final IOException e) { } }