Get the total space and free space of the SD card
File path = Environment.getexternalstoragedirectory (); StatFs stat = new StatFs (Path.getpath ()); Long blockSize = Stat.getblocksize (); Long totalblocks = Stat.getblockcount (); Long availableblocks = Stat.getavailableblocks (); Long totalsize = Totalblocks * Blocksize;long availsize = AvailableBlock S * blockSize; String totalstr = Formatter.formatfilesize (this, totalsize); String availstr = Formatter.formatfilesize (this, availsize);
Get your phone's total space and free space
File path2 = Environment.getdatadirectory (); StatFs stat2 = new StatFs (Path2.getpath ()); Long blockSize2 = Stat2.getblocksize (); Long totalBlocks2 = Stat2.getblockcount (); Long availableBlocks2 = Stat2.getavailableblocks (); Long totalSize2 = TotalBlocks2 * BLOCKSIZE2; Long availSize2 = AvailableBlocks2 * BLOCKSIZE2; String TOTALSTR2 = Formatter.formatfilesize (this, totalSize2); String AVAILSTR2 = Formatter.formatfilesize (this, availSize2);