Example usage for android.content Context getExternalCacheDir

List of usage examples for android.content Context getExternalCacheDir

Introduction

In this page you can find the example usage for android.content Context getExternalCacheDir.

Prototype

@Nullable
public abstract File getExternalCacheDir();

Source Link

Document

Returns absolute path to application-specific directory on the primary shared/external storage device where the application can place cache files it owns.

Usage

From source file:com.bt.download.android.util.SystemUtils.java

public static File getCacheDir(Context context, String directory) {
    File cache;/*  w  w w .ja v  a2s  . c  om*/

    if (isPrimaryExternalStorageMounted()) {
        cache = context.getExternalCacheDir();
    } else {
        cache = context.getCacheDir();
    }

    return new File(cache, directory);
}

From source file:com.isaacrf.epicbitmaprenderer.core.EpicBitmapCache.java

/**
 * Creates a unique subdirectory of the designated app cache directory. Tries to use external
 * but if not mounted, falls back on internal storage.
 *
 * @param context    Context from where EpicBitmapCache is being used.
 * @param uniqueName Unique name for cache directory.
 * @return {@link File} pointing to cache directory
 *//*from  w  w  w  .  j a v a  2 s. c  o  m*/
public static File getDiskCacheDir(Context context, String uniqueName) {
    File externalCacheDir = context.getExternalCacheDir();
    File cacheDir = context.getCacheDir();
    String cachePath;

    // Check if media is mounted or storage is built-in, if so, try and use external cache dir
    // otherwise use internal cache dir
    if ((Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) && externalCacheDir != null) {
        cachePath = externalCacheDir.getPath();
    } else {
        cachePath = cacheDir.getPath();
    }

    return new File(cachePath + File.separator + uniqueName);
}

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 {//w  ww.  java2  s.co 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:com.github.czy1121.update.app.utils.UpdateUtil.java

public static void clean(Context context) {
    SharedPreferences sp = context.getSharedPreferences(PREFS, 0);
    File file = new File(context.getExternalCacheDir(), sp.getString(PREFS_UPDATE, "") + ".apk");
    UpdateUtil.log("apk ==> " + file.toString());
    if (file.exists()) {
        file.delete();//  w  w w.j  a  v a 2  s .co  m
    }
    sp.edit().clear().apply();
}

From source file:ezy.boost.update.UpdateUtil.java

public static void clean(Context context) {
    SharedPreferences sp = context.getSharedPreferences(PREFS, 0);
    File file = new File(context.getExternalCacheDir(), sp.getString(KEY_UPDATE, "") + ".apk");
    UpdateUtil.log("apk ==> " + file.toString());
    if (file.exists()) {
        file.delete();/*w  ww .j  a  va  2 s  .  c  om*/
    }
    sp.edit().clear().apply();
}

From source file:ezy.boost.update.UpdateUtil.java

public static void install(Context context, boolean force) {
    String md5 = context.getSharedPreferences(PREFS, 0).getString(KEY_UPDATE, "");
    File apk = new File(context.getExternalCacheDir(), md5 + ".apk");
    if (UpdateUtil.verify(apk, md5)) {
        install(context, apk, force);//from  ww  w. j ava  2s .c  om
    }
}

From source file:com.github.czy1121.update.app.utils.UpdateUtil.java

public static void install(Context context, boolean force) {
    String md5 = context.getSharedPreferences(PREFS, 0).getString(PREFS_UPDATE, "");
    File apk = new File(context.getExternalCacheDir(), md5 + ".apk");
    if (UpdateUtil.verify(apk, md5)) {
        install(context, apk, force);/*from  ww w.  j  ava2 s. c o  m*/
    }
}

From source file:net.gree.asdk.core.imageloader.cache.ImageCache.java

@TargetApi(Build.VERSION_CODES.FROYO)
protected static File getExternalCacheDir(Context context) {
    if (Util.hasFroyo()) {
        File cacheDir = context.getExternalCacheDir();
        if (cacheDir != null) {
            return cacheDir;
        }/* w ww. ja  va2  s.co  m*/
    }
    final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/";
    return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir);
}

From source file:Main.java

/**
 * Get the external app cache directory.
 * //  ww  w .  j a v  a2 s  .  c  o m
 * @param context
 *            The context to use
 * @return The external cache dir
 */
private static File getExternalCacheDir(Context context) {
    // TODO: This needs to be moved to a background thread to ensure no disk
    // access on the
    // main/UI thread as unfortunately getExternalCacheDir() calls mkdirs()
    // for us (even
    // though the Volley library will later try and call mkdirs() as well
    // from a background
    // thread).
    return context.getExternalCacheDir();
}

From source file:com.allen.mediautil.ImageTakerHelper.java

/**
 * ???/*from   www .j ava 2 s .  com*/
 * ?????
 *
 * @param context Context
 * @return ?
 */
public static File getTmpSaveFilePath(Context context) {
    File f = new File(context.getExternalCacheDir(), "/camera/tmp.jpg");
    if (!f.getParentFile().exists()) {
        f.getParentFile().mkdirs();
    }
    return f;
}