Skip to content

Instantly share code, notes, and snippets.

@kived
Created July 6, 2015 21:40
Show Gist options
  • Save kived/9e37002da7994329fb10 to your computer and use it in GitHub Desktop.
Save kived/9e37002da7994329fb10 to your computer and use it in GitHub Desktop.
Kivy: Flash example fixed
from kivy.app import App
from kivy.uix.switch import Switch
from jnius import autoclass
Camera = autoclass('android.hardware.Camera')
Parameters = autoclass('android.hardware.Camera$Parameters')
__version__ = '0.1'
class FlashApp(App):
def build(self):
self.root = Switch(text='enlightenme')
self.root.bind(active=self.toggle_flash)
self.camera = None
return self.root
def toggle_flash(self, *args):
if self.camera == None:
self.camera = Camera.open()
p = self.camera.getParameters()
if self.root.active:
p.setFlashMode(Parameters.FLASH_MODE_TORCH)
self.camera.setParameters(p)
self.camera.startPreview()
else:
p.setFlashMode(Parameters.FLASH_MODE_OFF)
self.camera.stopPreview()
self.camera.setParameters(p)
self.camera.release()
self.camera = None
if __name__ == '__main__':
FlashApp().run()
@HakHanKoh
Copy link

HakHanKoh commented Jan 15, 2017

OMG THANK YOU SO MUCH. I new to Kivy and Pyjnius and i've been trying to access flash for the whole day and none of the code works. I can't tell you how happy i'm to found this code. THANK YOU!

@block0xhash
Copy link

thanks for this

@ahmedfgad
Copy link

Thanks too much 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment