[Enhancement] [Android] In WebView on Android, respect <input type="file" capture="camera" />
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
## Summary
In Xamarin.Forms, a `WebView` on Android does not respect the `capture="camera"` attribute when an `` is clicked on. The default `FormsWebChromeClient.OnShowFileChooser` implementation presents the Intent provided by the OS to the `OnShowFileChooser` method, so the user can only select a file or picture from the photos app, there is no option to open the camera and take a picture.
This is expected behavior when using the intent provided by Android when an `` is selected. Android docs note that if you want to capture live media, then you do have to create your own intent or intent chooser.
See android docs for CreateIntent on the FileChooserParams: https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#createIntent()
> Creates an intent that would start a file picker for file selection.
> The Intent supports choosing files from simple file sources available on the device.
> Some advanced sources (for example, live media capture) may not be supported and applications
> wishing to support these sources or more advanced file operations should build their own Intent."
UIWebVIew on iOS respects the capture attribute and opens the camera as expected.
## API Changes
This suggestion would require having the `FormsWebChromeClient.OnShowFileChooser` method check for the existence of the `capture` element and its value. There are three possible values: `camera`, `user`, and `environment`, though `camera` value is deprecated. `user` should open the front camera, and `environment` should open the back camera. See: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/capture
If the `capture` attribute is not present, then the Intent supplied via the `FileChooserParams fileChooserParams` parameter that is passed into the WebChromeClient.OnShowFileChooser method can be used, but if the `capture` attribute is present, then an Intent would need to be created to open the Camera activity and supply the file path to the picture taken to the filePathCallback.OnRecieve(Uri uri) method.
## Intended Use Case
This would be used anytime a WebView on Android goes to a web page that has an `` element.
It would make the experience with a WebView on Android line up with the experience with a WebView on iOS
Contributor guide
Research direction
Start at FormsWebChromeClient.OnShowFileChooser and review the Android FileChooserParams behavior described in the issue. Compare the supplied intent with the capture values camera, user, and environment, then verify that a captured image is returned through filePathCallback. Done means Android WebView inputs with capture open the appropriate camera while inputs without capture retain the existing file picker behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, csharp
- Domain
- mobile
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100