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

@Deprecated
private static File getInternalCacheDirectory_Old(Context paramContext, String paramString) {
    File localFile1 = paramContext.getCacheDir();
    if (localFile1 != null)
        ;/*from  w  ww  . j a v a  2 s  . c om*/
    for (File localFile2 = new File(localFile1, paramString);; localFile2 = null)
        return localFile2;
}

From source file:Main.java

public static void deleteCache(Context context) {
    try {/*from   w  w w.  ja  va2  s  .  com*/
        File dir = context.getCacheDir();
        if (dir != null && dir.isDirectory()) {
            deleteDir(dir);
        }
    } catch (Exception e) {
    }
}

From source file:Main.java

public static File getPhotoCacheDir(Context context, File file) {
    File cacheDir = context.getCacheDir();
    if (cacheDir != null) {
        File mCacheDir = new File(cacheDir, DEFAULT_DISK_CACHE_DIR);
        if (!mCacheDir.mkdirs() && (!mCacheDir.exists() || !mCacheDir.isDirectory())) {
            return file;
        } else {/*from  w w  w. j a  va 2  s. c  o  m*/
            return new File(mCacheDir, file.getName());
        }
    }
    if (Log.isLoggable(TAG, Log.ERROR)) {
        Log.e(TAG, "default disk cache dir is null");
    }
    return file;
}

From source file:Main.java

private static File getFile(Context context, String fileName) {

    File dir = context.getCacheDir();
    dir.mkdirs();/*  w w w. j  a  va2  s.c  o m*/
    File file = new File(dir, fileName);

    return file;
}

From source file:Main.java

public static File getSDPath(Context context) {
    File sdDir = context.getCacheDir();
    boolean sdCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    if (sdCardExist) {
        sdDir = Environment.getExternalStorageDirectory();
    }//from   w  w w .j  a va 2  s .co  m
    return sdDir;
}

From source file:Main.java

/**
 * Helper method to retrieve the application internal storage cache
 * directory and make sure it exists.//w ww .  j  ava2s  .  c o m
 */
@CheckForNull
static File getInternalAppCacheDir(@Nonnull Context context) {
    File intCacheDir = context.getCacheDir();
    if (intCacheDir != null && !intCacheDir.exists()) {
        if (!intCacheDir.mkdirs() || !intCacheDir.canWrite()) {
            intCacheDir = null;
        }
    }
    return intCacheDir;
}

From source file:Main.java

private static File getOutputMediaFile(Context context, String thumbName) {
    File file = new File(context.getCacheDir() + "/thumbnails/" + thumbName + ".png");
    if (!file.exists()) {
        File mediaStorageDir = new File(context.getCacheDir() + "/thumbnails");

        // Create the storage directory if it does not exist
        if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {
                return null;
            }/*www  . ja va2 s .c o  m*/
        }
        // Create a media file name
        String mImageName = thumbName + ".png";
        File mediaFile = new File(mediaStorageDir.getPath() + File.separator + mImageName);
        return mediaFile;
    } else {
        return file;
    }
}

From source file:Main.java

public static File getFontDir(Context context) {

    File dir = null;//from   www .j av a2 s. c  o m
    dir = new File(context.getCacheDir() + File.separator + "wanjia" + File.separator + "font");
    File nomediaFile = new File(dir.getAbsolutePath() + File.separator + ".nomedia");
    if (!dir.exists()) {
        dir.mkdirs();
    }
    if (!nomediaFile.exists()) {
        try {
            nomediaFile.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return dir;
}

From source file:Main.java

public static File getMateralDir(Context context) {

    File dir = null;/*from w  ww .  j  av  a 2 s. c  o m*/
    dir = new File(context.getCacheDir() + File.separator + "wanjia" + File.separator + "material");
    File nomediaFile = new File(dir.getAbsolutePath() + File.separator + ".nomedia");
    if (!dir.exists()) {
        dir.mkdirs();
    }
    if (!nomediaFile.exists()) {
        try {
            nomediaFile.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return dir;
}

From source file:Main.java

public static void clearSystemCache(Context context) {
    try {/*  ww w  .jav a 2 s .  c  o  m*/
        File dir = context.getCacheDir();
        if (dir != null && dir.isDirectory()) {
            deleteDir(dir);
        }
    } catch (Exception e) {
    }
}