How to execute Python script from Java code on Android

I am trying to get a standard Android application to execute a python script that can return Java values, but I have a lot of problems.

Jython doesn't support this on Android, SL4A is a dead project, Kivi seems to be a complete stack structure that doesn't use Java at all, and QPython is SL4A that runs on Android 5+, but almost no documentation.

I wanted something like:

// From INSIDE my Java Code new PythonEngine().execute('a = 1 + 1').getInt('a') 

With QPython, I found an example that executes arbitrary code, but I could not figure out how to get the result and how to run the script without opening a new activity waiting for the user to return.

Is it possible? An example can be found here. QPython Java Sample

+5
source share
1 answer

I do not think any of these projects will help. For example, Kivy controls the execution of Python, even if it starts with Java.

If you have a Java application but want to run Python Interpreter, I think a solution using https://code.google.com/p/android-python27/ might be the start. Not sure if they have a Java interface at the top of the Python C-API.

+1
source

Source: https://habr.com/ru/post/1214904/


All Articles