Fixed bug in calculation of free space
This commit is contained in:
parent
d30bcfff79
commit
625a043644
@ -57,9 +57,10 @@ public class HttpDownloader extends Downloader {
|
|||||||
status.setSize(connection.getContentLength());
|
status.setSize(connection.getContentLength());
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Size is " + status.getSize());
|
Log.d(TAG, "Size is " + status.getSize());
|
||||||
if (status.getSize() == -1
|
long freeSpace = StorageUtils.getFreeSpaceAvailable();
|
||||||
|| status.getSize() <= StorageUtils
|
if (AppConfig.DEBUG)
|
||||||
.getFreeSpaceAvailable()) {
|
Log.d(TAG, "Free space is " + freeSpace);
|
||||||
|
if (status.getSize() == -1 || status.getSize() <= freeSpace) {
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Size is " + status.getSize());
|
Log.d(TAG, "Size is " + status.getSize());
|
||||||
publishProgress();
|
publishProgress();
|
||||||
|
@ -28,9 +28,11 @@ public class StorageUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get the number of free bytes that are available on the external storage. */
|
/** Get the number of free bytes that are available on the external storage. */
|
||||||
public static int getFreeSpaceAvailable() {
|
public static long getFreeSpaceAvailable() {
|
||||||
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
|
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
|
||||||
return stat.getAvailableBlocks() * stat.getBlockSize();
|
long availableBlocks = stat.getAvailableBlocks();
|
||||||
|
long blockSize = stat.getBlockSize();
|
||||||
|
return availableBlocks * blockSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean externalStorageMounted() {
|
public static boolean externalStorageMounted() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user