-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.py
60 lines (47 loc) · 1.9 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
__version__ = '0.1'
from kivy.app import App
from jnius import autoclass, cast
from PIL import Image
from android import activity, mActivity
from android.permissions import request_permissions, Permission
from android.storage import primary_external_storage_path
request_permissions([Permission.CAMERA, Permission.READ_EXTERNAL_STORAGE])
from kivy.logger import Logger
from kivy.config import Config
Config.set('kivy', 'log_level', 'debug')
Config.set('kivy', 'log_dir', 'logs')
Config.set('kivy', 'log_name', 'kivy_%y-%m-%d_%_.txt')
Config.set('kivy', 'log_enable', 1)
Config.write()
Logger.debug("DEBUG: primary_external_storage_path")
Logger.debug("DEBUG: %s", primary_external_storage_path())
Intent = autoclass('android.content.Intent')
MediaStore = autoclass('android.provider.MediaStore')
Environment = autoclass('android.os.Environment')
Context = autoclass("android.content.Context")
FileProvider = autoclass('android.support.v4.content.FileProvider')
PythonActivity = autoclass("org.kivy.android.PythonActivity").mActivity
class TakePictureApp(App):
def take_picture(self):
def create_img_file():
File = autoclass('java.io.File')
storageDir = Context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
imageFile = File(
storageDir,
"temp.jpg"
)
imageFile.createNewFile()
return imageFile
intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
photoFile = create_img_file()
photoUri = FileProvider.getUriForFile(
Context.getApplicationContext(),
"org.test.takepicture.fileprovider",
photoFile
)
parcelable = cast('android.os.Parcelable', photoUri)
intent.putExtra(MediaStore.EXTRA_OUTPUT, parcelable)
mActivity.startActivityForResult(intent, 0x123)
def on_pause(self):
return True
TakePictureApp().run()