Get the phone's remaining space tool class

Source: Internet
Author: User

1 ImportJava.io.File;2 3 ImportCom.iss.utils.LogUtil;4 5 Importandroid.os.Environment;6 ImportAndroid.os.StatFs;7 8 /**9 * Class nameTen *  @authorWang Hong He <br/> One * Get the remaining storage space tool class for your phone A * Date Created August 1, 2014 - */ -  the  Public classStorageutil { -  -     /** - * Get SD card remaining storage space +     *  @returnreturns a long integer value in KB bytes -     */ +      Public Static LongReadsdcard () { AString State =environment.getexternalstoragestate (); at         if(Environment.MEDIA_MOUNTED.equals (state)) { -File Sdcarddir =environment.getexternalstoragedirectory (); -StatFs SF =NewStatFs (Sdcarddir.getpath ()); -             LongBlockSize =sf.getblocksize (); -             LongBlockcount =Sf.getblockcount (); -             LongAvailcount =sf.getavailableblocks (); in            /*LOGUTIL.D ("", "Block Size:" + BlockSize + ", block number:" + Blockcount + ", Total size:" + blockSize - * blockcount/1024 + "KB"); to LOGUTIL.D ("", "number of available blocks::" + Availcount + ", Remaining space:" + availcount * blocksize/1024 + + "KB");*/ -             returnAvailcount * blocksize/1024; the}Else { *             return0; $         }Panax Notoginseng     } -  the     /** + * Get SD card remaining storage space A      *  @returnreturns a long integer value in M-byte units the      */ +      Public Static LongREADSDCARDM () { -         returnReadsdcard ()/1024; $     } $  -     /** - * Get the remaining storage space of the system the      *  @returnreturns a long integer value in kilobytes -      */Wuyi      Public Static LongReadsystem () { theFile root =environment.getrootdirectory (); -StatFs SF =NewStatFs (Root.getpath ()); Wu         LongBlockSize =sf.getblocksize (); -         LongBlockcount =Sf.getblockcount (); About         LongAvailcount =sf.getavailableblocks (); $         /*LOGUTIL.D ("", "Block Size:" + BlockSize + ", block number:" + Blockcount + ", Total size:" + blockSize - * blockcount/1024 + "KB"); - LOGUTIL.D ("", "number of available blocks::" + Availcount + ", available size:" + availcount * blocksize/1024 + "KB");*/ -         returnAvailcount * blocksize/1024; A     } +  the     /** - * Get the remaining storage space of the system $      *  @returnreturns a long integer value in M the      */ the      Public Static LongReadsystemm () { the         returnReadsystem ()/1024; the     } -  in     /** the * Determine if the remaining space is greater than the specified space the      *  @paramSIZEMB The specified size in megabytes About      *  @returnreturn value true to have corresponding space, false to be less than the corresponding space the      */ the      Public Static BooleanIsavailablespace (intsizemb) { the         BooleanHasspace =false; +         LongAvailablespare =READSDCARDM (); -         if(Availablespare >sizemb) { theHasspace =true;Bayi         } the         returnHasspace; the     } -  -     /** the * Determine if the remaining space is greater than the specified space the      *  @returnreturn value True to have 100m,false of less than 100M the      */ the      Public Static BooleanIsavailablespace () { -         returnIsavailablespace (100); the     } 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.