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.frostwire.android.util.SystemUtils.java

public static long getCurrentMountAvailableBytes() {
    StatFs stat = new StatFs(ConfigurationManager.instance().getStoragePath());
    return ((long) stat.getBlockSize() * (long) stat.getAvailableBlocks());
}

From source file:com.just.agentweb.AgentWebUtils.java

public static long getAvailableStorage() {
    try {/*from  w w  w .  ja va  2s.co  m*/
        StatFs stat = new StatFs(Environment.getExternalStorageDirectory().toString());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            return stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
        } else {
            return (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
        }
    } catch (RuntimeException ex) {
        return 0;
    }
}

From source file:ly.count.android.sdk.CrashDetails.java

/**
 * Returns the current device disk space.
 *//*  w  ww . j  a  v  a  2 s.  co m*/
@TargetApi(18)
static String getDiskCurrent() {
    if (android.os.Build.VERSION.SDK_INT < 18) {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = ((long) statFs.getBlockCount() * (long) statFs.getBlockSize());
        long free = ((long) statFs.getAvailableBlocks() * (long) statFs.getBlockSize());
        return Long.toString((total - free) / 1048576L);
    } else {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = (statFs.getBlockCountLong() * statFs.getBlockSizeLong());
        long free = (statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong());
        return Long.toString((total - free) / 1048576L);
    }
}

From source file:count.ly.messaging.CrashDetails.java

/**
 * Returns the current device disk space.
 *//* w w  w  . ja  v  a2 s  .  c o  m*/
static String getDiskTotal() {
    if (android.os.Build.VERSION.SDK_INT < 18) {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = (statFs.getBlockCount() * statFs.getBlockSize());
        return Long.toString(total / 1048576L);
    } else {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = (statFs.getBlockCountLong() * statFs.getBlockSizeLong());
        return Long.toString(total / 1048576L);
    }
}

From source file:com.wso2.mobile.mdm.api.DeviceInfo.java

/**
*Returns the available internal memory size
*//*  ww  w.  java2 s  .  c  o m*/
public double getAvailableInternalMemorySize() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    double blockSize = stat.getBlockSize();
    double availableBlocks = stat.getAvailableBlocks();
    return formatSizeGB(availableBlocks * blockSize);
}

From source file:ly.count.android.sdk.CrashDetails.java

/**
 * Returns the current device disk space.
 *///ww w .  j  a v a 2s. com
@TargetApi(18)
static String getDiskTotal() {
    if (android.os.Build.VERSION.SDK_INT < 18) {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = ((long) statFs.getBlockCount() * (long) statFs.getBlockSize());
        return Long.toString(total / 1048576L);
    } else {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = (statFs.getBlockCountLong() * statFs.getBlockSizeLong());
        return Long.toString(total / 1048576L);
    }
}

From source file:org.kde.necessitas.ministro.MinistroActivity.java

private boolean checkFreeSpace(final long size) throws InterruptedException {
    final StatFs stat = new StatFs(m_qtLibsRootPath);
    if (stat.getBlockSize() * stat.getAvailableBlocks() < size) {
        runOnUiThread(new Runnable() {
            public void run() {

                AlertDialog.Builder builder = new AlertDialog.Builder(MinistroActivity.this);
                builder.setMessage(getResources().getString(R.string.ministro_disk_space_msg,
                        (size - (stat.getBlockSize() * stat.getAvailableBlocks())) / 1024 + "Kb"));
                builder.setCancelable(true);
                builder.setNeutralButton(getResources().getString(R.string.settings_msg),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                try {
                                    startActivityForResult(
                                            new Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS),
                                            freeSpaceCode);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    try {
                                        startActivityForResult(
                                                new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS),
                                                freeSpaceCode);
                                    } catch (Exception e1) {

                                        e1.printStackTrace();
                                    }// w w  w.  j  ava  2 s  .  c o  m
                                }
                            }
                        });
                builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();
                        m_diskSpaceSemaphore.release();
                    }
                });
                builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                    public void onCancel(DialogInterface dialog) {
                        dialog.dismiss();
                        m_diskSpaceSemaphore.release();
                    }
                });
                m_distSpaceDialog = builder.create();
                m_distSpaceDialog.show();
            }
        });
        m_diskSpaceSemaphore.acquire();
    } else
        return true;

    return stat.getBlockSize() * stat.getAvailableBlocks() > size;
}

From source file:com.example.demo_highlights.slidingmenu.fragment.LeftFragment.java

public void getSDSize() {
    textView1.setText("");
    progressBar1.setProgress(0);/*from   w w  w  . j  a  v a2 s  .  c om*/
    //
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File path = Environment.getExternalStorageDirectory();
        //sdcard
        StatFs statfs = new StatFs(path.getPath());
        //blockSIZE
        long blocSize = statfs.getBlockSize();
        //BLOCK
        long totalBlocks = statfs.getBlockCount();
        //Block
        long availaBlock = statfs.getAvailableBlocks();

        String[] total = filesize(totalBlocks * blocSize);
        String[] availale = filesize(availaBlock * blocSize);
        // 
        int maxValue = Integer.parseInt(availale[0].replaceAll(",", "")) * progressBar1.getMax()
                / Integer.parseInt(total[0].replaceAll(",", ""));
        progressBar1.setProgress(100 - maxValue);
        String Text = "SD:"
                + (Integer.parseInt(total[0].replaceAll(",", ""))
                        - Integer.parseInt(availale[0].replaceAll(",", "")))
                + availale[1]/*availale[0].replaceAll(",", "")+availale[1]*/ + " / "
                + total[0].replaceAll(",", "") + total[1];
        textView1.setText(Text);

    } else if (Environment.getExternalStorageState().equals(Environment.MEDIA_REMOVED)) {
        //          Toast.makeText(getActivity(), "sdCard", 1000).show();
        textView1.setText("SD??");
    }
}

From source file:mx.klozz.xperience.tweaker.fragments.DiskInfo.java

public static long Freebytes(File f) {
    StatFs stat = new StatFs(f.getPath());
    //return (long) stat.getBlockSizeLong() * (long) stat.getAvailableBlocksLong(); <-- deprecated :) now can unse LONG in name
    return stat.getBlockSizeLong() * stat.getAvailableBlocksLong();
}

From source file:com.wso2.mobile.mdm.api.DeviceInfo.java

/**
*Returns the total internal memory size/*from w  w w.j av  a2s .co  m*/
*/
public double getTotalInternalMemorySize() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    double blockSize = stat.getBlockSize();
    double totalBlocks = stat.getBlockCount();
    return formatSizeGB(totalBlocks * blockSize);
}