I'm new to Android. I need the simple code of getting the Internal storage and external storage and System storage and how to get the Details of available memory(internal and external) space, total memory space. My code is below but its getting error in "StatFs" method. Thanks in advance.
long total, aval,total1, aval1,total2, aval2;
int kb = 1024;
StatFs fs = new StatFs(Environment.
getExternalStorageDirectory().getPath());
total = fs.getBlockCount() * (fs.getBlockSize() / kb);
aval = fs.getAvailableBlocks() * (fs.getBlockSize() / kb);
//Here Iam Getting error StatFs method not loading
StatFs fs1 = new StatFs(Environment.
getRootDirectory()+"/storage/extSdCard/");
total1 = fs1.getBlockCount() * (fs1.getBlockSize() / kb);
aval1 = fs1.getAvailableBlocks() * (fs1.getBlockSize() / kb);
pb1.setMax((int)total);
pb1.setProgress((int)aval);
pb2.setMax((int)total1);
pb2.setProgress((int)aval1);
}
When accessing the SDCARD services Always start by checking whether or not the SDCARD is currently mounted. You cannot assume that it is:
Now, to get available internal storage:
Note: the above will return available storage for all, not only for your app!
Get memory usage:
All values are in bytes.
And finally - interrogating the external memory (not the SDCARD):
You code assumes that the path to the above is "/mnt/extSdCard/". This is not guaranteed. In some devices it is "/mnt/external_sd/". And there can be other names..
What you need to do is to start by listing all mounted storage devices and somehow (programmatically, user intervention...) pick your one. The way to do it is as follows: