Example usage for android.os StatFs StatFs

List of usage examples for android.os StatFs StatFs

Introduction

In this page you can find the example usage for android.os StatFs StatFs.

Prototype

public StatFs(String path) 

Source Link

Document

Construct a new StatFs for looking at the stats of the filesystem at path .

Usage

From source file:com.zz.lib.bitmapfun.util.ImageCache.java

/**
 * Check how much usable space is available at a given path.
 *
 * @param path The path to check//w w w.  ja  v  a2  s . c o  m
 * @return The space available in bytes
 */
@TargetApi(9)
public static long getUsableSpace(File path) {
    if (Utils.hasGingerbread()) {
        return path.getUsableSpace();
    }
    if (!path.exists())
        return 0;
    final StatFs stats = new StatFs(path.getPath());
    return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
}

From source file:com.att.android.arodatacollector.utils.AROCollectorUtils.java

/**
 * Returns the amount of available memory left on the device SD Card (in
 * bytes)./*from   w  w w.  j av  a 2  s  .  c o  m*/
 */
public long checkSDCardMemoryAvailable() {
    final StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    final long bytesAvailable = (long) stat.getBlockSize() * (long) stat.getAvailableBlocks();
    final long kbsAvailable = bytesAvailable / 1024;
    // float megAvailable = (long) (bytesAvailable / (1024.f * 1024.f));
    return kbsAvailable;
}

From source file:com.almalence.util.Util.java

public static long FreeExternalMemory() {
    StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
    long blockSize = statFs.getBlockSize();
    long availableBloks = statFs.getAvailableBlocks();
    return (availableBloks * blockSize) / 1048576;
}

From source file:com.almalence.util.Util.java

public static long BusyDeviceMemory() {
    StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
    long Total = (statFs.getBlockCount() * statFs.getBlockSize()) / 1048576;
    long Free = (statFs.getAvailableBlocks() * statFs.getBlockSize()) / 1048576;
    return (Total - Free);
}

From source file:org.akvo.flow.activity.SurveyActivity.java

public void spaceLeftOnCard() {
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        // TODO: more specific warning if card not mounted?
    }//  www .j  a v  a2  s. c o m
    // compute space left
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    double sdAvailSize = (double) stat.getAvailableBlocks() * (double) stat.getBlockSize();
    // One binary gigabyte equals 1,073,741,824 bytes.
    // double gigaAvailable = sdAvailSize / 1073741824;
    // One binary megabyte equals 1 048 576 bytes.
    long megaAvailable = (long) Math.floor(sdAvailSize / 1048576.0);

    // keep track of changes
    SharedPreferences settings = getPreferences(MODE_PRIVATE);
    // assume we had space before
    long lastMegaAvailable = settings.getLong("cardMBAvaliable", 101L);
    SharedPreferences.Editor editor = settings.edit();
    editor.putLong("cardMBAvaliable", megaAvailable);
    // Commit the edits!
    editor.commit();

    if (megaAvailable <= 0L) {// All out, OR media not mounted
        // Bounce user
        ViewUtil.showConfirmDialog(R.string.nocardspacetitle, R.string.nocardspacedialog, this, false,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (dialog != null) {
                            dialog.dismiss();
                        }
                        finish();
                    }
                });
        return;
    }

    // just issue a warning if we just descended to or past a number on the list
    if (megaAvailable < lastMegaAvailable) {
        for (long l = megaAvailable; l < lastMegaAvailable; l++) {
            if (ConstantUtil.SPACE_WARNING_MB_LEVELS.contains(Long.toString(l))) {
                // display how much space is left
                String s = getResources().getString(R.string.lowcardspacedialog);
                s = s.replace("%%%", Long.toString(megaAvailable));
                ViewUtil.showConfirmDialog(R.string.lowcardspacetitle, s, this, false,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                if (dialog != null) {
                                    dialog.dismiss();
                                }
                            }
                        }, null);
                return; // only one warning per survey, even of we passed >1 limit
            }
        }
    }
}

From source file:com.almalence.util.Util.java

public static long BusyExternalMemory() {
    StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
    long Total = (statFs.getBlockCount() * statFs.getBlockSize()) / 1048576;
    long Free = (statFs.getAvailableBlocks() * statFs.getBlockSize()) / 1048576;
    return (Total - Free);
}

From source file:net.wespot.pim.utils.images.ImageCache.java

/**
 * Check how much usable space is available at a given path.
 *
 * @param path The path to check//from  w  w  w.  j a va2  s  . c o  m
 * @return The space available in bytes
 */
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static long getUsableSpace(File path) {
    if (Utils.hasGingerbread()) {
        return path.getUsableSpace();
    }
    final StatFs stats = new StatFs(path.getPath());
    return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
}

From source file:com.rp.justcast.photos.ImageCache.java

/**
 * Check how much usable space is available at a given path.
 *
 * @param path The path to check/*from  www .  j a  va 2s  .  co  m*/
 * @return The space available in bytes
 */
@TargetApi(VERSION_CODES.GINGERBREAD)
public static long getUsableSpace(File path) {
    if (JustCastUtils.hasGingerbread()) {
        return path.getUsableSpace();
    }
    final StatFs stats = new StatFs(path.getPath());
    return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
}

From source file:prince.app.sphotos.util.ImageCache.java

/**
 * Check how much usable space is available at a given path.
 *
 * @param path The path to check/*from   w w w  .ja v  a2 s  .c  om*/
 * @return The space available in bytes
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static long getUsableSpace(File path) {
    if (Global.hasGingerbread()) {
        return path.getUsableSpace();
    }
    final StatFs stats = new StatFs(path.getPath());
    return (long) stats.getBlockSizeLong() * (long) stats.getAvailableBlocksLong();
}

From source file:wb.android.cache.ImageCache.java

/**
 * Check how much usable space is available at a given path.
 *
 * @param path The path to check//from ww  w . j a  va 2 s . c o m
 * @return The space available in bytes
 */
@TargetApi(VERSION_CODES.GINGERBREAD)
@SuppressWarnings("deprecation")
public static long getUsableSpace(File path) {
    if (Utils.ApiHelper.hasGingerbread()) {
        return path.getUsableSpace();
    }
    final StatFs stats = new StatFs(path.getPath());
    return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
}