Skip to content

Commit

Permalink
Fix missing .json file extension when exporting notes
Browse files Browse the repository at this point in the history
The input from the user doesn't have a .json suffix. Previously, we
passed that value to ActivityResultContracts.CreateDocument as is
(without an extension), and relied on the file picker to automatically
append the extension based on the MIME type.

But some file pickers don't automatically append the extension, e.g.
the native Files app (com.android.documentsui) on Android <= 9, and
FossifyOrg/File-Manager. This results in the exported file not having
a .json extension.

Fix this by manually appending the .json extension before passing the
file name to CreateDocument.

Manually appending the extension shouldn't cause a problem for file
pickers that can automatically add an extension. For example the
native Files app doesn't add a second extension, and if the file
already exists it generates a unique name correctly, with the "(1)"
inserted before the extension, e.g. "Notes (1).json".

Fixes #13.
  • Loading branch information
tom93 committed Jan 31, 2024
1 parent 33969d2 commit 433a7c1
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class SettingsActivity : SimpleActivity() {
private fun setupNotesExport() {
binding.settingsExportNotesHolder.setOnClickListener {
ExportNotesDialog(this) { filename ->
saveDocument.launch(filename)
saveDocument.launch("$filename.json")
}
}
}
Expand Down

0 comments on commit 433a7c1

Please sign in to comment.