Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (c) 2016-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the license found in the
 * LICENSE-examples file in the root directory of this source tree.
 */

import android.content.Context;
import android.os.Environment;

import java.io.File;

public class Main {
    /**
     * Helper method to initiate cache directory. It will return the cache directory in File format,
     * or NULL if the directory path is invalid or not accessible.
     */
    public static File getCacheDirectory(final Context context, final String path) {
        File cacheDir = null;
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            try {
                cacheDir = context.getExternalCacheDir();
            } catch (NullPointerException e) {
                // Fallback to use internal storage if external storage isn't available.
            }
        }
        if (cacheDir == null) {
            cacheDir = context.getCacheDir();
        }
        return (cacheDir != null && path != null) ? new File(cacheDir, path) : null;
    }
}