Get the phone content space size code
1 Public classMainactivityextendsActivity {2 3 4 PrivateTextView tv_01;5 @Override6 protected voidonCreate (Bundle savedinstancestate) {7 Super. OnCreate (savedinstancestate);8 Setcontentview (r.layout.activity_main);9 Tentv_01 =(TextView) Findviewbyid (r.id.tv_01); One A //get information on SD card - //environment.getexternalstoragedirectory () return path/mnt/sdcard -File Sdcardfiledir =environment.getexternalstoragedirectory (); theString sdmemory =getmemory (sdcardfiledir); - - //get your phone's internal storage space - //environment.getdatadirectory () return path/data +File Datafiledir =environment.getdatadirectory (); -String datamemory =getmemory (datafiledir); + ATv_01.settext ("SD card" +sdmemory+ "\ nthe phone inside" +datamemory); at } - - - PublicString getmemory (File path) { - - //Path.getpath () returns the path to the file in //Get disk status under this path - //StatFs Retrieving the entire information space of the file system toStatFs stat =NewStatFs (Path.getpath ()); + //get the band size for each sector - the //in the newer version of the system, it is suggested that getblocksize is obsolete and needs to use Getblocksizelong () similar to the following method * //However, if you use Getblocksizelong () in a low-version system, a compilation error may occur $ LongBlockSize =stat.getblocksize (); Panax Notoginseng //get the total number of sectors - LongTotalblocks =Stat.getblockcount (); the //Get available Sectors + LongAvaiableblocks =stat.getavailableblocks (); A the //Total Space + -String totalmemory = Formatter.formatfilesize ( This, BlockSize *totalblocks); $ $ //Free Space - -String avaiablememory = Formatter.formatfilesize ( This, totalblocks*avaiableblocks); the - return"Total space:" +totalmemory+ "\ n" + "Free Space:" +avaiablememory;Wuyi } the -}