1. Determine if the SD card exists returns TRUE indicates that there is
1 /*determine if the SD card exists returns TRUE indicates that there is*/2 Public BooleanAvaiablemedia () {3String status =environment.getexternalstoragestate ();4 5 if(Status.equals (environment.media_mounted)) {6 return true;7}Else {8 return false;9 }Ten}
2. Get the SD card free space
1 /*get SD card free space*/2 Public Longgetsdfreesize () {3 //get SD card file path4File Path =environment.getexternalstoragedirectory ();5StatFs SF =NewStatFs (Path.getpath ());6 //gets the size of a single data block (Byte)7 LongBlockSize =Sf.getblocksizelong ();8 //the number of free data blocks9 LongFreeblocks =Sf.getavailableblockslong ();Ten //return SD card idle size One //return freeblocks * blockSize;//Unit byte A //return (freeblocks * blockSize)/1024;//Unit KB - return(Freeblocks * blockSize)/1024/1024;//units MB -}
3. Get all the space on the SD card
1 /*get all the space on your SD card*/2 Public Longgetsdallsize () {3 //get SD card file path4File Path =environment.getexternalstoragedirectory ();5StatFs SF =NewStatFs (Path.getpath ());6 //gets the size of a single data block (Byte)7 LongBlockSize =Sf.getblocksizelong ();8 //get the number of all data blocks9 LongAllblocks =Sf.getblockcountlong ();Ten //return SD card size One //return allblocks * blockSize;//Unit byte A //return (allblocks * blockSize)/1024;//Unit KB - return(Allblocks * blockSize)/1024/1024;//units MB -}
Android to determine if SD card exists and use capacity query