Android: Internal storage available


In order to execute a process that generates many files, I must ensure that I have the storage space available, based on estimates and calculations that give me an approximate figure of the space I must have to execute the process.

Eventually I should also be able to know the internal storage space, for example the one used by applications when they insert records into their database or anything that is saved in getApplicationInfo().dataDir .

With external storage I have no problem, I have done tests duplicating and tripling photographs, videos and audios and the figure is calculated correctly. But the internal space (or the one that is supposed to be) does not change if, for example; I access the folder /data/data/app.package/ and double and triple the contents of some large file that is there.

For example, I have the following output:

04-22 16:06:10.662: I/System.out(7411): External 2.38 Gb, Internal 468.32 Mb
//Se copia carpeta de 16MB
04-22 16:09:10.476: I/System.out(7411): External 2.36 Gb, Internal 468.32 Mb
//Se copia carpeta de 32MB
04-22 16:12:04.349: I/System.out(7411): External 2.34 Gb, Internal 468.32 Mb
//Se copia archivo de +500MB y se desinstala Facebook (pesa 136MB)
04-22 16:27:26.924: I/System.out(23762): External 1.69 Gb, Internal 468.32 Mb
//Se instala app de 136MB
04-22 16:38:39.571: I/System.out(28209): External 1.61 Gb, Internal 468.32 Mb
//Se instala Word
04-22 16:56:00.658: I/System.out(31925): External 1.46 Gb, Internal 468.32 Mb

Note that External does vary according to what you put in the SD, but Internal does not change if you install apps or alter your data / data folder, it remains 468.32 MB.

The code I occupy is the following:

public static long checkInternalUsage() {
    StatFs stat = new StatFs(Environment.getRootDirectory().getPath());
    long bytesAvailable = (long)stat.getBlockSize() * (long)stat.getAvailableBlocks();
    return bytesAvailable;

I know beforehand that the methods getBlockSize and others are Deprecated but in this case I am working with an API < 18, I'm cured in health of that.

If the app (like any other) runs in root mode, is the Environment.getRootDirectory() statement correct to access the space I want to analyze? Any light on this is welcome!

asked by Rosendo Ropher 23.04.2016 в 01:28