Using SAF I create a file in the file provider. In onActivityResult I then persist the permissions to that file and store the Uri into the shared preferences. Later I write data into the file.
This seems to work. except if the file was deleted/moved/renamed or basically if it no longer exists.
I can check whether it exists or not using:
val file = DocumentFile.fromSingleUri(applicationContext, uri)
if (!file!!.exists())
But this doesn't solve the problem that I can not write my data using contentResolver.openOutputStream(uri)
, for I get a FileNotFoundException
.
Is there a way to create the file using the stored Uri, while I should still have the permissions persisted?