Android implementation gets the total capacity of SD card, usable size, total memory capacity of fuselage and available size _android

Source: Internet
Author: User

This article describes the Android implementation to obtain the total capacity of SD card, available size, total memory capacity of the fuselage and the available size of the method. Share to everyone for your reference, specific as follows:

Maybe some students do not know that the system has been provided to obtain the total capacity of SD card, available size, total memory capacity of the fuselage and the size of the system, the system source code provided by the method can be very simple, easy to obtain its size. Here I put a method in the system source code to post, for everyone to refer to:

Image:

The code in the red box in the picture is the program method for obtaining the size of the SD card in the source code.
Here I tidy up a bit, and I put in a package that I packed up for you to post:

/** * Obtain SD card Total size * * @return/private String getsdtotalsize () {File path = Environment.getexternalstoragedirecto 
  Ry (); 
  Statfs stat = new Statfs (Path.getpath ()); 
  Long blockSize = Stat.getblocksize (); 
  Long totalblocks = Stat.getblockcount (); 
Return Formatter.formatfilesize (mainactivity.this, blockSize * totalblocks); /** * Obtain SD card remaining capacity, you can use the size * * @return/private String getsdavailablesize () {File path = Environment.getexternals 
  Toragedirectory (); 
  Statfs stat = new Statfs (Path.getpath ()); 
  Long blockSize = Stat.getblocksize (); 
  Long availableblocks = Stat.getavailableblocks (); 
Return Formatter.formatfilesize (mainactivity.this, blockSize * availableblocks); 
  /** * Get the total memory size of the fuselage * * @return/private String getromtotalsize () {File path = Environment.getdatadirectory (); 
  Statfs stat = new Statfs (Path.getpath ()); 
  Long blockSize = Stat.getblocksize (); 
  Long totalblocks = Stat.getblockcount (); Return Formatter.formatfilesize (MainactiviTy.this, BlockSize * totalblocks); /** * Access to the body available memory * * @return/private String getromavailablesize () {File path = Environment.getdatadirectory () 
  ; 
  Statfs stat = new Statfs (Path.getpath ()); 
  Long blockSize = Stat.getblocksize (); 
  Long availableblocks = Stat.getavailableblocks (); 
Return Formatter.formatfilesize (mainactivity.this, blockSize * availableblocks);

 }

I hope this article will help you with your Android programming.

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.