How to know internal memory size in android?
This is my code,
private String memSize(String path){
StatFs stat = new StatFs(path);
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
long freeBlocks = stat.getFreeBlocks();
long countBlocks = stat.getBlockCount();
String fileSize = Formatter.formatFileSize(this, availableBlocks * blockSize);
String maxSize = Formatter.formatFileSize(this, countBlocks * blockSize);
String info = path.toString()
+ "\nblockSize : " + Long.toString(blockSize)
+ "\navailableBlocks : " + Long.toString(availableBlocks)
+ "\nfreeBlocks : " + Long.toString(freeBlocks)
+ "\nreservedBlocks : " + Long.toString(freeBlocks - availableBlocks)
+ "\ncountBlocks : " + Long.toString(countBlocks)
+ "\nspace : " + fileSize + " / " + maxSize
+ "\n\n";
return info;
}
I test my function with path /data
and /sdcard
and it works
/
(I understand it is root path), this is开发者_如何学运维 result.
- blockSize: 4096
- availableBlocks: 0
- freeBlocks: 0
- reservedBlocks: 0
- countBlocks: 0
- space: 0.00B / 0.00B
I think root path is SuperUser area. May need some permission to access.
My phone is already rooted. Could you show me what I should do next step ?Thank you.
References
- http://developer.android.com/reference/android/os/StatFs.html
- android internal phone storage
Your internal storage is not mounted in / it's in /data dir. android internal phone storage
精彩评论