Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - how to handle saving file on low device memory(Internal/External memory)

Tags:

android

memory

How we can handle the file saving on low device memory(internal/Excternal memrory). I know if sufficient space is not available the OS will throw IOException but is there any way to handle this gracefully.

like image 763
Sumit Gulati Avatar asked Oct 22 '22 12:10

Sumit Gulati


1 Answers

File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return Formatter.formatFileSize(this, availableBlocks * blockSize);
like image 127
Arun C Avatar answered Oct 29 '22 18:10

Arun C