Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

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

import java.io.File;

public class Main {
    public static long getTotalExternalMemorySize(Context context) {
        if (!isHaveSDCard()) {
            return -1;
        }
        StatFs sFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
        long blockSize = sFs.getBlockSize();
        long totalBlocks = sFs.getBlockCount();
        return blockSize * totalBlocks;
    }

    public long getTotalExternalMemorySize() {
        if (!isHaveSDCard()) {
            return -1;
        }
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long blockCount = stat.getBlockCount();
        return blockSize * blockCount;
    }

    public static boolean isHaveSDCard() {
        String status = Environment.getExternalStorageState();
        return status.equals(Environment.MEDIA_MOUNTED);
    }
}