Java tutorial
//package com.java2s; import android.content.Context; import android.os.Environment; import java.io.File; public class Main { 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()) || !Environment.isExternalStorageRemovable() ? Environment.getExternalStorageDirectory().getPath() : context.getCacheDir().getPath(); return new File(cachePath + File.separator + uniqueName); } }