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 long getSdAvailaleSize() {
        if (!isSdCardExist()) {
            return 0;
        }

        StatFs stat = new StatFs(getSDPath());
        long blockSize = stat.getBlockSize();
        long availableBlocks = stat.getAvailableBlocks();
        return availableBlocks * blockSize;
    }

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

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

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