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 {
    private static boolean useExternalStorage = false;

    public static String storageDir(Context context) {
        if (useExternalStorage) {
            return extStorageDir(context);
        }
        File mediaStorageDir = context.getFilesDir();
        return mediaStorageDir.getPath() + File.separator;
    }

    public static String extStorageDir(Context context) {
        return extStorageDir(context.getPackageName());
    }

    public static String extStorageDir(String packageName) {
        // To be safe, you should check that the SDCard is mounted
        // using Environment.getExternalStorageState() before doing this.

        File mediaStorageDir = new File(Environment.getExternalStorageDirectory() + "/Android/data/"
        //+ getApplicationContext().getPackageName()
                + packageName + "/Files");

        // This location works best if you want the created images to be shared
        // between applications and persist after your app has been uninstalled.

        // Create the storage directory if it does not exist
        if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {
                return null;
            }
        }

        return mediaStorageDir.getPath() + File.separator;
    }
}