How read and display available space in android bo

2019-02-15 13:11发布

how to programmatically read and display the size of sd-card and internal memory.

Internal Memory

  1. total space.
  2. used space.
  3. free space.

External Memory

  1. total space.
  2. used space.
  3. free space.

any related suggestions are apreciatted

3条回答
神经病院院长
2楼-- · 2019-02-15 13:52

Check this Memory Status class it has both methods to get Internal and external available storage

查看更多
虎瘦雄心在
3楼-- · 2019-02-15 13:57
StatFs class 

you can use here, provide the path for your internal and external directory and calculate the total, free and avialable space.

StatFs memStatus = new StatFs(Environment.getExternalStorageDirectory().getPath());

See the documentation for more details.

查看更多
Animai°情兽
4楼-- · 2019-02-15 14:02

Try this code:

public static long remainingLocalStorage()
{
StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
stat.restat(Environment.getDataDirectory().getPath());
long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getAvailableBlocks();
return bytesAvailable;
}
查看更多
登录 后发表回答