Repository navigation
fix(android): use bridge.registerForActivityResult for Fragment compatibility - #84
Merged
jcesarmobile merged 1 commit intoOct 16, 2026
Conversation
…rtals compatibility IonCameraFlow.setupLaunchers() registered its six ActivityResult launchers directly against the Activity. Under Ionic Portals the Bridge is built in PortalFragment.onViewCreated() when the host Activity is already STARTED/RESUMED, so AndroidX's registerForActivityResult guard throws IllegalStateException and the plugin fails to load (masked by Capacitor as PluginLoadException). Register against Capacitor's Bridge instead, which resolves to the hosting Fragment (still CREATED) under Portals and to the Activity otherwise. The contracts, callbacks, and runtime behavior are unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jcesarmobile
approved these changes
Oct 15, 2026
capacitor-bot
pushed a commit
that referenced
this pull request
Oct 16, 2026
## [8.2.6](v8.2.5...v8.2.6) (2026-10-16) ### Bug Fixes * **android:** use bridge.registerForActivityResult for Fragment compatibility ([#84](#84)) ([41ece15](41ece15))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CameraPluginfails to register duringBridgeinitialization on Android when hosted inside Ionic Portals, making camera features completely non-functional in Portals flows. iOS is unaffected.Sibling fix of ionic-team/capacitor-geolocation#104.
IonCameraFlow.setupLaunchers()registers its sixActivityResultlaunchers directly against the Activity. AndroidX only allowsregisterForActivityResultwhile the owner's lifecycle is≤ CREATED. In a stockBridgeActivitytheBridgeis built in the Activity'sonCreate()(stateCREATED), so this is legal. Under Portals theBridgeis built inPortalFragment.onViewCreated(), by which point the host Activity is alreadySTARTED/RESUMED, so AndroidX throws and Capacitor masks it as aPluginLoadException.Root cause
Capacitor already exposes
Bridge.registerForActivityResult(...), which registers against the hosting Fragment when one exists (thePortalFragment, stillCREATEDduringonViewCreated) and against the Activity otherwise. Every non-rewritten Capacitor plugin uses this path — which is why only the ion*-based plugins fail.Fix
Change the registration target from the Activity to Capacitor's
Bridgefor all six launchers inIonCameraFlow.setupLaunchers()(cameraLauncher,cameraCropLauncher,videoLauncher,galleryLauncher,galleryCropLauncher,editLauncher):IonCameraFlowalready receivesbridge: Bridgein its constructor, so no signature change is needed. Contracts, callbacks, and runtime behavior are identical — only the lifecycle owner of the registration changes. Under a standardBridgeActivity,Bridge.registerForActivityResultresolves to the Activity, so existing hosting is unaffected.Steps to reproduce
PortalFragmentwhere the containing Activity is alreadySTARTED/RESUMEDwhen the Portal loads.@capacitor/camera.PortalFragment.onViewCreated→ Bridge init.Testing
npm run verify:android(./gradlew clean build test) — passes.Notes
PluginLoadExceptionin capacitor core to chain the underlying exception — the current "Ensure plugin is publicly accessible" message obscures the real cause and initially misdirects debugging.