I am downloading data into my app from the internet. If I specify internal memory (=Environment.getExternalStorageDirectory()), I may have face problem of "not enough space". Sdcard mount address always differs phone to phone, so I would like to allow user to select his preferable location, where to store downloaded data. Is there any method, how to get all available storage options, whhich can be used? (generally, I would like to choose between internal memory or inserted sdcard).
Thanks
Please check the below code.
Calculate Available Internal Storage memory
StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
long bytesAvailable = (long)stat.getFreeBlocks() * (long)stat.getBlockSize();
long megAvailable = bytesAvailable / 1048576;
Calculate Total Internal Storage memory
StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getBlockCount();
long megAvailable = bytesAvailable / 1048576;
Calculate Available External Storage memory
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long bytesAvailable = (long)stat.getFreeBlocks() * (long)stat.getBlockSize();
long megAvailable = bytesAvailable / 1048576;
Calculate Total External Storage memory
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getBlockCount();
long megAvailable = bytesAvailable / 1048576;
Note : First of all you need to calculate avilable internal memory and show to user where he/she wants to download file.
来源:https://stackoverflow.com/questions/14645189/android-get-list-of-all-available-storage