CommunityToolkit / CommunityToolkit/Maui

[BUG] CameraView CaptureImage Faults on Android

Open
#2,942 1 comment 1 reaction 0 assignees View on GitHub
bug unverified
Dominant language
C#
Stars
2.7k
Forks
500
Avg merge
2d 14h
Merged PRs (30d)
7

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Did you read the "Reporting a bug" section on Contributing file?

- [x] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug

### Current Behavior

I have an old piece of code that does not uses MVVM but instead calls `CaptureImage` out of an event method (`OnPictureTaken` in the repro) called as a result of a `MediaCaptured` event. It works fine in Windows but crashes in Android.

### Expected Behavior

`CaptureImage` should work on Android as it does on Windows.

### Steps To Reproduce

1. Open, build and run the application from the test repo on Windows
2. Tap the button to take a picture and note it pops up a dialog confirming one has been taken.
3. Build and run it on Android it throws a Java exception, "Not bound to a valid Camera".

There's a certain amount of extraneous junk in the code as i was trying to reproduce my failing page as exactly as possible. Just ignore it.

A workaround is to use the CameraView CaptureImage command instead.

### Link to public reproduction project repository

https://github.com/david-maw/DivisiBillCamera.git

### Environment

```markdown
- .NET MAUI CommunityToolkit.Maui:13.0.0
- .NET MAUI CommunityToolkit.Maui.Camera:5.0.0
- OS: Any Android
- .NET MAUI: 10.0.0
```

### Anything else?

Low priority for me, since the MVVM workaround, once written, is cleaner code anyway.

There were a couple of warnings during the build that seem irrelevant but worth mentioning:

```
1>...: warning NU1608: Detected package version outside of dependency constraint: Xamarin.AndroidX.Fragment.Ktx 1.8.8.1 requires Xamarin.AndroidX.Fragment (>= 1.8.8.1 && < 1.8.9) but version Xamarin.AndroidX.Fragment 1.8.9 was resolved.
1>...: warning NU1608: Detected package version outside of dependency constraint: Xamarin.AndroidX.Lifecycle.Process 2.9.2.1 requires Xamarin.AndroidX.Lifecycle.Runtime (>= 2.9.2.1 && < 2.9.3) but version Xamarin.AndroidX.Lifecycle.Runtime 2.9.3 was resolved.
```

Contributor guide

Open the contributing guide

Research direction

Start by running the linked DivisiBillCamera reproduction on Android and trace the OnPictureTaken handler invoked by the MediaCaptured event. Compare its direct CaptureImage call with the working CaptureImage command workaround; done means direct CaptureImage no longer throws “Not bound to a valid Camera” on Android.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, csharp
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.