Skip to content

Replace direct file access with Storage Access Framework for markdown export#13

Merged
j-almenara-r merged 3 commits intomainfrom
copilot/fix-export-to-markdown-feature
Jan 2, 2026
Merged

Replace direct file access with Storage Access Framework for markdown export#13
j-almenara-r merged 3 commits intomainfrom
copilot/fix-export-to-markdown-feature

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 1, 2026

The export feature saved files to a hardcoded system directory (/storage/emulated/0/Documents/VoiceNotes/), showed truncated paths in Toast messages, and provided no way to choose save location.

Changes

MainActivity.kt

  • Replace direct file writing with ACTION_CREATE_DOCUMENT intent
  • Add writeNotesToUri() to handle ContentResolver-based writing
  • Optimize file writing with single write operation using buildString
  • Add explicit null check on openOutputStream() with error feedback
// Before: Direct file access
val file = File(documentsDir, "VoiceNotes/$filename")
FileWriter(file).use { writer ->
    writer.write("# Voice Notes Export\n\n")
    // ... multiple writes
}

// After: SAF with user-chosen location
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
    type = "text/markdown"
    putExtra(Intent.EXTRA_TITLE, "voice-notes-$timestamp.md")
}
startActivityForResult(intent, CREATE_FILE_REQUEST_CODE)

// Write once with buildString
contentResolver.openOutputStream(uri)?.use { 
    it.write(markdownContent.toByteArray())
} ?: throw Exception("Failed to open output stream")

AndroidManifest.xml

  • Remove WRITE_EXTERNAL_STORAGE permission (unnecessary with SAF)

strings.xml

  • Update success message to remove file path reference

Users now get a system file picker to choose save location, with a pre-filled ISO 8601 timestamped filename. No storage permissions required.

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix Export to Markdown feature</issue_title>
<issue_description>Current behavior:

  • A click in the "Export to markdown" button yields a "Notes exported successfully to: /storage/emulated/0/Dcouments..." and nothing else.

Problems:

  • I couldn't see the entire file path.
  • It was very hard for me to find the file in the "File Explorer". My phone is in Spanish, and turns out they are under "/Almacenamiento Interno/Documents/VoiceNotes/voice-notes-20260101T18-19-45.md".
  • I didn't get prompted for a custom storage location, which I was expecting.

</issue_description>

<agent_instructions>Could you improve the overall experience taking into account this issue and the original #6?</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 1, 2026 18:00
Co-authored-by: j-almenara-r <246562873+j-almenara-r@users.noreply.github.com>
Co-authored-by: j-almenara-r <246562873+j-almenara-r@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix export to Markdown feature for better user experience Replace direct file access with Storage Access Framework for markdown export Jan 1, 2026
Copilot AI requested a review from j-almenara-r January 1, 2026 18:04
@j-almenara-r j-almenara-r marked this pull request as ready for review January 1, 2026 20:39
@j-almenara-r j-almenara-r merged commit 964ab18 into main Jan 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix Export to Markdown feature

2 participants