Search in sources :

Example 16 with StatFs

use of android.os.StatFs in project superCleanMaster by joyoyao.

the class StorageUtil method getSDCardInfo.

public static SDCardInfo getSDCardInfo() {
    if (Environment.isExternalStorageRemovable()) {
        String sDcString = Environment.getExternalStorageState();
        if (sDcString.equals(Environment.MEDIA_MOUNTED)) {
            File pathFile = Environment.getExternalStorageDirectory();
            try {
                StatFs statfs = new StatFs(pathFile.getPath());
                // 获取SDCard上BLOCK总数
                long nTotalBlocks = statfs.getBlockCount();
                // 获取SDCard上每个block的SIZE
                long nBlocSize = statfs.getBlockSize();
                // 获取可供程序使用的Block的数量
                long nAvailaBlock = statfs.getAvailableBlocks();
                // 获取剩下的所有Block的数量(包括预留的一般程序无法使用的块)
                long nFreeBlock = statfs.getFreeBlocks();
                SDCardInfo info = new SDCardInfo();
                // 计算SDCard 总容量大小MB
                info.total = nTotalBlocks * nBlocSize;
                // 计算 SDCard 剩余大小MB
                info.free = nAvailaBlock * nBlocSize;
                return info;
            } catch (IllegalArgumentException e) {
            }
        }
    }
    return null;
}
Also used : StatFs(android.os.StatFs) SDCardInfo(com.yzy.supercleanmaster.model.SDCardInfo) File(java.io.File)

Example 17 with StatFs

use of android.os.StatFs in project superCleanMaster by joyoyao.

the class StorageUtil method getSystemSpaceInfo.

public static SDCardInfo getSystemSpaceInfo(Context context) {
    File path = Environment.getDataDirectory();
    // File path = context.getCacheDir().getAbsoluteFile();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long totalBlocks = stat.getBlockCount();
    long availableBlocks = stat.getAvailableBlocks();
    long totalSize = blockSize * totalBlocks;
    long availSize = availableBlocks * blockSize;
    SDCardInfo info = new SDCardInfo();
    info.total = totalSize;
    info.free = availSize;
    return info;
}
Also used : StatFs(android.os.StatFs) SDCardInfo(com.yzy.supercleanmaster.model.SDCardInfo) File(java.io.File)

Example 18 with StatFs

use of android.os.StatFs in project nmid-headline by miao1007.

the class FileUtil method getFreeDiskSpace.

/**
   * 计算SD卡的剩余空间
   *
   * @return 返回-1,说明没有安装sd卡
   */
public static long getFreeDiskSpace() {
    String status = Environment.getExternalStorageState();
    long freeSpace = 0;
    if (status.equals(Environment.MEDIA_MOUNTED)) {
        try {
            File path = Environment.getExternalStorageDirectory();
            StatFs stat = new StatFs(path.getPath());
            long blockSize = stat.getBlockSize();
            long availableBlocks = stat.getAvailableBlocks();
            freeSpace = availableBlocks * blockSize / 1024;
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        return -1;
    }
    return (freeSpace);
}
Also used : StatFs(android.os.StatFs) File(java.io.File) IOException(java.io.IOException)

Example 19 with StatFs

use of android.os.StatFs in project android-app-common-tasks by multidots.

the class CropImage method calculatePicturesRemaining.

private static int calculatePicturesRemaining(Activity activity) {
    try {
        /*if (!ImageManager.hasStorage()) {
                return NO_STORAGE_ERROR;
            } else {*/
        String storageDirectory;
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            storageDirectory = Environment.getExternalStorageDirectory().toString();
        } else {
            storageDirectory = activity.getFilesDir().toString();
        }
        StatFs stat = new StatFs(storageDirectory);
        float remaining = ((float) stat.getAvailableBlocks() * (float) stat.getBlockSize()) / 400000F;
        return (int) remaining;
    //}
    } catch (Exception ex) {
        // blank since we really don't know.
        return CANNOT_STAT_ERROR;
    }
}
Also used : StatFs(android.os.StatFs) IOException(java.io.IOException)

Example 20 with StatFs

use of android.os.StatFs in project android-app-common-tasks by multidots.

the class CropImage method calculatePicturesRemaining.

private static int calculatePicturesRemaining(Activity activity) {
    try {
        /*if (!ImageManager.hasStorage()) {
                return NO_STORAGE_ERROR;
            } else {*/
        String storageDirectory;
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            storageDirectory = Environment.getExternalStorageDirectory().toString();
        } else {
            storageDirectory = activity.getFilesDir().toString();
        }
        StatFs stat = new StatFs(storageDirectory);
        float remaining = ((float) stat.getAvailableBlocks() * (float) stat.getBlockSize()) / 400000F;
        return (int) remaining;
    //}
    } catch (Exception ex) {
        // blank since we really don't know.
        return CANNOT_STAT_ERROR;
    }
}
Also used : StatFs(android.os.StatFs) IOException(java.io.IOException)

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