Skip to content

Return captured photo to calling app on IMAGE_CAPTURE - #140

Open
EiSiMo wants to merge 1 commit into
iakdis:masterfrom
EiSiMo:fix/image-capture-intent
Open

EiSiMo wants to merge 1 commit into
iakdis:masterfrom
EiSiMo:fix/image-capture-intent

Conversation

@EiSiMo

@EiSiMo EiSiMo commented Oct 24, 2026 •

Copy link
Copy Markdown

LibreCamera registers for IMAGE_CAPTURE / IMAGE_CAPTURE_SECURE in the manifest, but never reads the launching intent. Apps that request a photo (e.g. via ActivityResultContracts.TakePicture) can pick LibreCamera, but it behaves like a normal launch: the photo goes to the gallery and nothing is returned to the caller.

Changes

  • MainActivity.kt: two new calls on the existing media_store channel
    • isCaptureRequest: whether the activity was started with IMAGE_CAPTURE(_SECURE)
    • finishCapture: writes the JPEG to EXTRA_OUTPUT, or returns a small bitmap in the data extra if no output URI was given, then setResult(RESULT_OK) + finish(). Falls back to RESULT_CANCELED if writing fails.
    • onNewIntent updates the intent (activity is singleTop).
  • camera_page.dart: in capture mode, takePicture() hands the processed JPEG to finishCapture instead of saving it to the gallery. This matches what other camera apps do. The camera is released first; otherwise late preview frames hit the detached Flutter engine after finish() and crash the app.

Normal launches are unchanged.

Testing

Tested on a Pixel 8 Pro (Android 17), debug and release builds:

  • Normal launch → photo saved to gallery, app stays open
  • am start -a android.media.action.IMAGE_CAPTURE → activity finishes after capture, no gallery entry
  • Third-party app using TakePicture() → photo arrives in the calling app, no crash

Not covered

  • VIDEO_CAPTURE has the same issue and is not handled here.
  • Unrelated but noticed while testing: leaving the camera screen with the back button crashes with FlutterJNI is not attached to native (same root cause as above, but on master).

Related to #82

🤖 Generated with Claude Code

LibreCamera registers for IMAGE_CAPTURE / IMAGE_CAPTURE_SECURE but never
read the launching intent, so apps requesting a photo (e.g. via
ActivityResultContracts.TakePicture) never got a result and the camera
just behaved like a normal launch.

When started with one of these actions, the processed JPEG is now written
to EXTRA_OUTPUT (or returned as a small "data" bitmap if no output URI is
given), RESULT_OK is set and the activity finishes. The photo is not
saved to the gallery in that case, matching the behavior of other camera
apps. The camera is released before finishing to avoid preview frames
hitting the detached Flutter engine.

VIDEO_CAPTURE has the same problem and is not handled yet.

Related: iakdis#82

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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