Search code examples
androiddiskspace

Retrieve free internal memory on an Android device


I would like to know how I can retrieve device information on my Android mobile application as the free internal memory available on the device.


Solution

  • Try this. following code returns Internal Storage Memory in MB ,

    StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
    long bytesAvailable = (long)stat.getFreeBlocks() * (long)stat.getBlockSize();
    long megAvailable = bytesAvailable / 1048576;