ionic-team / ionic-team/capacitor

feat: consistent file input behavior on android

Open
#6,536 8 comments 9 reactions 0 assignees View on GitHub
platform: android
Dominant language
TypeScript
Stars
16.7k
Forks
1.3k
Avg merge
3d 15h
Merged PRs (30d)
10

Description

## Feature Request

### Description

When using `` on Android, allow the user to choose what app to use (e.g. Camera or Files), unless the behavior is restricted by `accept` or `capture` attributes.

Current behavior on Android with Capacitor seems to be:
- If [`capture`](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/capture) attribute is present, and `IMAGE_CAPTURE` action is defined in `AndroidManifest.xml` then open the camera,
- Otherwise open the file browser

This differs from the behavior in Chrome for Android or Capacitor on iOS, both of which let the user choose between multiple apps when the `capture` attribute isn't set.

### Platform(s)
- Android

### Preferred Solution
Show an [app chooser](https://developer.android.com/training/basics/intents/sending#AppChooser) an Android depending on the `accept` and `capture` properties:
- If [`capture`](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/capture) attribute is present, then directly open camera
- If [`accept`](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept) attribute is used to only include types that aren't images, then directly open file browser
- Otherwise show an [app chooser](https://developer.android.com/training/basics/intents/sending#AppChooser), which should include at least Camera and File options

![](https://user-images.githubusercontent.com/3334654/234116440-e34676cb-e9cd-4fa1-b70e-8be23e4a0090.png)

Also document that on Android it's necessary to add the following code to `AndroidManifest.xml` in order to show the camera from a file input:

```xml






```

### Alternatives

Document the differences in behavior between Android and web/iOS, as well as a suggested workaround (e,g, implementing a custom action sheet or popover with options for Camera and Files).

### Additional Context

- https://github.com/apache/cordova-android/issues/816
- https://github.com/ionic-team/capacitor/pull/809

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.