List of usage examples for android.content Context getCacheDir
public abstract File getCacheDir();
From source file:com.apptentive.android.sdk.util.Util.java
public static File getDiskCacheDir(Context context) { File appCacheDir = null;//from ww w. j a v a 2s .c o m if ((Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) && hasPermission(context, "android.permission.WRITE_EXTERNAL_STORAGE")) { appCacheDir = context.getExternalCacheDir(); } if (appCacheDir == null && context != null) { appCacheDir = context.getCacheDir(); } return appCacheDir; }
From source file:com.utils.image.cache.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise) * /*from w w w . j a v a 2 s. com*/ * @param context The {@link Context} to use * @param uniqueName A unique directory name to append to the cache * directory * @return The cache directory */ public static final File getDiskCacheDir(final Context context, final String uniqueName) { // final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment // .getExternalStorageState()) || !isExternalStorageRemovable() ? getExternalCacheDir( // context).getPath() : context.getCacheDir().getPath();//sd? final String cachePath = context.getCacheDir().getPath();// return new File(cachePath + File.separator + uniqueName); }
From source file:me.zhang.accountbook.util.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * * @param context The context to use//from ww w.j a va 2s .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); }
From source file:free.rm.skytube.gui.businessobjects.updates.UpgradeAppTask.java
public UpgradeAppTask(URL apkUrl, Context context) { this.apkUrl = apkUrl; this.context = context; this.apkDir = context.getCacheDir(); }
From source file:com.scanvine.android.util.SVDownloadManager.java
public File cacheFor(Context context, String urlString) { String fileName = Util.ConvertUrlToFilename(urlString); return new File(context.getCacheDir(), fileName); }
From source file:com.xlythe.engine.theme.Theme.java
public static Typeface getFont(Context context, String name) { String key = getKey(context) + "_" + name; if (TYPEFACE_MAP.containsKey(key)) { return TYPEFACE_MAP.get(key); }/* w w w . ja v a2 s. co m*/ String[] extensions = { ".ttf", ".otf" }; for (String s : extensions) { try { // Use cursor loader to grab font String url = getPackageName() + ".FileProvider/" + name + s; Uri uri = Uri.parse("content://" + url); ContentResolver cr = context.getContentResolver(); AssetFileDescriptor a = cr.openAssetFileDescriptor(uri, null); FileInputStream in = new FileInputStream(a.getFileDescriptor()); in.skip(a.getStartOffset()); File file = new File(context.getCacheDir(), name + s); file.createNewFile(); FileOutputStream fOutput = new FileOutputStream(file); byte[] dataBuffer = new byte[1024]; int readLength = 0; while ((readLength = in.read(dataBuffer)) != -1) { fOutput.write(dataBuffer, 0, readLength); } in.close(); fOutput.close(); // Try/catch for broken fonts Typeface t = Typeface.createFromFile(file); TYPEFACE_MAP.put(key, t); return TYPEFACE_MAP.get(key); } catch (Exception e) { // Do nothing here } } TYPEFACE_MAP.put(key, null); return TYPEFACE_MAP.get(key); }
From source file:com.rivbird.guichecker.bitmapfun.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * * @param context The context to use// w w w. j a v a 2s . c om * @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) != null ? getExternalCacheDir(context).getPath() : context.getCacheDir().getPath()) : context.getCacheDir().getPath(); return new File(cachePath + File.separator + uniqueName); }
From source file:com.android.calculator2.BitmapTask.java
private File getCacheFile(Context context, String url) { if (url != null && !"".equals(url)) { try {/*from ww w . j a va2 s . c o m*/ return new File(context.getCacheDir() + File.separator + URLEncoder.encode(url, "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return null; }
From source file:com.baasbox.android.HttpUrlConnectionClient.java
private void enableHttpCacheIfAvailable(Context context, long cacheSize) { File httpCacheDir = new File(context.getCacheDir(), "baashttpcache"); try {//from w w w . ja va 2 s. c o m Class.forName("android.net.http.HttpResponseCache").getMethod("install", File.class, long.class) .invoke(null, httpCacheDir, cacheSize); Logger.debug("Installed http cache"); } catch (Exception e) { Logger.debug("HttpResponseCache not available"); } }
From source file:com.kaplandroid.colorbook.utils.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * //w w w. j a va 2 s. c o m * @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 /* * final String cachePath = * Environment.MEDIA_MOUNTED.equals(Environment. * getExternalStorageState()) || !isExternalStorageRemovable() ? * getExternalCacheDir(context).getPath() : * context.getCacheDir().getPath(); */ final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Utils.isExternalStorageRemovable() ? Utils.getExternalCacheDir(context).getPath() : context.getCacheDir().getPath(); return new File(cachePath + File.separator + uniqueName); }