Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;
import android.os.Environment;

public class Main {
    /**
     * Get the external storage path of the device
     *
     * @return The external storage path of the device.
     */
    public static String getStorageRootDirectory() {
        try {
            if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                return null;
            }
        } catch (Exception e) {
            // Catch exception is trying to fix a crash inside of Environment.getExternalStorageState().
            e.printStackTrace();
            return null;
        }
        String rootDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
        File file = new File(rootDir);
        if (!file.exists()) {
            if (!file.mkdirs()) {
                return null;
            }
        }
        return rootDir;
    }
}