List of usage examples for android.content Context getCacheDir
public abstract File getCacheDir();
From source file:com.zhiyicx.zycx.sociax.gimgutil.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * * @param context The context to use//from w ww . j a v a 2 s . c o m * @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 extStoreState = Environment.getExternalStorageState(); String extCachePath = getExternalCacheDir(context).getPath(); String cacheDirPath = context.getCacheDir().getPath(); final String cachePath = Environment.MEDIA_MOUNTED.equals(extStoreState) || !isExternalStorageRemovable() ? extCachePath : cacheDirPath; return new File(cachePath + File.separator + uniqueName); }
From source file:com.android.framework.core.image.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * * @param context The context to use// www . j a v a 2 s .co m * @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 = getExternalCacheDir(context); final String cachePath = (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !isExternalStorageRemovable()) && externalCacheDir != null ? externalCacheDir.getPath() : cacheDirPath; return new File(cachePath + File.separator + uniqueName); }
From source file:com.emin.digit.mobile.android.storage.cache.FileCache.java
public static FileCache get(Context ctx, String cacheName) { debug("0 ---- ctx.getCacheDir().getAbsolutePath():" + ctx.getCacheDir().getAbsolutePath()); File f = new File(ctx.getCacheDir(), cacheName); return get(f, MAX_SIZE, MAX_COUNT); }
From source file:com.xiaochao.lcrapiddeveloplibrary.Cache.ACache.java
public static ACache get(Context ctx, long max_zise, int max_count) { File f = new File(ctx.getCacheDir(), "youzyToB"); return get(f, max_zise, max_count); }
From source file:com.msx7.image.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * * @param context The context to use//from w w w.java2s. com * @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 boolean flag = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !isExternalStorageRemovable(); String str1 = getExternalCacheDir(context).getPath(); String str2 = context.getCacheDir().getPath(); final String cachePath = flag ? str1 : str2; return new File(cachePath + File.separator + uniqueName); }
From source file:com.hz_library.utils.ACache.java
public static ACache get(Context ctx, long max_zise, int max_count) { File f = new File(ctx.getCacheDir(), "XcgooCache"); return get(f, max_zise, max_count); }
From source file:com.roach.framework.cache.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * * @param context The context to use/*from w ww . java2 s .c o m*/ * @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 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:org.odk.collect.android.utilities.MediaUtils.java
private static File getGoogleDriveFile(Context context, Uri uri) throws GDriveConnectionException { if (!Collect.getInstance().isNetworkAvailable()) { throw new GDriveConnectionException(); }/* w w w . j a v a 2 s. c om*/ if (uri == null) { return null; } FileInputStream inputStream = null; FileOutputStream outputStream = null; String filePath = new File(context.getCacheDir(), "tmp").getAbsolutePath(); try { ParcelFileDescriptor parcelFileDescriptor = context.getContentResolver().openFileDescriptor(uri, "r"); if (parcelFileDescriptor == null) { return null; } FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); inputStream = new FileInputStream(fileDescriptor); outputStream = new FileOutputStream(filePath); int read; byte[] bytes = new byte[4096]; while ((read = inputStream.read(bytes)) != -1) { outputStream.write(bytes, 0, read); } return new File(filePath); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); } return null; }
From source file:com.plusub.lib.util.CacheUtils.java
public static CacheUtils get(Context ctx, String cacheName) { File f = new File(ctx.getCacheDir(), cacheName); return get(f, MAX_SIZE, MAX_COUNT); }
From source file:com.discogs.utils.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * * @param context The context to use//from ww w . j a v a2s . c o m * @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 // final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !isExternalStorageRemovable() ? getExternalCacheDir(context).getPath() : context.getCacheDir().getPath(); final String cachePath = context.getCacheDir().getPath(); return new File(cachePath + File.separator + uniqueName); }