The example in this article describes how Android programming obtains SDcard card information. Share to everyone for your reference, specific as follows:
public static Sdcardinfo Getsdcardinfo () {String sdcstring = Android.os.Environment.getExternalStorageState (); if (Sdcstring.equals (Android.os.Environment.MEDIA_MOUNTED)) {File Pathfile =
Android.os.Environment.getExternalStorageDirectory ();
try {android.os.StatFs statfs = new Android.os.StatFs (Pathfile.getpath ());
Gets the total number of blocks on the sdcard long ntotalblocks = Statfs.getblockcount ();
Gets the size long nblocsize = Statfs.getblocksize () of each block on the sdcard;
Gets the number of blocks that can be used by the program long Navailablock = Statfs.getavailableblocks ();
Gets the number of all remaining blocks (including chunks that are not used by the reserved general program) long Nfreeblock = Statfs.getfreeblocks ();
Sdcardinfo info = new Sdcardinfo ();
Calculates sdcard Total capacity MB Info.total = Ntotalblocks * nblocsize;
Calculates sdcard remaining size MB Info.free = Navailablock * nblocsize;
return info;
catch (IllegalArgumentException e) {log.e (Log_tag, e.tostring ());
} return null;
} sdcardinfo Sdcardinfo = Util.getsdcardinfo (); SD Card Total Capacity SdcardinFo.total//SD card remaining capacity Sdcardinfo.free
I hope this article will help you with your Android programming.