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 java.io.File;

public class Main {
    /**
     * Get a usable cache directory (external if available, internal otherwise)
     *
     * @param context The {@link android.content.Context} to use
     * @param uniqueName A unique directory name to append to the cache
     *            directory
     * @return The cache directory
     */
    public static File getCacheDir(final Context context, final String uniqueName) {
        File cachePath = context.getExternalCacheDir();
        if (cachePath == null || !cachePath.canWrite()) {
            cachePath = context.getCacheDir();
        }
        File cacheDir = new File(cachePath, uniqueName);
        if (!cacheDir.exists()) {
            cacheDir.mkdirs();
        }
        if (!cacheDir.canWrite()) {
            cacheDir.setWritable(true);
        }
        return cacheDir;
    }
}