Internal phone storage in Android

前端 未结 2 1404
既然无缘
既然无缘 2020-12-13 16:23

How can you retrieve your phone internal storage from an app? I found MemoryInfo, but it seems that returns information on how much memory use your currently running tasks.

2条回答
  •  时光说笑
    2020-12-13 17:21

    Use android.os.Environment to find the internal directory, then use android.os.StatFs to call the Unix statfs system call on it. Shamelessly stolen from the Android settings app:

    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return Formatter.formatFileSize(this, availableBlocks * blockSize);
    

提交回复
热议问题