List of usage examples for android.content Context getCacheDir
public abstract File getCacheDir();
From source file:com.haipeng.libraryforandroid.cacheormemory.imageload.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * * @param context The context to use/*ww w . java 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).getPath() : context.getCacheDir().getPath(); return new File(cachePath + File.separator + uniqueName); }
From source file:com.bbxiaoqu.api.util.Utils.java
public static void clearCache(Context context) { File file = Environment.getDownloadCacheDirectory(); File[] files = file.listFiles(); if (files != null) { for (File f : files) { f.delete();// w w w. j ava 2s . c o m } } file = context.getCacheDir(); files = file.listFiles(); if (files != null) { for (File f : files) { f.delete(); } } }
From source file:com.plusub.lib.util.CacheUtils.java
public static CacheUtils get(Context ctx, long max_zise, int max_count) { File f = new File(ctx.getCacheDir(), "CacheUtils"); return get(f, max_zise, max_count); }
From source file:com.zz.lib.bitmapfun.util.ImageCache.java
/** * Get the external app cache directory. * * @param context The context to use/*from ww w .j a v a 2 s. c o m*/ * @return The external cache dir */ @TargetApi(8) public static File getExternalCacheDir(Context context) { if (Utils.hasFroyo()) { File ret = context.getExternalCacheDir(); if (ret != null) return ret; } if (getUsableSpace(Environment.getExternalStorageDirectory()) < 1024 * 100) { //! SD?? return context.getCacheDir(); } // Before Froyo we need to construct the external cache dir ourselves final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/"; return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir); }
From source file:com.codingPower.framework.worker.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * * @param context The context to use//from w ww . java 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 String cachePath = null; if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !isExternalStorageRemovable()) { cachePath = getExternalCacheDir(context).getPath(); } else { cachePath = context.getCacheDir().getPath(); } return new File(cachePath + File.separator + uniqueName); }
From source file:com.guodong.sun.guodong.uitls.CacheUtil.java
public static CacheUtil get(Context ctx, long maxSise, int maxCount) { File f = new File(ctx.getCacheDir(), "ACache"); return get(f, maxSise, maxCount); }
From source file:com.crte.sipstackhome.ui.preferences.PreferencesWrapper.java
/** * //w ww.j a va2 s . co m * @param ctxt * @param preferCache * @return */ private static File getStorageFolder(Context ctxt, boolean preferCache) { File root = Environment.getExternalStorageDirectory(); if (!root.canWrite() || preferCache) { root = ctxt.getCacheDir(); } if (root.canWrite()) { File dir = new File(root.getAbsolutePath() + File.separator + /*CustomDistribution.getSDCardFolder()*/ "SipStackHome"); if (!dir.exists()) { dir.mkdirs(); Log.d(THIS_FILE, " " + dir.getAbsolutePath()); } return dir; } return null; }
From source file:com.data.pack.Util.java
public static void clearCacheVideos(Context context, ArrayList<String> list) { try {//from ww w . j a v a 2 s. c o m ArrayList<String> finalFilelist = new ArrayList<String>(); String deletedFile = ""; for (int i = 0; i < list.size(); ++i) { finalFilelist.add(list.get(i)); } String cacheFiles = finalFilelist.toString(); File cacheDir = context.getCacheDir(); File[] files = cacheDir.listFiles(); if (files != null) { for (File file : files) { String fname = file.getName(); if (!fname.equalsIgnoreCase("completed_exercise_de.mp4") && !fname.equalsIgnoreCase("completed_exercise.mp4") && !fname.equalsIgnoreCase("next_exercise_de.mp4") && !fname.equalsIgnoreCase("next_exercise.mp4") && !fname.equalsIgnoreCase("otherside_exercise_de.mp4") && !fname.equalsIgnoreCase("otherside_exercise.mp4") && !fname.equalsIgnoreCase("recovery_15_de.mp4") && !fname.equalsIgnoreCase("recovery_15.mp4") && !fname.equalsIgnoreCase("recovery_30_de.mp4") && !fname.equalsIgnoreCase("recovery_30.mp4") && !fname.equalsIgnoreCase("stop_exercise_de.mp4") && !fname.equalsIgnoreCase("stop_exercise.mp4") && fname.contains(".mp4") ) if (file.exists()) { deletedFile = fname; if (!cacheFiles.contains(deletedFile) && deletedFile.contains(".mp4")) { file.delete(); } } } } } catch (Exception e) { // TODO: handle exception String st = e.toString(); st = st + ""; } }
From source file:com.gm.goldencity.util.Utils.java
/** * Making empty all application data in cache * * @param context Application context//from w w w . j a v a 2s.c o m * @return */ public static Boolean emptyAllApplicationData(Context context) { File cache = context.getCacheDir(); File appDir = new File(cache.getParent()); if (appDir.exists()) { String[] children = appDir.list(); for (String s : children) { if (!s.equals("databases")) { deleteDir(new File(appDir, s)); } } } return true; }
From source file:fm.jihua.weixinexplorer.cache.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * * @param context The context to use//from ww w . j a v a 2 s . 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 try { final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !isExternalStorageRemovable() ? getExternalCacheDir(context).getPath() : context.getCacheDir().getPath(); return new File(cachePath + File.separator + uniqueName); } catch (Exception e) { e.printStackTrace(); } return null; }