This paper illustrates the existence of the SD card and the implementation of capacity query using the Android programming method. Share to everyone for your reference, specific as follows:
1. To determine whether the existence of SD card returns TRUE indicates existence
/* To determine if SD card exists returns true to exist
/public boolean Avaiablemedia () {
String status = Environment.getexternalstoragestate ();
if (Status.equals (environment.media_mounted)) {return
true;
} else {return
false;
}}
2. Get SD card free space
/* Get SD card free space *
/public long getsdfreesize () {
//Get SD card file path filename
Environment.getexternalstoragedirectory ();
Statfs SF = new Statfs (Path.getpath ());
Gets the size of a single block of data (Byte)
Long blockSize = Sf.getblocksizelong ();
The number of free blocks of data
long freeblocks = Sf.getavailableblockslong ();
Back to SD card idle size
//return freeblocks * blockSize;//unit byte
//Return (Freeblocks * blockSize)/1024;//unit KB
RE Turn (Freeblocks * blockSize)/1024/1024; per MB
}
3. Get SD card all the space
/* Get SD Card all space/public
long Getsdallsize () {
//Get SD card file path filename
Environment.getexternalstoragedirectory ();
Statfs SF = new Statfs (Path.getpath ());
Gets the size of a single block of data (Byte)
Long blockSize = Sf.getblocksizelong ();
Gets all data blocks number
long allblocks = Sf.getblockcountlong ();
Back to SD card size
//return allblocks * blockSize;//unit byte
//Return (Allblocks * blockSize)/1024;//unit KB
return (Allblocks * blockSize)/1024/1024; per MB
}
I hope this article will help you with the Android program.