0

I'm working with SAF (Storage access framework) to write down video files onto SD-CARD. I've successfully create files, read them and moving. But i have found the issue with deleting files.

When i delete files using SAF. Files are gone, but space isn't recover.

For example: when 1 have 2GB left out of 10GB. And i delete file (1GB total) space left is 2GB, not 3GB.

I've used: enter code here

val file: DocumentFile = DocumentFile.fromTreeUri(ctx, treeUri)
file?.delete()

Even:

DocumentsContract.deleteDocument(
                            activity.contentResolver,
                            uri
                        )

and even this:

val path = "/storage/${external?.name}/root.img"
    val f = File(path)


    if (f.exists()) {
        val deleteCmd = "rm -r $path"
        val runtime = Runtime.getRuntime()
        try {
            runtime.exec(deleteCmd)
        } catch (e: IOException) {
            e.printStackTrace()
        }
    }
    app.applicationContext.deleteFile(f.name)
    f.absoluteFile.delete()
    f.exists()
Kvout
  • 1
  • 2
  • Who is telling you the amount of free storage? – blackapps Nov 14 '19 at 19:42
  • Total commander. And i do it in programming way too. By getting storage and count amount of space. Its all the same. New space shows up just after unplug and plug again sd card in slot. – Kvout Nov 15 '19 at 06:35
  • Can confirm what you told. Deleting with SAF does not change the free space on the medium. Well ... if on primary partition it does. But not on micro SD card. Interesting. But is it true? Did you check by further writing to the micro SD card? And which code do you use to determine free space? – blackapps Nov 15 '19 at 10:16
  • Under Settings - Storage one can eject and mount the card. The amount of free space is indicated there and it does display more after remount. Did you check how much you can write to the card if the software tells you there is 2GB free but you assume it will be 3GB? – blackapps Nov 15 '19 at 10:23
  • On the Pixel 2 Android Q emulator same story. Be it that under Settings-Storage the amount of used space is ok. So how is it calculated there.? Offers SAF a disk space calculation? I do it now with the File clas. File.getFreeSpace() and so. – blackapps Nov 15 '19 at 10:43
  • This is about the same: https://stackoverflow.com/questions/56663624/how-to-get-free-and-total-size-of-each-storagevolume – blackapps Nov 15 '19 at 10:55

0 Answers0