How read and display available space in android both sd card and internal memory?

馋奶兔 提交于 2019-12-03 22:18:12

问题


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


回答1:


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;
}



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/15521050/how-read-and-display-available-space-in-android-both-sd-card-and-internal-memory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!