Get the size of your phone's content space

Source: Internet
Author: User

 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 -}

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.