-
Notifications
You must be signed in to change notification settings - Fork 2.2k
GH-328 android: handle photo from camera #857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LuckyLuky
wants to merge
1
commit into
apache:master
Choose a base branch
from
LuckyLuky:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 tasks
moklett
added a commit
to servus/cordova-plugin-inappbrowser
that referenced
this pull request
Mar 18, 2022
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)
moklett
added a commit
to servus/cordova-plugin-inappbrowser
that referenced
this pull request
Jan 21, 2025
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)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Platforms affected
Android
Motivation and Context
Allows users to use camera, not just file browser.
Closes #328.
Description
Added new ImageCapture intent and an option to choose between file browser and camera.
Testing
For image upload, I've tried to add image from file browser and camera. I've also tested changing from one to another.
Checklist
(platform)
if this change only applies to one platform (e.g.(android)
)