Skip to content

fix(mobile): open the gallery without the system photo picker - #823

Merged
huichen merged 1 commit into
mainfrom
fix/album-picker
Sep 25, 2026
Merged

huichen merged 1 commit into
mainfrom
fix/album-picker

Conversation

@huichen

@huichen huichen commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

On a Huawei phone without Play services, tapping 相册 in the attachment menu opened the document picker (Download folder / file browser). Media permission for the app was granted and had no effect on it; 拍照 and 选择手机文件 behaved exactly as labelled.

Root cause: pickFromAlbum passes legacy: false to expo-image-picker, which hands the call to AndroidX PickVisualMedia. That contract only presents a real picker where Android 13's system photo picker exists, or where the Play-services / R-extension photo-picker backport has landed on API 30-32. Where neither holds, PickVisualMedia.createIntent silently resolves to ACTION_OPEN_DOCUMENT — the document picker — which is what the phone showed. The full-album media permission cannot influence this path: neither picker asks for it, by design.

Fixes for that class of device:

  • Below API 33, ask the phone's own gallery for one image: ACTION_PICK on content://media/external/images/media, without CATEGORY_OPENABLE so DocumentsUI (whose ACTION_PICK filter requires openable documents) cannot take the call instead.
  • The returned photo is copied into the cache while the read grant is live, then goes through the same attachment pipeline as any other image (size cap, format checks, quotas, name preserved from the gallery).
  • API 33+ is unchanged: the system photo picker with multi-select. Devices with no gallery app at all fall back to the existing contract, i.e. today's behaviour.

Neither route requests a full-album permission or the media permission shown in app info — both grant the selected photos alone.

Validation

  • tsc --noEmit and eslint clean; full mobile suite 125 suites / 1910 tests passed (3 new cases: gallery-first below API 33, cancellation, no-gallery fallback).
  • No new native dependency (expo-intent-launcher was already used by the update flow), so JS only — no native rebuild needed for the fix to take effect on an existing install.
  • Not verified on a physical device. Remaining limit, now recorded in docs/internals/mobile/harmonyos-compatibility.zh-CN.md: if a compatibility runtime exposes no app handling ACTION_PICK on the MediaStore image collection (i.e. only the document picker), the album is unavailable from the APK and the picker falls back to the file browser — that needs a HarmonyOS-native photoAccessHelper.PhotoViewPicker target, not an APK-side change.

Docs updated: docs/internals/mobile/README.md, README.zh-CN.md, harmonyos-compatibility.zh-CN.md.

AndroidX's PickVisualMedia contract only presents a real picker where Android
13's system photo picker — or the Play-services backport that older versions
can receive — exists. Everywhere else it silently resolves to
ACTION_OPEN_DOCUMENT, which is the document picker: on a Huawei phone without
Play services, 相册 opened the file browser while 相机 and 选择手机文件 behaved
exactly as labelled.

Below API 33, ask the phone's own gallery for one image instead: ACTION_PICK on
MediaStore's image collection, without CATEGORY_OPENABLE, so the document
picker has no matching filter and the call stays on gallery apps. Copy the
returned photo into the cache while the read grant is live, then hand it to the
shared attachment pipeline like any other image. The contract remains the
fallback for devices with no gallery app at all, and Android 13+ keeps the
system photo picker with its multi-select.

Neither route asks for a full-album permission or requests the media permission
the OS shows in app info: the picker grants the selected photos alone.
@huichen
huichen enabled auto-merge (squash) September 25, 2026 09:28
@huichen
huichen merged commit 7c116f0 into main Sep 25, 2026
12 checks passed
@huichen
huichen deleted the fix/album-picker branch September 25, 2026 09:31
huichen added a commit that referenced this pull request Sep 25, 2026
…wser (#829)

#823 opened the gallery below API 33 and still let AndroidX's photo-picker
contract run when no gallery answered. On the Huawei phone that reported the
bug the album item keeps showing the document picker — the file browser the
report was about — because the contract degrades to ACTION_OPEN_DOCUMENT
wherever no system photo picker exists, and because nothing tells us whether
the gallery intent reaches a gallery or a file manager.

Resolve the candidates first instead of guessing from the API level:

- future-file-handler gains resolveImagePickRoutes, which reports the apps that
  would answer the album intent, Android 13's photo picker, the AOSP photo
  picker backport, and (for diagnostics) the document picker. Its manifest
  declares those intents in <queries>, without which package visibility hides
  user-installed galleries from the query and the router would read them as
  absent.
- The album router then decides: Android 13+ keeps the system photo picker
  (multi-select) when it answers; below 33 a gallery that advertises
  ACTION_PICK on MediaStore's image collection wins and is launched explicitly
  by component, so a file manager that also advertises the pick cannot stand in
  for it; a real backport photo picker is next; otherwise the album reports
  itself unavailable. It never opens the document picker — that is what
  "Choose files" is for, and opening one under the album label is the failure
  being fixed.
- Gallery recognition uses package-name hints, since Android has no "is this a
  gallery" flag. An unknown package is not treated as a gallery: a missed
  gallery degrades to the honest message, while a false positive reproduces the
  original complaint. The resolution is logged when nothing can present the
  album, so a device report can tell "no album app" from "only a file manager".
- App binaries without the probe keep the previous order, so a JS/native
  version skew does not change behaviour.
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