Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.os.Environment;
import android.os.StatFs;
import java.io.File;

public class Main {

    public static int freeSpaceOnSd() {
        StatFs stat = new StatFs(getSDPath());
        double sdFree = ((double) stat.getAvailableBlocks() * (double) stat.getBlockSize());
        return (int) sdFree;
    }

    public static String getSDPath() {
        String result = "";
        File sdDir = null;
        if (isSdCardExist()) {
            sdDir = Environment.getExternalStorageDirectory();
        }

        if (sdDir != null) {
            result = sdDir.getPath();
        }
        return result;
    }

    public static boolean isSdCardExist() {
        return Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
    }
}