Skip to content

android: Attach opens Android's chooser (files, photos, camera); Qt's file dialog hears the answer - #2132

Closed
trissim wants to merge 1 commit into
mainfrom
android-native-picker
Closed

trissim wants to merge 1 commit into
mainfrom
android-native-picker

Conversation

@trissim

@trissim trissim commented Nov 18, 2026

Copy link
Copy Markdown

Tristan, 2026-11-18: "the attach feature ... on mobile shows the same file picker as if it was on desktop. On Android I would rather it bring up the native file picker dialog — is it a photo, is it a camera, or is it a file — ... You can keep that existing window file picker for the desktop version."

Why the desktop dialog showed on the phone

Two owners were in the way:

  • pyqt-reactive's theme set AA_DontUseNativeDialogs on every platform, so Qt drew its widget dialog. The phone's log confirms it: Toad never launched a document intent. theming: phones keep the system's file picker; desktops keep the themed dialog PyQT-reactive#66 (merged, b63f12386) keeps native dialogs where the system's picker is the only way into storage (android, ios).
  • python-for-android's PythonActivity.onActivityResult notifies only its own listeners and never calls super. Qt's receivers, including the native file dialog's, never heard a result. QtActivityBase.onActivityResult is Activity.onActivityResult followed by QtNative.onActivityResult (javap of the shipped Qt6Android.jar). The second call is package-private, so org.qtproject.qt.android.QtActivityResults.deliver calls it, and ToadActivity.onActivityResult calls that after p4a's override.

The chooser

ToadActivity.startActivityForResult offers Qt's document request (ACTION_OPEN_DOCUMENT + CATEGORY_OPENABLE) to AttachChooser. That becomes Android's chooser:

  • ACTION_GET_CONTENT for the same types (Files, Photos, Drive);
  • a camera capture as its first choice, writing a new pending MediaStore photo in Pictures/Toad.

The answer reaches Qt's dialog as a content URI either way: the app's own URI, or the camera's photo with its pending flag cleared. A chooser left any other way deletes the pending photo. file_pickers.read_picked already reads content URIs through QFile, so no Python path changes.

Desktop: unchanged, the themed QFileDialog. WindowFilePicker stays the one choice; its documented meaning was already "the platform's file dialog; a phone shows its own".

Checks

  • javac --release 11 compiles ToadActivity (against p4a's qt-bootstrap PythonActivity and Qt6Android/Qt6AndroidBindings.jar), AttachChooser and QtActivityResults.
  • Gates: see the comment below once the run finishes. The run uses the full drive set including composer (desktop Attach still opens the themed QFileDialog), plus ratchet, shadow and check.sh.

Not provable off the device

Each of these is checked by building the APK and tapping Attach on the phone:

  • the chooser shows Files/Photos/Camera;
  • the camera writes the photo;
  • Qt's helper accepts a GET_CONTENT URI. Its takePersistableUriPermission throws for such URIs; QJniObject clears the exception;
  • QFileInfo(content://…).fileName() gives the display name.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3

… file dialog hears the answer

On the phone Attach showed Qt's widget file dialog, a desktop dialog that lists only the
app's own directories (Tristan: "it shows the same file picker as if it was on desktop ...
bring up the native file picker: is it a photo, is it a camera, or is it a file").

Two owners were in the way. pyqt-reactive's theme turned native dialogs off on every
platform (PyQT-reactive#66 keeps them on phones). And python-for-android's PythonActivity
overrides onActivityResult without calling super, so Qt's receivers - its native file
dialog's - never heard a result: QtActivityResults hands each result to Qt's package-private
entry, as QtActivityBase does, and ToadActivity calls it.

ToadActivity offers Qt's document request to AttachChooser: ACTION_GET_CONTENT for the same
types in Android's chooser (Files, Photos, Drive), with a camera capture into a new
MediaStore photo (Pictures/Toad) as its first choice. Either answer reaches Qt's dialog as
a content URI, which file_pickers.read_picked already reads. Desktops keep the themed dialog;
WindowFilePicker stays the one choice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
@trissim

trissim commented Nov 18, 2026

Copy link
Copy Markdown
Author

Merged as part of #2133, gated together with four other branches.

@trissim trissim closed this Nov 18, 2026
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