get Disk Cache Dir - Android App

Android examples for App:Cache

Description

get Disk Cache Dir

Demo Code


//package com.book2s;
import java.io.File;

import android.content.Context;

import android.os.Environment;

public class Main {

    public static File getDiskCacheDir(Context context, String uniqueName) {
        final String cachePath = Environment.MEDIA_MOUNTED
                .equals(Environment.getExternalStorageState()) ? getExternalCacheDir(
                context).getPath()/* w w  w.ja  v  a  2 s .  c  om*/
                : context.getCacheDir().getPath();

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

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

Related Tutorials