Java tutorial
//package com.java2s; import java.io.File; import android.content.Context; import android.util.Log; public class Main { public static final String TAG = "Utils"; public static File createCacheDir(Context context, String dirName) { File preparedDir; if (android.os.Environment.MEDIA_MOUNTED.equals(android.os.Environment.getExternalStorageState())) { preparedDir = context.getDir(dirName /* + UUID.randomUUID().toString()*/, Context.MODE_PRIVATE); Log.i(TAG, "Cache dir initialized at SD card " + preparedDir.getAbsolutePath()); } else { preparedDir = context.getCacheDir(); Log.i(TAG, "Cache dir initialized at phone storage " + preparedDir.getAbsolutePath()); } if (!preparedDir.exists()) { Log.i(TAG, "Cache dir not existed, creating"); preparedDir.mkdirs(); } return preparedDir; } }