Search in sources :

Example 86 with StatFs

use of android.os.StatFs in project JustAndroid by chinaltz.

the class AbFileUtil method freeSpaceOnSD.

/**
     * 计算sdcard上的剩余空间.
     *
     * @return the int
     */
public static int freeSpaceOnSD() {
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    double sdFreeMB = ((double) stat.getAvailableBlocks() * (double) stat.getBlockSize()) / 1024 * 1024;
    return (int) sdFreeMB;
}
Also used : StatFs(android.os.StatFs)

Example 87 with StatFs

use of android.os.StatFs in project smartmodule by carozhu.

the class DeviceInfoUtil method getSDAvailableSize.

/**
     * 获得sd卡剩余容量,即可用大小
     *
     * @return
     */
public String getSDAvailableSize(Context context) {
    File path = Environment.getExternalStorageDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return Formatter.formatFileSize(context, blockSize * availableBlocks);
}
Also used : StatFs(android.os.StatFs) File(java.io.File)

Example 88 with StatFs

use of android.os.StatFs in project StudyNotes by InnoFang.

the class SDCardUtil method getSDCardAllSize.

/**
     * 获取SD卡的剩余容量 单位byte
     *
     * @return
     */
@SuppressWarnings("deprecation")
public static long getSDCardAllSize() {
    if (isSDCardEnable()) {
        StatFs stat = new StatFs(getSDCardPath());
        //获取空闲的数据块的数量
        long availableBlocks = (long) stat.getAvailableBlocks() - 4;
        //获取单个数据块的大小(byte)
        long freeBlocks = stat.getAvailableBlocks();
        return freeBlocks * availableBlocks;
    }
    return 0;
}
Also used : StatFs(android.os.StatFs)

Example 89 with StatFs

use of android.os.StatFs in project android_packages_apps_Camera by CyanogenMod.

the class Storage method getAvailableSpace.

public long getAvailableSpace() {
    String state = Environment.getExternalStorageState();
    Log.d(TAG, "External storage state=" + state);
    if (Environment.MEDIA_CHECKING.equals(state)) {
        return PREPARING;
    }
    if (!Environment.MEDIA_MOUNTED.equals(state)) {
        return UNAVAILABLE;
    }
    File dir = new File(generateDirectory());
    dir.mkdirs();
    if (!dir.isDirectory() || !dir.canWrite()) {
        return UNAVAILABLE;
    }
    try {
        StatFs stat = new StatFs(generateDirectory());
        return stat.getAvailableBlocks() * (long) stat.getBlockSize();
    } catch (Exception e) {
        Log.i(TAG, "Fail to access external storage", e);
    }
    return UNKNOWN_SIZE;
}
Also used : StatFs(android.os.StatFs) File(java.io.File)

Example 90 with StatFs

use of android.os.StatFs in project android_frameworks_base by crdroidandroid.

the class LowStorageTest method onCreate.

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    // Update the current data info
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    int totalBlocks = stat.getBlockCount();
    mBlockSize = (int) (stat.getBlockSize());
    TextView startSizeTextView = (TextView) findViewById(R.id.totalsize);
    startSizeTextView.setText(Long.toString((totalBlocks * mBlockSize) / BYTE_SIZE));
    Button button = (Button) findViewById(R.id.button_run);
    button.setOnClickListener(mStartListener);
}
Also used : StatFs(android.os.StatFs) Button(android.widget.Button) TextView(android.widget.TextView) File(java.io.File)

Aggregations

StatFs (android.os.StatFs)196 File (java.io.File)120 IOException (java.io.IOException)30 FileOutputStream (java.io.FileOutputStream)17 TargetApi (android.annotation.TargetApi)15 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 FileNotFoundException (java.io.FileNotFoundException)11 ContentResolver (android.content.ContentResolver)10 DropBoxManager (android.os.DropBoxManager)10 TextView (android.widget.TextView)10 DropBoxManagerService (com.android.server.DropBoxManagerService)10 Test (org.junit.Test)7 PendingIntent (android.app.PendingIntent)6 Intent (android.content.Intent)6 IntentFilter (android.content.IntentFilter)6 Context (android.content.Context)5 Suppress (android.test.suitebuilder.annotation.Suppress)5 Button (android.widget.Button)5 SuppressLint (android.annotation.SuppressLint)3 SDCardInfo (com.yzy.supercleanmaster.model.SDCardInfo)3