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 {
    /**
     * Get the left size of the SDCard in Bytes.
     * 
     * @return the left size
     */
    @SuppressWarnings("deprecation")
    public static long getSDCardLeftSize() {
        File sdcard = Environment.getExternalStorageDirectory();
        if (sdcard.exists()) {
            StatFs statFs = new StatFs(sdcard.getAbsolutePath());
            long blockSize = statFs.getBlockSize();
            long availableBlocks = statFs.getAvailableBlocks();

            return blockSize * availableBlocks;
        }

        return 0;
    }
}