I can not take a picture android kivy.uix.camera

1,085 views
Skip to first unread message

Максим Шепард

unread,
Apr 6, 2019, 8:57:55 AM4/6/19
to Kivy users support
Good afternoon, I am trying to write an application that would take a photo and upload it for further editing. The camera starts up, but when you click "Take photo", nothing happens, the photo is not stored in the phone's memory. Who knows what the problem is or something is missing in the code? 
Attached buildozer.spec
import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
import time

Builder.load_string("""
<ScreenOne@Screen>:
 BoxLayout:
 Button:
 text: "
Open camera"
 color: 1,200,1,1
 font_size: 25
 on_press:
 root.manager.transition.direction = 'right'
 root.manager.transition.duration = 1
 root.manager.current = 'screen_two'
 Button:
 text: "
asd"
 color: 1,1,200,1
 font_size: 25
 on_press:
 root.manager.transition.direction = 'left'
 root.manager.transition.duration = 1

<ScreenTwo@Screen>:
 Camera:
 id: camera
 resolution: (640, 480)
 play: True
 Button:
 text: 'Take photo'
 size_hint_y: None
 height: '48dp'
 on_press: root.capture()
"""
)


class ScreenOne(Screen):
 
pass


class ScreenTwo(Screen):
 
def capture(self):
 camera
= self.ids['camera']
 timestr
= time.strftime("%Y%m%d_%H%M%S")
 camera
.export_to_png("IMG_{}.png".format(timestr))
 
print("Take photo")


screen_manager
= ScreenManager()


screen_manager
.add_widget(ScreenOne(name="screen_one"))
screen_manager
.add_widget(ScreenTwo(name="screen_two"))


class Interface(App):

 
def build(self):
 
return screen_manager



android_app
= Interface()
android_app
.run()


buildozer.spec

Максим Шепард

unread,
Apr 8, 2019, 7:02:52 AM4/8/19
to Kivy users support
The question is still relevant, please help

суббота, 6 апреля 2019 г., 15:57:55 UTC+3 пользователь Максим Шепард написал:

alessandro bonvicini

unread,
Apr 8, 2019, 12:20:38 PM4/8/19
to Kivy users support
Hi , some month ago i did a little app on andrid that read and preview the camera and then show the content on an image widget
After some time i tried to recompile the app and nothing work anymore...the camera in not instanciated where before it was....alway "none"
I am investigating but probably this weird behavior ha something to do with a new kind of permission model....i do not know

I hope that someone very strong on this can  make a check e make things work again

alessandro bonvicini

unread,
Apr 13, 2019, 5:13:38 AM4/13/19
to Kivy users support

Hi give a read here
this snippet wokrs for me.. Exactly as i said befero the is something with  the permissions granted that work now in a different way respect to the past.
Hope this help

Alec van Niekerk

unread,
Aug 23, 2019, 10:40:44 AM8/23/19
to Kivy users support
I got a working example of the Android camera on Kivy here:

https://github.com/alecvn/kivy-android-camera

Fabrício Melo

unread,
Jun 21, 2020, 3:45:22 PM6/21/20
to Kivy users support

Abhishek Das

unread,
Dec 19, 2020, 2:13:09 AM12/19/20
to Kivy users support
@Fabrício Melo

Can you please give me an working example of xcamera in the kivy code?
Message has been deleted

Abhishek Das

unread,
Dec 19, 2020, 6:11:52 AM12/19/20
to Kivy users support
@Fabrício Melo
Hi
I have successfully run xcamera in my main.py However when I am building it for android it crashes
My buildozer spec snippet is as follows:

[app]

# (str) Title of your application
title = My Application

# (str) Package name
package.name = myapp

# (str) Package domain (needed for android/ios packaging)
package.domain = org.test

# (str) Source code where the main.py live
source.dir = .

# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas,csv

# (list) List of inclusions using pattern matching
#source.include_patterns = assets/*,images/*.png

# (list) Source files to exclude (let empty to not exclude anything)
#source.exclude_exts = spec

# (list) List of directory to exclude (let empty to not exclude anything)
#source.exclude_dirs = tests, bin

# (list) List of exclusions using pattern matching
#source.exclude_patterns = license,images/*/*.jpg

# (str) Application versioning (method 1)
version = 0.1

# (str) Application versioning (method 2)
# version.regex = __version__ = ['"](.*)['"]
# version.filename = %(source.dir)s/main.py

# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3,kivy,kivymd,android,xcamera==2020.0613
# (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes
# requirements.source.kivy = ../../kivy

# (list) Garden requirements
garden_requirements = xcamera

# (str) Presplash of the application
#presplash.filename = %(source.dir)s/data/presplash.png

# (str) Icon of the application
#icon.filename = %(source.dir)s/data/icon.png

# (str) Supported orientation (one of landscape, sensorLandscape, portrait or all)
orientation = portrait

# (list) List of service to declare
#services = NAME:ENTRYPOINT_TO_PY,NAME2:ENTRYPOINT2_TO_PY

#
# OSX Specific
#

#
# author = © Copyright Info

# change the major version of python used by the app
osx.python_version = 3

# Kivy version to use
osx.kivy_version = 2.0.0

#
# Android specific
#

# (bool) Indicate if the application should be fullscreen or not
fullscreen = 0

# (string) Presplash background color (for new android toolchain)
# Supported formats are: #RRGGBB #AARRGGBB or one of the following names:
# red, blue, green, black, white, gray, cyan, magenta, yellow, lightgray,
# darkgray, grey, lightgrey, darkgrey, aqua, fuchsia, lime, maroon, navy,
# olive, purple, silver, teal.
#android.presplash_color = #FFFFFF

# (list) Permissions
android.permissions = INTERNET,CAMERA

# (int) Target Android API, should be as high as possible.
android.api = 28

# (int) Minimum API your APK will support.
android.minapi = 21

# (int) Android SDK version to use
#android.sdk = 20

# (str) Android NDK version to use
#android.ndk = 19b

# (int) Android NDK API to use. This is the minimum API your app will support, it should usually match android.minapi.
#android.ndk_api = 21

Can you please guide me where I am wrong?

planckp...@gmail.com

unread,
Dec 19, 2020, 11:24:12 AM12/19/20
to Kivy users support
Use the debugger, look at the logcat for the cause of the crash.
The cause is usually after the word "Traceback", where you will see a Python stack trace, the last line is usually the most important.

Vijay Raut

unread,
Feb 21, 2021, 5:53:31 AM2/21/21
to Kivy users support
I was also facing the same issue, camera example worked on linux/windows but the app crashed on Android phone.
After giving the Android permissions as mentioned here( https://github.com/AndreMiras/PyWallet/issues/129 ) the app worked on Android phone.

Reply all
Reply to author
Forward
0 new messages