問題描述
我正在嘗試讓一個標準的 Android 應用程序執行一個可以將值返回給 Java 的 python 腳本,但我面臨很多問題.
I'm trying to make an standard Android application execute a python script that could return values to Java, but I'm facing a lot of issues.
Jython 在 Android 環境中不支持此功能,SL4A 是一個死項目,Kivi 似乎是一個完全不使用 Java 的全棧框架,而 QPython 是適用于 Android 5+ 但幾乎沒有文檔的 SL4A.
Jython doesnt support this in the Android environment, SL4A is a dead project, Kivi seems to be an full stack framework that do not use Java at all and QPython is SL4A that works on Android 5+ but almost don't have documentation.
我想要類似的東西:
// From INSIDE my Java Code
new PythonEngine().execute('a = 1 + 1').getInt('a')
使用 QPython,我找到了一個執行任意代碼的示例,但我不知道如何在不打開等待用戶輸入返回的新活動的情況下獲得結果以及如何運行腳本.
With QPython I found an example that executes an arbitrary code, but I couldn't figure how to get the outcome and how to run the script without opening a new activity that waits for user input to come back.
這可能嗎?該示例可以在這里找到 QPython Java 示例
Is that possible? The example can be found here QPython Java Sample
推薦答案
我認為這些項目中的任何一個都沒有幫助.例如,Kivy 驅動 Python 執行,即使它是從 Java 啟動的.
I don't think any of thoses projects will help. For example, Kivy drive the Python execution, even it it's started from Java.
如果您有 Java 應用程序,但想啟動 Python 解釋器,我想使用 https://code.google.com/p/android-python27/ 可能是一個開始.不確定他們是否在 Python C-API 之上有 Java 接口.
If you have an application in Java, but want to start a Python Interpreter, i guess solution using https://code.google.com/p/android-python27/ might be a start. Unsure if they have a Java interface in top of the Python C-API.
這篇關于如何在 Android 中從 Java 代碼執行 Python 腳本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!