Get total space and free space for your phone and SD card under Android

Source: Internet
Author: User

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);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.