How to know internal memory size in android?

2019-03-20 02:07发布

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

1条回答
ゆ 、 Hurt°
2楼-- · 2019-03-20 02:46

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

查看更多
登录 后发表回答