Example usage for android.content Context getCacheDir

List of usage examples for android.content Context getCacheDir

Introduction

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

Prototype

public abstract File getCacheDir();

Source Link

Document

Returns the absolute path to the application specific cache directory on the filesystem.

Usage

From source file:com.lixiang.weather.support.http.ACache.java

public static ACache get(Context ctx, long max_zise, int max_count) {
    File f = new File(ctx.getCacheDir(), cacheName);
    return get(f, max_zise, max_count);
}

From source file:com.soubw.cache.ACache.java

public static ACache get(Context ctx, long max_size, int max_count) {
    File f = new File(ctx.getCacheDir(), "ACache");
    return get(f, max_size, max_count);
}

From source file:me.ihainan.bu.app.utils.ACache.java

public static ACache get(Context ctx, String cacheName) {
    File f = new File(ctx.getCacheDir(), "ACache");
    return get(f, MAX_SIZE, MAX_COUNT);
}

From source file:github.daneren2005.dsub.util.FileUtil.java

public static void deleteSerializedCache(Context context) {
    for (File file : context.getCacheDir().listFiles()) {
        if (file.getName().indexOf(".ser") != -1) {
            file.delete();/*from w  ww . jav a 2  s.c om*/
        }
    }
}

From source file:github.daneren2005.dsub.util.FileUtil.java

public static File getPodcastDirectory(Context context) {
    File dir = new File(context.getCacheDir(), "podcasts");
    ensureDirectoryExistsAndIsReadWritable(dir);
    return dir;/* w  w  w .j ava  2s  .  com*/
}

From source file:com.emin.digit.mobile.android.storage.cache.FileCache.java

public static FileCache get(Context ctx, long max_zise, int max_count) {
    File f = new File(ctx.getCacheDir(), CUSTOM_CACHE_DIR);
    return get(f, max_zise, max_count);
}

From source file:com.android.volley.plus.ImageCache.java

/**
 * Get a usable cache directory (external if available, internal otherwise).
 *
 * @param context    The context to use/*from  w w w  .j av a2 s .  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 , if so, try and use external cache dir
    // otherwise use internal cache dir
    if (!isSdCardOK()) {
        return null;
    }
    final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            ? getExternalCacheDir(context).getPath()
            : context.getCacheDir().getPath();

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

From source file:website.openeng.anki.web.HttpFetcher.java

public static String downloadFileToSdCardMethod(String UrlToFile, Context context, String prefix,
        String method) {//w ww .  jav a  2  s. c  o  m
    try {
        URL url = new URL(UrlToFile);

        String extension = UrlToFile.substring(UrlToFile.length() - 4);

        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestMethod(method);
        urlConnection.setRequestProperty("Referer", "website.openeng.anki");
        urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 ( compatible ) ");
        urlConnection.setRequestProperty("Accept", "*/*");
        urlConnection.setConnectTimeout(10000);
        urlConnection.setReadTimeout(60000);
        urlConnection.connect();

        File file = File.createTempFile(prefix, extension, context.getCacheDir());

        FileOutputStream fileOutput = new FileOutputStream(file);
        InputStream inputStream = urlConnection.getInputStream();

        byte[] buffer = new byte[1024];
        int bufferLength = 0;

        while ((bufferLength = inputStream.read(buffer)) > 0) {
            fileOutput.write(buffer, 0, bufferLength);
        }
        fileOutput.close();

        return file.getAbsolutePath();

    } catch (Exception e) {
        return "FAILED " + e.getMessage();
    }
}

From source file:com.likou.util.NImageLoader.java

/**
 * Get a usable cache directory (external if available, internal otherwise).
 * //  ww w.  j  a v  a2 s. com
 * @param context
 *            The context to use
 * @param uniqueName
 *            A unique directory name to append to the cache dir
 * @return The cache dir
 */
@SuppressLint("NewApi")
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

    // TODO: getCacheDir() should be moved to a background thread as it
    // attempts to create the
    // directory if it does not exist (no disk access should happen on the
    // main/UI thread).
    final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable() ? getExternalCacheDir(context).getPath()
                    : context.getCacheDir().getPath();

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

From source file:com.shenma.library.common.ACache.java

public static ACache get(Context ctx, String cacheName) {
    File f = new File(ctx.getCacheDir(), cacheName);
    Log.e("===", "acache path --> " + f.getAbsolutePath());
    return get(f, MAX_SIZE, MAX_COUNT);
}