Search in sources :

Example 46 with StatFs

use of android.os.StatFs in project bilibili-android-client by HotBitmapGG.

the class CommonUtil method getSDcardTotalSize.

/**
   * 获取手机SD卡总空间
   */
private static long getSDcardTotalSize() {
    if (checkSdCard()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs mStatFs = new StatFs(path.getPath());
        long blockSizeLong = mStatFs.getBlockSizeLong();
        long blockCountLong = mStatFs.getBlockCountLong();
        return blockSizeLong * blockCountLong;
    } else {
        return 0;
    }
}
Also used : StatFs(android.os.StatFs) File(java.io.File)

Example 47 with StatFs

use of android.os.StatFs in project bilibili-android-client by HotBitmapGG.

the class CommonUtil method getSDcardAvailableSize.

/**
   * 获取SDka可用空间
   */
private static long getSDcardAvailableSize() {
    if (checkSdCard()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs mStatFs = new StatFs(path.getPath());
        long blockSizeLong = mStatFs.getBlockSizeLong();
        long availableBlocksLong = mStatFs.getAvailableBlocksLong();
        return blockSizeLong * availableBlocksLong;
    } else {
        return 0;
    }
}
Also used : StatFs(android.os.StatFs) File(java.io.File)

Example 48 with StatFs

use of android.os.StatFs in project bilibili-android-client by HotBitmapGG.

the class CommonUtil method getPhoneTotalSize.

/**
   * 获取手机内部存储总空间
   */
public static long getPhoneTotalSize() {
    if (!checkSdCard()) {
        File path = Environment.getDataDirectory();
        StatFs mStatFs = new StatFs(path.getPath());
        long blockSizeLong = mStatFs.getBlockSizeLong();
        long blockCountLong = mStatFs.getBlockCountLong();
        return blockSizeLong * blockCountLong;
    } else {
        return getSDcardTotalSize();
    }
}
Also used : StatFs(android.os.StatFs) File(java.io.File)

Example 49 with StatFs

use of android.os.StatFs in project AndroidChromium by JackyAndroid.

the class SpaceDisplay method createStorageSizeTask.

private AsyncTask<Void, Void, Long> createStorageSizeTask() {
    return new AsyncTask<Void, Void, Long>() {

        @Override
        protected Long doInBackground(Void... params) {
            File downloadDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
            // Create the downloads directory, if necessary.
            if (!downloadDirectory.exists()) {
                try {
                    // mkdirs() can fail, so we still need to check if the directory exists
                    // later.
                    downloadDirectory.mkdirs();
                } catch (SecurityException e) {
                    Log.e(TAG, "SecurityException when creating download directory.", e);
                }
            }
            // Determine how much space is available on the storage device where downloads
            // reside.  If the downloads directory doesn't exist, it is likely that the user
            // doesn't have an SD card installed.
            long fileSystemBytes = 0;
            if (downloadDirectory.exists()) {
                StatFs statFs = new StatFs(downloadDirectory.getPath());
                long totalBlocks = ApiCompatibilityUtils.getBlockCount(statFs);
                long blockSize = ApiCompatibilityUtils.getBlockSize(statFs);
                fileSystemBytes = totalBlocks * blockSize;
            } else {
                Log.e(TAG, "Download directory doesn't exist.");
            }
            return fileSystemBytes;
        }
    };
}
Also used : StatFs(android.os.StatFs) AsyncTask(android.os.AsyncTask) File(java.io.File)

Example 50 with StatFs

use of android.os.StatFs in project QuickAndroid by ImKarl.

the class QAFileManager method getDataAvailableSize.

/**
     * 获取手机内部可用大小
     * @return 
     */
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static long getDataAvailableSize() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    if (QASdkVersion.isSupport(QASdkVersion.JELLY_BEAN_MR2)) {
        return stat.getAvailableBytes();
    } else {
        long availableBlocks = stat.getAvailableBlocks();
        long blockSize = stat.getBlockSize();
        return availableBlocks * blockSize;
    }
}
Also used : StatFs(android.os.StatFs) File(java.io.File) TargetApi(android.annotation.TargetApi)

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