How to get size of the app data in Android
Here is few lines how to get size of directory in Android.
To get size of directory you need sum sizes of all files in this directory and subdirectories.
So, we need recursion.
long sizeOfCacheDir = getCacheDirSize(getCacheDir()); textViewSize.setText("Cache dir size = " + sizeOfCacheDir + " bytes");
Where :
private long getCacheDirSize(File file) { long size = 0; for (File f : file.listFiles()) { if (f.listFiles() == null) { size = size + f.length(); } else { size = size + getCacheDirSize(f); } } return size; }
Short sample project here on my github:
0 Comments