开发者

How to calculate remaining space in local storage?

开发者 https://www.devze.com 2023-03-14 03:50 出处:网络
How do I find remaining/total space on the local storage? Can I use StatFs for this (as in - How to Check available space 开发者_如何转开发on android device ? on SD card?)Turns out you can. Ran this

How do I find remaining/total space on the local storage?

Can I use StatFs for this (as in - How to Check available space 开发者_如何转开发on android device ? on SD card?)


Turns out you can. Ran this code which seems to return the appropriate number of bytes remaining in my internal storage. Unsure about the reliability of Environment.getDataDirectory()

public static long remainingLocalStorage()
{
    StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
    stat.restat(Environment.getDataDirectory().getPath());
    long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getAvailableBlocks();
    return bytesAvailable;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消