Obtain SD card free size. - Android Hardware

Android examples for Hardware:SD Card

Description

Obtain SD card free size.

Demo Code


//package com.java2s;

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

public class Main {
    /**//  w  w w .java  2s.  c  om
     * Obtain SD card free size.
     * 
     * @return byte unit of SD card free size.
     */
    public static long getExternalStorageFreeSize() {
        final StatFs statfs = new StatFs(Environment
                .getExternalStorageDirectory().getAbsolutePath());
        final long availableBlocks = statfs.getAvailableBlocks();
        final long blockSize = statfs.getBlockSize();
        return availableBlocks * blockSize;
    }
}

Related Tutorials