Here is a basic device utility class that list out all device storage info.
- Available internal memory size.
- Total internal memory size.
- Available external memory size.
- Total external memory size.
Remember to use this utility we need application READ_EXTERNAL_STORAGE .
In code i did not imported required packages as it depends upon your application project packages.
public class DeviceInfoUtil { Context mContext; public DeviceInfoUtil(Context mContext) { this.mContext = mContext; } public long getTotalInternalMemorySize() { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long totalBlocks = stat.getBlockCount(); return totalBlocks * blockSize; } public long getAvailableInternalMemorySize() { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize; } public long getTotalExternelMemorySize() { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long totalBlocks = stat.getBlockCount(); return totalBlocks * blockSize; } public long getAvailableExternelMemorySize() { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize; } } |

