- Download Android source code, find the app under the Settings application source code, import settings project (Android project source code)
find "free space" to get
<string name= "memory_available" msgid= "418542433817289474" > "Free Space" </STRING>
Find "memory_available" and get
<Preference android:key="memory_sd_avail" style="?android:attr/preferenceInformationStyle" android:title="@string/memory_available" android:summary="00"/>
Find "MemorySDavail" to get
//这个字符串就是sd卡剩余容量formatSize(availableBlocks * blockSize) + readOnly//这两个参数相乘,得到sd卡以字节为单位的剩余容量availableBlocks * blockSize
The storage device is divided into chunks, each with a fixed size
- Chunk Size * Number of chunks equals the total size of the storage device
Sample code
File Path =environment.getexternalstoragedirectory (); StatFs Stat=NewStatFs (Path.getpath ()); LongblockSize; Longtotalblocks; Longavailableblocks; //gets the level of the current system version if(Build.VERSION.SDK_INT >=Build.version_codes. JELLY_BEAN_MR2) {blockSize=Stat.getblocksizelong (); Totalblocks=Stat.getblockcountlong (); Availableblocks=Stat.getavailableblockslong (); } Else{blockSize=stat.getblocksize (); Totalblocks=Stat.getblockcount (); Availableblocks=stat.getavailableblocks (); } TextView TV=(TextView) Findviewbyid (r.id.tv); Tv.settext (Formatsize (availableblocks*blockSize));}PrivateString Formatsize (Longsize) { returnFormatter.formatfilesize ( This, size);}
View source code find code to get the remaining capacity of SD card