Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.os.Environment;
import android.os.StatFs;

import java.io.File;

public class Main {

    public static String getSavePath() {
        String savePath = null;
        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
            savePath = Environment.getExternalStorageDirectory().getAbsolutePath();
        } else {
            File[] files = new File("/mnt/").listFiles();
            if (files.length > 0) {
                String filePath = null;
                for (int p = 0; p < files.length; p++) {
                    if (files[p].isDirectory()) {
                        if (files[p].getPath().indexOf("sdcard") >= 0) {
                            StatFs st = new StatFs(files[p].getPath());
                            int blocksize = st.getBlockSize();
                            int blockcount = st.getBlockCount();
                            if ((blocksize * blockcount) > 0) {
                                filePath = files[p].getPath();
                            }
                        }

                    }
                }
                if (filePath != null) {
                    savePath = filePath;
                } else {
                    savePath = null;
                }
            }
        }
        return savePath;
    }
}