Obtain free external storage directory size,unit is MB - Android Hardware

Android examples for Hardware:SD Card

Description

Obtain free external storage directory size,unit is MB

Demo Code


//package com.java2s;

import java.io.File;

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

public class Main {
    /**//  w w  w  .  j av  a2s  .com
     * Obtain free external storage directory size,unit is MB
     * @param context
     * @deprecated
     * @return
     */
    public static final long obtainFreeExternalStorageDirectory() {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long availableBlocks = stat.getAvailableBlocks();
        long size = blockSize * availableBlocks / 1024 / 1024;
        return size;
    }
}

Related Tutorials