From Jnius import autoclass
>>> stack = autoclass (' java.util.Stack ')
>>> stack = stack ()
>>> stack.push (' hello ')
>>> Stack.push (' World ')
>>> stack.pop ()
' World '
>>> stack.pop ()
' Hello '
In the code above, we use the Autoclass function to create a type agent that corresponds to all the methods and field properties of the Java.util.Stack class in Java.
OK, maybe you want an android-related example, look here:
From Jnius import Autoclass from time
import sleep
mediarecorder = Autoclass (' Android.media.MediaRecorder ')
Audiosource = Autoclass (' Android.media.mediarecorder$audiosource ')
OutputFormat = Autoclass (' Android.media.mediarecorder$outputformat ')
Audioencoder = Autoclass (' Android.media.mediarecorder$audioencoder ') # Record of the
microphone with a 3GP recorder
Mrecorder = Mediarecorder ()
mrecorder.setaudiosource (audiosource.mic)
Mrecorder.setoutputformat (OutputFormat.THREE _GPP)
mrecorder.setoutputfile ('/sdcard/testrecorder.3gp ')
Mrecorder.setaudioencoder (AudioEncoder.ARM _NB)
Mrecorder.prepare ()
# record 5 Seconds
Mrecorder.start () Sleep
(5)
mrecorder.stop ()
Mrecorder.release ()
Well, you can get more examples from the documentation.
We can already map the types of Java/python, native arrays, support method overloads, and so on. We are using Cython + JNI internally, so the consumption performance is minimal.
Also, the Python for Android library is complete and you can get it from GitHub.