You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This builds on LuckyLuky's [commit](LuckyLuky@876a12a) in [PR apache#857](apache#857) to improve the camera path for file inputs (`<input type="file"/>`) on Android.
The changes are:
- Light refactoring to extract work such as configuring the intent into functions
- Only offer the "Image Capture" intent if the device has a camera app and the file input has an accept type of an image (e.g. "image/png" or "image/*")
- Use a cache directory to store files, rather than the external storage. This mimics how cordova-plugin-camera stores files.
- Mark the photos for later deletion with `deleteOnExit`. I'm not sure how robust this is, so if we truly wanted to clean up files, we would need to do it explicitly, each time `onShowFileChooser` was fired.
Both the change in the original commit and in this one rely on the FileProvider API to allow the passing of content URIs (rather than File URIs) between this plugin and the camera app. As such, the FileProvider must be configured. The Camera Plugin does this in plugin.xml, but no such change has been made here yet. Therefore, configuration similar to the following must be added to the main app.
```xml
<!-- config.xml -->
<widget>
...
<platform name="android">
<!-- Configure our FileProvider-->
<config-file target="AndroidManifest.xml" parent="application">
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="YOUR_APP_ID.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/camera_provider_paths"
/>
</provider>
</config-file>
<resource-file src="camera_provider_paths.xml" target="app/src/main/res/xml/camera_provider_paths.xml" />
</platform>
...
</widget>
```
```xml
<!-- camera_provider_paths.xml -->
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path name="cache_files" path="." />
</paths>
```
Fore more information on the above configuration, see the ["Take photos" Guide on Android Developers](https://developer.android.com/training/camera/photobasics)
The following improvements could be made to this feature of the plugin:
- Use the `captureEnabled()` boolean on the file chooser params to only offer the camera when capture is enabled on the HTML element
- Image downscaling - it would be very nice to allow control over the quality and size of the captured image. But, at this point, could we just delegate to the existing Camera plugin? (cordova-plugin-camera)
0 commit comments