Skip to content

Camera image upload to file input (frontend) #6055

@Mofef

Description

@Mofef

Home Assistant Android app version(s):
2025.8.7-full

Android version(s):
16 / 1st of July 2025

Device model(s):
Samsung Galaxy S25 Ultra a.k.a. SM-S938B/DS

Home Assistant version:
Installation method Home Assistant Container
Core 2025.11.2
Frontend 20251105.0

Last working Home Assistant release (if known):
//

Description of problem, include YAML if issue is related to notifications:

I am working on a custom dashboard card for the bparasite plant sensor, which offers users to upload a photo of their plant in the config page of the card.

I could not make that work with a prompt to directly take a camera image in the app it did work when i accessed HA via the chrome browser on my android though. Since this feature seems to be known to be flaky on Android, I asked Gemini to create test-cases, which you can find here: https://mofef.github.io/android_camera_test.html
They work as intended via android chrome but not if I integrate the exact same page as an iframe into my card. It only ever shows a file picker, not offering the camera option.

The HA app does have camera permission in case that is relevant.

Since I'm not familiar with android development i asked Gemini for a hypothesis:
Currently, the Home Assistant Android app's WebView implementation of onShowFileChooser appears to only trigger the standard file picker (ACTION_GET_CONTENT). On modern Android versions (14+), this often defaults to the new Photo Picker or a system file picker that omits the Camera tile.

This makes it impossible for a user to "Take a Photo" directly from an HTML <input type="file"> element within the HA app. They are forced to background the app, open the Camera app, take a photo, return to HA, and select the file from the gallery.

Here is some more of what Gemini has to say about it, but I don't have the competence to review that sadly. Please ignore unless you are interested: trigger warning: potential AI slop

### Testing & Diagnosis I have tested the following HTML5 input configurations inside the Home Assistant Android App (latest version) on Android 14/15.
HTML Input Configuration Result in HA App Result in Chrome (Ref)
<input type="file" accept="image/*"> Opens Gallery (Photo Picker). No Camera option. Gallery (Photo Picker).
<input type="file" accept="image/*" capture="environment"> Opens Gallery. No Camera option. Opens Camera directly.
<input type="file" accept="image/*, .pdf"> Opens System Files. No Camera option. Opens System Files + Camera option.
<input type="file" accept="image/*, android/hack"> Opens System Files. No Camera option. Opens System Files + Camera option.

Conclusion: The WebView seems to be lacking the specific intent logic to handle capture attributes or to append the MediaStore.ACTION_IMAGE_CAPTURE intent to the chooser dialog.

Proposed Solution

I propose updating the WebChromeClient.onShowFileChooser override in the Android app to explicitly add the ACTION_IMAGE_CAPTURE intent to the chooser options.

This is a standard pattern for Android WebViews to support HTML5 camera inputs. By creating a takePictureIntent and adding it to the Intent.createChooser extra EXTRA_INITIAL_INTENTS, the WebView will present the user with both the File Manager and the Camera.

Companion App Logs:

Pretty sure its irrelevant, let me know otherwise please

Screenshot or video of problem:
card config page before clicking a button (current state while debugging with different file inputs):
Image
behaviour in app:
Image
behaviour in chrome:
Image
card (just for illustration, irrelevant to the issue):
Image

Additional information:
I'm not an Android developer (last contact point 2011) but I'm in SWE since 10 years so I'm happy to take directions and prepare a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions