views:

691

answers:

1

how can you retrieve yours phone internal storage from an app? I found memoryinfo, but it seems that returns information on how much memory your currently running tasks. I am trying to get my app to retrieve how much internal phone storage is available.

+3  A: 

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);
jleedev
@jleedev nice solution, thanks
systempuntoout
thanks, I will try this out later :)
John
works great, thanks!
John
@John Thanks and welcome to Stack Overflow. If you click the check mark next to the answer, it will mark it as accepted.
jleedev