Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;
import android.os.Environment;
import java.io.File;

public class Main {
    /**
     * Get disk cache directory
     *
     * @param ctx
     * @param uniqueName Unique name for caching directory, use it separate different types of cached files. eg: bitmap,strings,css,files etc.
     * @return cache directory
     */
    public static File getDiskCacheDir(Context ctx, String uniqueName) {

        String cachePath;
        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
                || !Environment.isExternalStorageRemovable()) {
            cachePath = ctx.getExternalCacheDir().getPath();
        } else {
            cachePath = ctx.getCacheDir().getPath();
        }

        return new File(cachePath, uniqueName);
    }
}