01.
/**
02.
* 判斷是否有足夠的空間供下載
03.
*
04.
* @param downloadSize
05.
* @return
06.
*/
07.
public boolean isEnoughForDownload(long downloadSize)
08.
{
09.
StatFs statFs = new StatFs(Environment.getExternalStorageDirectory()
10.
.getAbsolutePath());
11.

 

12.
//sd卡分區數
13.
int blockCounts = statFs.getBlockCount();
14.

 

15.
Log.e("ray", "blockCounts" + blockCounts);
16.

 

17.
//sd卡可用分區數
18.
int avCounts = statFs.getAvailableBlocks();
19.

 

20.
Log.e("ray", "avCounts" + avCounts);
21.

 

22.
//一個分區數的大小
23.
long blockSize = statFs.getBlockSize();
24.

 

25.
Log.e("ray", "blockSize" + blockSize);
26.

 

27.
//sd卡可用空間
28.
long spaceLeft = avCounts * blockSize;
29.

 

30.
Log.e("ray", "spaceLeft" + spaceLeft);
31.

 

32.
Log.e("ray", "downloadSize" + downloadSize);
33.

 

34.
if (spaceLeft < downloadSize)
35.
{
36.
return false;
37.
}
38.

 

39.
return true;
40.
}
創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()