From 86d7678b5717e2534e0dec096d7cbdfe0b45cf18 Mon Sep 17 00:00:00 2001 From: Hamza Al Omari Date: Wed, 14 Oct 2026 15:46:14 +0200 Subject: [PATCH] fix(android): register ActivityResult launchers against Bridge for Portals 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> --- .../com/capacitorjs/plugins/camera/IonCameraFlow.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/com/capacitorjs/plugins/camera/IonCameraFlow.kt b/android/src/main/java/com/capacitorjs/plugins/camera/IonCameraFlow.kt index 7b35d3f..c8e46cf 100644 --- a/android/src/main/java/com/capacitorjs/plugins/camera/IonCameraFlow.kt +++ b/android/src/main/java/com/capacitorjs/plugins/camera/IonCameraFlow.kt @@ -147,37 +147,37 @@ class IonCameraFlow( // Launchers // ---------------------------------------------------- private fun setupLaunchers() { - cameraLauncher = activity.registerForActivityResult( + cameraLauncher = bridge.registerForActivityResult( ActivityResultContracts.StartActivityForResult() ) { result -> handleCameraResult(result) } - cameraCropLauncher = activity.registerForActivityResult( + cameraCropLauncher = bridge.registerForActivityResult( ActivityResultContracts.StartActivityForResult() ) { result -> handleCameraCropResult(result) } - videoLauncher = activity.registerForActivityResult( + videoLauncher = bridge.registerForActivityResult( ActivityResultContracts.StartActivityForResult() ) { result -> handleVideoResult(result) } - galleryLauncher = activity.registerForActivityResult( + galleryLauncher = bridge.registerForActivityResult( ActivityResultContracts.StartActivityForResult() ) { result -> handleGalleryResult(result) } - galleryCropLauncher = activity.registerForActivityResult( + galleryCropLauncher = bridge.registerForActivityResult( ActivityResultContracts.StartActivityForResult() ) { result -> handleGalleryCropResult(result) } - editLauncher = activity.registerForActivityResult( + editLauncher = bridge.registerForActivityResult( ActivityResultContracts.StartActivityForResult() ) { result -> handleEditResult(result)