Skip to content

fix(android): napplet file inputs open the file picker - #154

Merged
Origami74 merged 1 commit into
mainfrom
fix/napplet-file-chooser
Oct 19, 2026
Merged

Origami74 merged 1 commit into
mainfrom
fix/napplet-file-chooser

Conversation

@Origami74

@Origami74 Origami74 commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

What

An <input type="file"> in a napplet opens the system file picker, and its accept list is honoured.

Why

WebView shows a picker only when the app implements WebChromeClient.onShowFileChooser; the napplet window did not, so file fields did nothing. And FileChooserParams.createIntent passes only the first accept entry on, as a MIME type: accept=".csv,text/csv" asked for files of type ".csv" and nothing could be chosen.

How

  • NappletActivity sets a WebChromeClient with onShowFileChooser, launching the picker through an activity-result contract; the result goes to that window only, as a browser hands a picked file to the page that asked.
  • fileChooserIntent / acceptedMimeTypes map every accept entry: extensions to MIME types (CSV also under the names Android files it as), anything unknown opens the picker to all files rather than none.
  • SystemAskTest allowlists NappletActivity.kt for registerForActivityResult: the document picker is user-initiated and asks Android for no permission.
  • CHANGELOG.md [Unreleased] → Fixed: "A napplet's file field opens the file picker."

Testing

  • testDebugUnitTest passes, including SystemAskTest (which failed CI before the allowlist line) and FileChooserTest (3 unit tests); compileDebugKotlin passes.
  • On device (A52): a napplet's CSV file field opens the picker and the CSV in Downloads (text/comma-separated-values) is selectable.

Tapping an <input type="file"> in a napplet (lightertrek's CSV import) did
nothing, and once it did open, a field with accept=".csv,text/csv" let no
file be chosen.

WebView shows a picker only when the app implements
WebChromeClient.onShowFileChooser, which the napplet window did not, and
FileChooserParams.createIntent passes only the first accept entry on, as a
MIME type, so ".csv" matched no file.

The window now implements onShowFileChooser, launching the system picker
through an activity-result contract and handing the result to that window
only. fileChooserIntent/acceptedMimeTypes map every accept entry:
extensions to MIME types (CSV also under the names Android files it as),
and anything unknown opens the picker to all files rather than none.

SystemAskTest allowlists NappletActivity.kt for registerForActivityResult:
the document picker asks Android for no permission.
@Origami74
Origami74 force-pushed the fix/napplet-file-chooser branch from 387d644 to 4d0bf09 Compare October 19, 2026 13:48
@Origami74
Origami74 merged commit e6e8ce8 into main Oct 19, 2026
4 checks passed
@Origami74
Origami74 deleted the fix/napplet-file-chooser branch October 19, 2026 13:56
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.

1 participant