diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt index abb4e277..42cea30c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt @@ -568,9 +568,11 @@ class MainActivity : SimpleActivity() { if (needsStupidWritePermissions(path)) { handleSAFDialog(path) { - var document = getDocumentFile(File(path).parent) ?: return@handleSAFDialog - if (!File(path).exists()) { - document = document.createFile("", path.getFilenameFromPath())!! + val document = if (File(path).exists()) { + getDocumentFile(path) ?: return@handleSAFDialog + } else { + val parent = getDocumentFile(File(path).parent) ?: return@handleSAFDialog + parent.createFile("", path.getFilenameFromPath())!! } contentResolver.openOutputStream(document.uri).apply {