-
-
Notifications
You must be signed in to change notification settings - Fork 674
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
Add an implementation of Camera for Android. #2353
Conversation
Related: I previously thought that we didn't need a permission to use the camera intent, because it's the camera app that's accessing the camera and not us. But apparently it's not that simple, because if you have the camera permission in the manifest, then it must be enabled even to use the camera intent, and it would be ridiculous for us to tell the user "if you want to use the camera, then DON'T include the camera permission".
Unfortunately it looks like the mechanism for passing intents and responses has a 1 MB limit, so that's why they have to pass the image using a file.
This is the first time I've looked into this area, and I agree it's very frustrating. And 80% of the answers online are useless because they were written before Android locked down the shared storage directories in 2019. I don't see any simpler solution than to follow this example. Some notes:
|
That's at least a reasonable explanation... it's still annoying, though.
I've broadly followed this approach; with one notable deviation - I've used the cache dir, not the files dir. My reasoning is that the file itself should be a transient artefact - ideally it wouldn't hit the disk at all. If you do want to save the file as a permanent artefact, you can This also means we can create a general purpose "shared" file provider that any intent could use for cross-app communication. Based on what I understand of file providers, we might need to add additional path registrations (or add a briefcase customisation) to allow for sharing of regular files or external files; but I think we can cross that bridge when get get to it. |
aa8db91
to
61382e0
Compare
Implements the Camera API on Android.
Requires the use of beeware/briefcase#1610 and beeware/briefcase-android-gradle-template#83, because an updated version of AppCompat. This is imported indirectly by the Material libraries. It also requires callback hooks for resolving permission requests, and a FileProvider declaration.
As this uses an intent to launch the camera, it includes tests of invoking and getting results from an intent. As part of the PR, I've deprecated the
intent_result
method, on the basis that the API it exposes matches what I'd expect of a public API, rather than one that is useful internally to satisfy the needs of a public API. This new API is both documented and tested. Fixes #1798There's one notable discrepancy with iOS/macOS cameras. Android doesn't appear to have an "unknown/unasked" state for permissions, so we can't differentiate between "You've never asked for permissions" and "You've denied permission" - they're both "no permission". There's a lot of discussion about the
shouldShowPermissionRequestRationale
method - however, this only appears to allow you to differentiate between a permission that was denied once, and a permission that was denied permanently.PR Checklist: