First to join the permissions <uses-permission android:name = "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/><uses-permission Android:name= "Android.permission.WRITE_EXTERNAL_STIRAGE"/>
Infer if the SD card exists
/* * Infer if the SD card exists */private Boolean exitsdcard () {if (Environment.getexternalstoragestate (). Equals ( Android.os.Environment.MEDIA_UNMOUNTED) {return true;} else {return false;}}
<span style= "White-space:pre" ></span>/* * View SD card Total capacity */@SuppressWarnings ("deprecation") public long Getsdallsize () {String path = Environment.getexternalstoragedirectory (). GetPath (); StatFs SF = new StatFs (path), int blockSize = Sf.getblocksize (); int allblocks = Sf.getblockcount (); return (Allblocks * bloc ksize)/1024/1024;}
/* * View the remaining space on the SD card */@SuppressWarnings ("deprecation") public long Getsdfreesize () {String path = Environment.getexternalstoragedirectory (). GetPath (); StatFs StatFs = new StatFs (path), int size = Statfs.getblocksize (); int freeblocks = Statfs.getavailableblocks (); Return (FR Eeblocks * size)/1024/1024;}
Android infers if SD card exists and capacity query