When you are working on a project, you need to know the storage card capacity information. Let's record it.
Android memory card capacity information is obtained using two classes: Android. OS. Environment and Android. OS. stafs. The specific method is as follows:
1. Environment
File data = environment. getdatadirectory (); // obtain the object file data = environment of the mobile phone storage file. getexternalstoragedirectory (); // get the sdcard file object file data = environment. getexternalstoragedirectory (); // get the system root file object
2. statfs:
Statfs sdstatfs = new statfs (data. getpath (); int availableblocks = statfs. getavailableblocks (); // number of available storage blocks int blockcount = statfs. getblockcount (); // The total number of storage blocks int size = statfs. getblocksize (); // the size of each block int totalsize = blockcount * size; // total storage int availablesize = availableblocks * size; // available capacity