First, add the SD card access to the Androidmanifest.xml
<!--- <android:name = " Android.permission.MOUNT_UNMOUNT_FILESYSTEMS "/> <!---- <android:name= "Android.permission.WRITE_EXTERNAL_STORAGE" />
//whether the SD exists Private BooleanExistsdcard () {if(Environment.getexternalstoragestate (). Equals (environment.media_mounted)) {return true; } Else return false; } //SD remaining space Public Longgetsdfreesize () {//get SD card file pathFile Path =environment.getexternalstoragedirectory (); StatFs SF=NewStatFs (Path.getpath ()); //gets the size of a single data block (Byte) LongBlockSize =sf.getblocksize (); //the number of free data blocks LongFreeblocks =sf.getavailableblocks (); //return SD card idle size//return freeblocks * blockSize; //Unit byte//return (Freeblocks * blockSize)/1024; //Unit KB return(Freeblocks * blockSize)/1024/1024;//units MB } //SD Total Capacity Public Longgetsdallsize () {//get SD card file pathFile Path =environment.getexternalstoragedirectory (); StatFs SF=NewStatFs (Path.getpath ()); //gets the size of a single data block (Byte) LongBlockSize =sf.getblocksize (); //get the number of all data blocks LongAllblocks =Sf.getblockcount (); //return SD card size//return allblocks * blockSize;//Unit byte//return (allblocks * blockSize)/1024;//Unit KB return(Allblocks * blockSize)/1024/1024;//units MB}
Android to determine if SD card exists and capacity