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.ultramegasoft.flavordex2.util.PhotoUtils.java

/**
 * Get a Bitmap file for an entry.//w w w .ja v  a 2 s . com
 *
 * @param context The Context
 * @param id      The entry ID
 * @return A reference to the image file
 */
@NonNull
private static File getThumbFile(@NonNull Context context, long id) {
    final String fileName = THUMB_FILE_PREFIX + id + JPEG_FILE_SUFFIX;
    return new File(context.getCacheDir(), fileName);
}

From source file:gr.unfold.android.tsibato.images.ImageCache.java

/** Get a usable cache directory (external if available, internal otherwise). */
public static File getDiskCacheDir(Context context, String uniqueName) {
    //If storage built-in or media mounted use external storage, otherwise use internal
    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:at.jclehner.rxdroid.Backup.java

private static void encrypt(Context context, File backup, String password) throws ZipException, IOException {
    final BackupFile bf = new BackupFile(backup.getAbsolutePath());
    if (!bf.isValid() || bf.isEncrypted())
        return;/*ww w.j  a  va2  s .c om*/

    Log.i(TAG, "Encrypting " + backup);

    final File tmpDir = new File(context.getCacheDir(), "tmp");
    tmpDir.mkdirs();

    final File tmpFile = new File(tmpDir, "tmp.rxdbak");

    bf.getZip().extractAll(tmpDir.getAbsolutePath());
    tmpFile.delete();
    createBackup(tmpFile, password, tmpDir.getAbsolutePath(), bf.getTimestamp().getTime());
    Util.copyFile(tmpFile, backup);
}

From source file:com.momock.util.Logger.java

public static void open(Context context, String logfilename, int level) {
    if (!enabled)
        return;// www. j  a va 2 s. c o  m
    logFileName = logfilename;
    if (logStream == null) {
        logStream = System.out;
        File logDir = null;
        try {
            if (getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                logDir = Environment.getExternalStorageDirectory();
            } else if (context != null) {
                logDir = context.getCacheDir();
            }
            if (logDir != null) {
                android.util.Log.d("Logger", logDir.getAbsolutePath());
                logStream = new PrintStream(new FileOutputStream(new File(logDir, logFileName), false));
            }
        } catch (IOException e) {
            android.util.Log.e("Logger", "Fails to create log file!", e);
        }
    }
    logLevel = level;

    logStream.println("========== Logger Begin ==========");
    logStream.flush();
}

From source file:com.rocko.io.ACache.java

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

From source file:ch.uzh.supersede.feedbacklibrary.utils.Utils.java

/**
 * This method creates a temporary file in the cache directory.
 *
 * @param context the context of the application
 * @param prefix  the prefix, e.g., crop
 * @param suffix  the suffix, e.g., .jpg
 * @return the created file, or null if an exception occurred
 *///  w ww . j a  v a2  s  .com
@Nullable
public static File createTempChacheFile(Context context, String prefix, String suffix) {
    try {
        return File.createTempFile(prefix, suffix, context.getCacheDir());
    } catch (IOException e) {
        Log.e(TAG, "Failed to create a temporary file", e);
    }
    return null;
}

From source file:com.gdgdevfest.android.apps.devfestbcn.util.ImageLoader.java

/**
 * Get a usable cache directory (external if available, internal otherwise).
 *
 * @param context The context to use/*from  w w w .java 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

    // 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.rocko.io.ACache.java

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

From source file:com.lovebridge.chat.view.ImageCache.java

/**
 * Get a usable cache directory (external if available, internal otherwise).
 *
 * @param context The context to use/*from  www.j  a  va2s  .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
    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:caesar.feng.framework.utils.ACache.java

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