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:Main.java

public static String getRootFilePath(Context context) {
    if (hasSDCard()) {
        //return Environment.getExternalStorageDirectory().getAbsolutePath();// filePath:/sdcard/android
        return context.getExternalCacheDir().getAbsolutePath();// filePath:/sdcard/android/+packageName+/cache
    } else {//  w  w  w.ja  va 2 s. c o  m
        return context.getCacheDir().getAbsolutePath(); // filePath: /data/data/
    }
}

From source file:it.restrung.rest.cache.RequestCache.java

/**
 * Invalidates the cache for the requesting context by removing all files associated with it
 *
 * @param context the requesting context
 *///from   w  w w.jav  a 2  s. com
public static void invalidateAll(Context context) {
    for (File file : context.getCacheDir().listFiles()) {
        if (file.getName().endsWith(CACHE_EXTENSION)) {
            file.delete();
        }
    }
}

From source file:de.spiritcroc.ownlog.FileHelper.java

static void onExit(Context context) {
    rmdir(context.getCacheDir());
}

From source file:Main.java

/**
 * Returns application cache directory. Cache directory will be created on SD card
 * <i>("/Android/data/[app_package_name]/cache")</i> if card is mounted. Else - Android defines cache directory on
 * device's file system.//from  w w  w . jav a  2s .c o m
 * 
 * @param context Application context
 * @return Cache {@link File directory}
 */
public static File getCacheDirectory(Context context) {
    File appCacheDir = null;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        appCacheDir = getExternalCacheDir(context);
    }
    if (appCacheDir == null) {
        appCacheDir = context.getCacheDir();
    }
    return appCacheDir;
}

From source file:de.spiritcroc.ownlog.FileHelper.java

private static File getExportPath(Context context) {
    return new File(context.getCacheDir(), EXPORT_PATH);
}

From source file:Main.java

public static String createRootPath(Context context) {
    String cacheRootPath = "";
    if (isSdCardAvailable()) {
        // /sdcard/Android/data/<application package>/cache
        cacheRootPath = context.getExternalCacheDir().getPath();
    } else {// ww w  . j  a v a2s  . c o  m
        // /data/data/<application package>/cache
        cacheRootPath = context.getCacheDir().getPath();
    }
    return cacheRootPath;
}

From source file:Main.java

public static File getDiskAppCacheDir(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 File externalCache = getExternalCacheDir(context);
    final String cachePath = (externalCache == null) ? context.getCacheDir().getPath()
            : externalCache.getPath();/*from www  .  j av a2  s  . c  om*/

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

From source file:Main.java

public static File getCacheDirectory(Context context) {
    File appCacheDir = null;/*from  w  w w .  jav a 2  s .  com*/
    if (MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && hasExternalStoragePermission(context)) {
        appCacheDir = getExternalCacheDir(context);
    }
    if (appCacheDir == null) {
        appCacheDir = context.getCacheDir();
    }
    if (appCacheDir == null) {
        Log.w(TAG, "Can't define system cache directory! The app should be re-installed.");
    }
    return appCacheDir;
}

From source file:Main.java

public static File getCacheFile(@NonNull Context context, @NonNull String fileName) {
    File savedir = null;/*w w  w  . j  a v a 2 s.co  m*/
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        savedir = new File(context.getExternalCacheDir(), fileName);
    }

    if (savedir == null) {
        savedir = new File(context.getCacheDir(), fileName);
    }

    if (!savedir.exists()) {
        savedir.mkdirs();
    }
    return savedir;
}

From source file:com.ruesga.rview.misc.CacheHelper.java

@SuppressWarnings("ResultOfMethodCallIgnored")
public static File getImagesCacheDir(Context context) {
    File cacheDir = new File(context.getCacheDir(), IMAGES_CACHE_FOLDER);
    if (!cacheDir.exists()) {
        cacheDir.mkdir();/*from ww w .  j  ava  2s. c  o m*/
    }
    return cacheDir;
}