Skip to content

Claude/bug opening a file from recents fails with a permi l fad j#29

Merged
kevincarlson merged 2 commits into
masterfrom
claude/bug-opening-a-file-from-recents-fails-with-a-permi-lFadJ
Mar 30, 2026
Merged

Claude/bug opening a file from recents fails with a permi l fad j#29
kevincarlson merged 2 commits into
masterfrom
claude/bug-opening-a-file-from-recents-fails-with-a-permi-lFadJ

Conversation

@kevincarlson

Copy link
Copy Markdown
Member

Android's Storage Access Framework (SAF) grants only a temporary permission for a content:// URI when the user picks a file via the file picker. That permission is tied to the app process and is revoked when the app is killed. Attempting to re-open the same URI from Recents in a new session therefore fails with a permissions error.

Fix — 4 changes:

UriPermissionPlugin.kt (new) — A Tauri Android plugin that calls ContentResolver.takePersistableUriPermission(uri, READ | WRITE). Android will then persist that grant across app restarts in its own permission store.

MainActivity.kt — Registers the plugin via registerPlugin(UriPermissionPlugin::class.java) so Tauri routes the JS invoke call to it.

commands.ts — Adds takePersistableUriPermission(uri), a typed TypeScript wrapper around invoke('plugin:uriPermission|takePersistablePermission', { uri }).

useFileOperations.ts — Calls takePersistableUriPermission in two places:
    loadDocument() — when a content:// file is opened (covers the file picker path and the Recents path on first open)
    handleSaveAs() — when a new file is saved to a content:// destination

Both calls are wrapped in try/catch so they are silently ignored on desktop and on URIs that don't support persistable permissions.

claude and others added 2 commits March 23, 2026 06:09
…rks after restart

On Android, the Storage Access Framework grants only a *temporary* permission
when the user picks a file via the file picker. That permission is revoked when
the app process is killed, which is why opening a file from Recents after an
app restart failed with a permissions error.

Fix:
- Add UriPermissionPlugin.kt: a Tauri Android plugin that calls
  ContentResolver.takePersistableUriPermission() for a given content:// URI.
- Register the plugin in MainActivity.kt.
- Add takePersistableUriPermission() TypeScript wrapper in commands.ts.
- Call it in useFileOperations.loadDocument() and handleSaveAs() whenever a
  content:// URI is opened or saved for the first time, so the permission is
  durably stored and survives subsequent app restarts.

Errors from the permission call are swallowed (non-fatal) so the fix is
transparent on desktop platforms and on URIs that don't support persistence.

Fixes #24

https://claude.ai/code/session_01KdVehRZ9Rk2MyyEuzSbpHJ
Merging fix for Android file I/O permissions
@kevincarlson kevincarlson merged commit ad26069 into master Mar 30, 2026
12 checks passed
@kevincarlson kevincarlson deleted the claude/bug-opening-a-file-from-recents-fails-with-a-permi-lFadJ branch March 30, 2026 07:01
@AppThere AppThere locked and limited conversation to collaborators Mar 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants