1

I'm trying to get the total internal storage and available storage for the android device but the code I have only gets the available disk space. Any advice on how to get total storage space.

    private fun getStorage() {

        val stat = StatFs(Environment.getDataDirectory().path)
        val bytesAvailable: Long = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            stat.blockSizeLong * stat.availableBlocksLong
        } else {
            TODO("VERSION.SDK_INT < JELLY_BEAN_MR2")
        }
        val gbAvailable = (bytesAvailable / (1024 * 1024) ) * 0.001
        Log.d("Storage", "Available GB : ${gbAvailable.roundToInt()}")
    }
kongkip
  • 61
  • 1
  • 7
  • Does this help? https://stackoverflow.com/questions/8133417/android-get-free-size-of-internal-external-memory – Quinn Feb 17 '21 at 18:03

1 Answers1

0

stat.getTotalBytes()

Returns (from the docs) "The total number of bytes supported by the file system."

How to find the amount of free storage (disk space) left on Android?

ryankuck
  • 320
  • 3
  • 15