I want to ask if it's possible to import only jnius from Kivy. I using Python for Android "qpython" distribution with Kivy compiled in it. Kivy also have pyjnius included. Now I try to use jnius without calling a Kivy app to call Java modules? Any idea to call kivy included modules without import Kivy itself or to usw Kivy only in terminal without calling a App or Window? Or some help to compile pyjnius for qpython directly? Thanks
Asked
Active
Viewed 1,676 times
2 Answers
0
Pyjnius is a separate module, it doesn't depend on Kivy. It does depend on getting a JNIEnv*
somehow, and pyjnius currently hardcodes doing so via an SDL function (although this may work even if SDL's eventloop isn't actually running).
I'm not sure what you're actually asking regarding how your app would be run (if it's within qpython, doesn't pyjnius work anyway?), but in general it's easy to modify it to get the pointer a different way (although you need some C code to manage it). This is the method used by python-for-android, which patches pyjnius to use an appropriate api.

inclement
- 29,124
- 4
- 48
- 60
-
If I simply try: `import jnius` I get: `Traceback (most recent call last): File "
", line 1, in – fteinz May 10 '16 at 13:35File "/QPython/QPython2-core/build/python-install/lib/python2.7/site-packages/jnius/__init__.py", line 13, in File "/QPython/QPython2-core/build/python-install/lib/python2.7/site-packages/jnius/reflect.py", line 9, in File "jnius_export_class.pxi", line 44, in jnius.jnius.MetaJavaClass.__new__ (jnius/jnius.c:13255) SystemError: NULL result without error in PyObject_Call >>>` -
I don't know what's wrong exactly, but maybe I'm wrong about it working without something else running. It does run fine without Kivy and SDL though, there's no major dependency there even if qpython has a problem. – inclement May 10 '16 at 13:44
0
That's a problem of qpython. You can use pyjnius only when you add this in front of your script:
#qpy:kivy
For example:
#-*-coding:utf8;-*-
#qpy:2
#qpy:kivy
from kivy.app import App
from kivy.uix.button import Button
from jnius import autoclass
MediaPlayer = autoclass('android.media.MediaPlayer')
player=MediaPlayer()
media="/storage/emulated/legacy/YOUR_MEDIA_FILE"
def reset_player():
if (player.isPlaying()):
player.stop()
player.reset()
def restart_player(_):
reset_player()
try:
player.setDataSource(media)
player.prepare()
player.start()
except:
player.reset()
class App(App):
def build(self):
return Button(text='Hello world!',on_release=restart_player)
if __name__=="__main__":
App().run()
Hope this help you!

Kirk
- 446
- 4
- 18