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.