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 above code, we use the Autoclass function to create a type proxy 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 autoclassfrom time import sleep Mediarecorder = Autoclass (' android.media.MediaRecorder ') Audiosource = a Utoclass (' Android.media.mediarecorder$audiosource ') OutputFormat = Autoclass (' android.media.mediarecorder$ OutputFormat ') Audioencoder = Autoclass (' Android.media.mediarecorder$audioencoder ') # Record the microphone with a 3GP Recordermrecorder = Mediarecorder () mrecorder.setaudiosource (audiosource.mic) Mrecorder.setoutputformat ( OUTPUTFORMAT.THREE_GPP) mrecorder.setoutputfile ('/sdcard/testrecorder.3gp ') Mrecorder.setaudioencoder ( AUDIOENCODER.ARM_NB) Mrecorder.prepare () # Record 5 Secondsmrecorder.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 use Cython + JNI internally, so the consumption performance is minimal.
Meanwhile, the Python for Android Library has been completed and you can get it from GitHub.