Hi everyone, i am trying to save a csv file on an ...
# android
s
Hi everyone, i am trying to save a csv file on an android app, so it can later be accessed by users and downloaded from the device. I am using an Android 12 tablet. I cant get it working writing the file so that i can see it in the Files App. At the moment i am trying it like this, but this obviously doesnt work:
Copy code
val directory = context.getExternalFilesDir("")
val file = File(directory, fileName)

// If the file does not exist, write the header
if (!file.exists()) {
    FileWriter(file).write(header)
    FileWriter(file).use { writer ->
        writer.write("\n")
    }
}

return file
Has anyone a idea what i am doing wrong? I would really appreciate any help. It doesnt have to be persistent when the app is uninstalled, but i want to at least find the file on the device when it is saved. I have the bad feeling, i need to use SAF and open the document tree to write files that i can use later, but using SAF is cluttering my MainActivity and is not really simple to implement after what i read. Is there no way of just writing a file to a folder that can be accessed by the files app without that much overhead? Thanks in advance folks.
not kotlin but kotlin colored 2
🧵 1
c
This is a workspace of the Kotlin programming language. Your general question should be asked somewhere else - you can find some resources in the channel description.