Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
But when path is / (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
like image 364
diewland Avatar asked Feb 22 '11 03:02

diewland


1 Answers

Your internal storage is not mounted in / it's in /data dir. android internal phone storage

like image 107
Mojo Risin Avatar answered Sep 28 '22 07:09

Mojo Risin