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.gelakinetic.mtgfam.helpers.lruCache.ImageCache.java

/**
 * Get a usable cache directory (external if available, internal otherwise).
 *
 * @param context    The context to use/*  ww  w .j  a  v a 2  s.  c  o m*/
 * @param uniqueName A unique directory name to append to the cache dir
 * @return The cache dir
 */
private static File getDiskCacheDir(Context context, String uniqueName) throws NullPointerException {
    // 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() ? context.getExternalCacheDir().getPath()
                    : context.getCacheDir().getPath();

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

From source file:android.bitmap.util.ImageCache.java

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

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

From source file:com.mklodoss.SexyGirl.displayingbitmaps.util.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 2  s .  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();
    android.util.Log.e(TAG, cachePath + File.separator + uniqueName);
    return new File(cachePath + File.separator + uniqueName);
}

From source file:com.simplelife.seeds.android.utils.gridview.gridviewutil.ImageCache.java

/**
 * Get a usable cache directory (external if available, internal otherwise).
 *
 * @param context The context to use/*from w w  w .j ava 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
    // ||!isExternalStorageRemovable()
    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:cc.yamyam.image.ImageCache.java

/**
 * Get a usable cache directory (external if available, internal otherwise).
 *
 * @param context The context to use/*from  www  .  ja va2s  .  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();
    //Log.i("yamyamcache","!!!cachepath:"+cachePath);
    //storage/emulated/0/Android/data/cc.yamyam/cache
    return new File(cachePath + File.separator + uniqueName);
}

From source file:com.github.piasy.biv.loader.fresco.ImageDownloadSubscriber.java

public ImageDownloadSubscriber(Context context) {
    mTempFile = new File(context.getCacheDir(), "" + System.currentTimeMillis() + ".png");
}

From source file:com.app.chasebank.bitmap.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 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
    boolean isExternalRemovable = isExternalStorageRemovable();
    boolean media_mounted_xternal = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
    String internalCache = context.getCacheDir().getPath();

    String xternalCacheDir = null;
    try {
        xternalCacheDir = getExternalCacheDir(context).getPath();
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    final String cachePath = isExternalRemovable || !media_mounted_xternal ? xternalCacheDir : internalCache;
    return new File(cachePath + File.separator + uniqueName);
}

From source file:com.fivehundredpxdemo.android.storage.ImageCache.java

/**
 * Get a usable cache directory (external if available, internal otherwise).
 *
 * @param context The context to use// w w w .java 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();
    // Only store internally due to security
    final String cachePath = context.getCacheDir().getPath();

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

From source file:com.cloudsynch.quickshare.utils.thumbnail.ImageCache.java

/**
 * Get a usable cache directory (external if available, internal otherwise).
 * /*from  w  w w  . j a v  a2  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
    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 new File(context.getCacheDir().getPath() + File.separator + uniqueName);
}

From source file:com.app.secnodhand.imageutil.ImageCache.java

/**
 * Get a usable cache directory (external if available, internal otherwise).
 * /*from   www.j  a  v a2 s  . c  om*/
 * @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
    try {
        if (Environment.MEDIA_MOUNTED != null) {
            final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
                    || !isExternalStorageRemovable() ? getExternalCacheDir(context).getPath()
                            : context.getCacheDir().getPath();
            return new File(cachePath + File.separator + uniqueName);
        } else {
            return null;
        }
    } catch (Exception e) {
        return null;
    }
}