This is a kivy example app which demonstrate how to use
plyer.camera.take_picture
on Android API versions >= 24.
Starting with that version, you need to use a FileProvider in order to save
a picture taken with the ACTION_IMAGE_CAPTURE
intent.
If you target Android API 24 (or higher) and use plyer<=2.0.0
, when you call
plyer.camera.take_picture
you get an error like this:
jnius.jnius.JavaException:` JVM exception occurred: file://foo.jpg exposed beyond app through `ClipData.Item.getUri()
See also Plyer issue #500.
At the moment of writing, the required functionalities are not present in the
master versions of plyer
, p4a
and buildozer
, so you need a
fork of all of those.
-
plyer
branch antocuni/android-24-camera, see also PR #649. This is also the plyer version which is vendored in this repository. -
p4a
branch fileprovider-rebased, see also PR #1922. -
buildozer
branch antocuni/p4a-extra-args, see also PR #1369.
The key points are:
-
in
buildozer.spec
:p4a.extra_args = --fileprovider-paths=/github/workspace/src/file_paths.xml
: this is needed to add a FileProvider inAndroidManifest.xml
-
in
main.py
, the following lines instructplyer
to use the correct FileProvider authority to save the image:
self.package_name = Context.getPackageName()
assert plyer.camera.FILEPROVIDER_AUTHORITY is None
plyer.camera.FILEPROVIDER_AUTHORITY = f'{self.package_name}.fileprovider'
See also .github/workflow/buildozer.yml
for the full configuration needed to build the APK with the buildozer action
Before taking pic | After taking pic |
---|---|