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:ezy.boost.update.UpdateUtil.java

public static void setUpdate(Context context, String md5) {
    if (TextUtils.isEmpty(md5)) {
        return;/*from  ww w.j a  v a  2s.  c o m*/
    }
    SharedPreferences sp = context.getSharedPreferences(PREFS, 0);
    String old = sp.getString(KEY_UPDATE, "");
    if (md5.equals(old)) {
        return;
    }
    File oldFile = new File(context.getExternalCacheDir(), old);
    if (oldFile.exists()) {
        oldFile.delete();
    }
    sp.edit().putString(KEY_UPDATE, md5).apply();
    File file = new File(context.getExternalCacheDir(), md5);
    if (!file.exists()) {
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

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

@TargetApi(8)
public static File getExternalCacheDir(Context context) {
    if (Utils.hasFroyo()) {
        return context.getExternalCacheDir();
    }/*from  w w  w. j a  v  a2  s.c  o  m*/

    final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/";
    return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir);
}

From source file:org.inaturalist.android.GuideXML.java

/**
 * Returns all offline (downloaded) guides available
 * @param context//from   ww w.  j a v a 2  s  . com
 * @return
 */
public static List<GuideXML> getAllOfflineGuides(Context context) {
    ArrayList<GuideXML> guides = new ArrayList<GuideXML>();
    File rootDir = new File(context.getExternalCacheDir() + OFFLINE_GUIDE_PATH);
    File files[] = rootDir.listFiles();

    if (files == null)
        return guides;

    // Iterate over all directories in the offline guides root directory, and create
    // a new GuideXML instance for each.

    for (int i = 0; i < files.length; i++) {
        if (!files[i].isDirectory()) {
            continue;
        }
        String guideId = files[i].getName();

        guides.add(new GuideXML(context, guideId));
    }

    return guides;
}

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

public static void setUpdate(Context context, String md5) {
    if (TextUtils.isEmpty(md5)) {
        return;//from ww w  .  j  a  v a 2  s . c o m
    }
    SharedPreferences sp = context.getSharedPreferences(PREFS, 0);
    String old = sp.getString(PREFS_UPDATE, "");
    if (md5.equals(old)) {
        return;
    }
    File oldFile = new File(context.getExternalCacheDir(), old);
    if (oldFile.exists()) {
        oldFile.delete();
    }
    sp.edit().putString(PREFS_UPDATE, md5).apply();
    File file = new File(context.getExternalCacheDir(), md5);
    if (!file.exists()) {
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.egoists.coco_nut.android.cache.ImageCache.java

/**
 * Get the external app cache directory.
 * //from  www  . jav a  2  s  . c o  m
 * @param context The context to use
 * @return The external cache dir
 */
public static File getExternalCacheDir(Context context) {
    if (hasExternalCacheDir()) {
        File cacheDir = context.getExternalCacheDir();
        if (cacheDir != null) {
            return cacheDir;
        }
    }

    // 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.lovebridge.chat.view.ImageCache.java

/**
 * Get the external app cache directory.
 *
 * @param context The context to use/*from  ww  w.  ja va2  s. c  o  m*/
 * @return The external cache dir
 */
@TargetApi(VERSION_CODES.FROYO)
public static File getExternalCacheDir(Context context) {
    if (com.lovebridge.chat.utils.Utils.hasFroyo()) {
        return context.getExternalCacheDir();
    }
    // 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.android.pc.ioc.image.ImageCache.java

/**
 * Get the external app cache directory.
 * /*from www.  ja  va2  s.c  o m*/
 * @param context
 *            The context to use
 * @return The external cache dir
 */
@TargetApi(VERSION_CODES.FROYO)
public static File getExternalCacheDir(Context context) {
    if (Utils.hasFroyo()) {
        return context.getExternalCacheDir();
    }

    // Before Froyo we need to construct the external cache dir ourselves
    final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/images";
    return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir);
}

From source file:com.liangxun.university.huanxin.chat.video.util.VideoImageCache.java

/**
 * Get the external app cache directory.
 *
 * @param context The context to use/* w ww.ja va2 s . c o m*/
 * @return The external cache dir
 */
@TargetApi(VERSION_CODES.FROYO)
public static File getExternalCacheDir(Context context) {
    if (HxUtils.hasFroyo()) {
        return context.getExternalCacheDir();
    }

    // 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.conferenceengineer.android.iosched.util.ImageLoader.java

/**
 * Get the external app cache directory.
 *
 * @param context The context to use//from   ww w  . j  a v  a 2s .c o m
 * @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.miaotu.imutil.video.ImageCache.java

/**
 * Get the external app cache directory.
 * /* w  w w .j ava  2  s  .  c  om*/
 * @param context
 *            The context to use
 * @return The external cache dir
 */
@TargetApi(VERSION_CODES.FROYO)
public static File getExternalCacheDir(Context context) {
    if (Util.hasFroyo()) {
        return context.getExternalCacheDir();
    }

    // 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);
}