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.support.annotation.Nullable;
import java.io.File;

public class Main {
    /**
     * Application cache sub-directory. Note that this name must be exactly the
     * same name used in the resource xml/file_paths.xml to support the
     * applications file provider implementation.
     */
    private static final String CACHE_DIRNAME = "download";

    /**
     * Creates a file object with the specified name in the application cache
     * directory.
     *
     * @param fileName A file name string.
     * @return A file object with the specified name
     */
    @Nullable
    public static File getCacheFile(Context context, String fileName) {
        return new File(getCacheDirPathName(context) + File.separator + fileName);
    }

    /**
     * Gets the current application cache directory path in private storage.
     *
     * @param context Any context.
     * @return The default application cache directory path.
     */
    public static String getCacheDirPathName(Context context) {
        return context.getApplicationContext().getCacheDir() + File.separator + getCacheDirName();
    }

    /**
     * @return Application cache directory sub-folder name.
     */
    private static String getCacheDirName() {
        return CACHE_DIRNAME;
    }
}