Reputation: 1593
I am working on a video camera app which will record a video but i want to stop the video recording when the user runs out of memory ,for that I will have to continuously check the size of video and sd card
The scenario is when I am recording the file size will change continuously so how do I stop recording video inside activity and how do i continuously check sdcard size
code to check sd card size is
StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
long blockSize = statFs.getBlockSize();
long totalSize = statFs.getBlockCount()*blockSize;
long availableSize = statFs.getAvailableBlocks()*blockSize;
long freeSize = statFs.getFreeBlocks()*blockSize;
long megAvailablenew = availableSize/ (1024 * 1024);
Log.e("","Available MB : "+megAvailablenew+" avail "+availableSize)
Upvotes: 0
Views: 527
Reputation: 3703
refer this-
public long TotalMemory()//Environment.getExternalStorageDirectory().getAbsolutePath()
{
StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
long Total = ( (long) statFs.getBlockCount() * (long) statFs.getBlockSize()) / 1048576;
return Total;
}
public long FreeMemory()
{
StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
long Free = (statFs.getAvailableBlocks() * (long) statFs.getBlockSize()) / 1048576;
return Free;
}
public long BusyMemory()
{
StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
long Total = ( (long) statFs.getBlockCount() * (long) statFs.getBlockSize()) / 1048576;
long Free = (statFs.getAvailableBlocks() * (long) statFs.getBlockSize()) / 1048576;
long Busy = Total - Free;
return Busy;
}
Upvotes: 3