hotwired / turbo-android

Android framework for making Turbo native apps
MIT License
431 stars 49 forks source link

Enable image capture for file uploads #141

Closed jayohms closed 3 years ago

jayohms commented 3 years ago

Addresses: https://github.com/hotwired/turbo-android/issues/139

Given the following markup, turbo-android already handles opening a file chooser to upload files:

<input type="file" id="file" accept="*/*" />

However, it's not currently possible change the file Intent to capture an image from the camera. Android's WebChromeClient [handles the capture attribute](https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#isCaptureEnabled()):

<input type="file" id="photo" accept="image/*" capture="user" />

This PR adds the following behavior:

When set on a file input type, operating systems with microphones and cameras will display a user interface allowing the selection from an existing file or the creating of a new one.

When capture is enabled, Android will present an Intent chooser:

2021-02-02 17 16 18

Known limitation: video and audio intents are not currently supported, but this solves the primary use case.