如何在 Android 中从 Java 代码执行 Python 脚本 [英] How to execute Python script from Java code in Android

查看:37
本文介绍了如何在 Android 中从 Java 代码执行 Python 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让一个标准的 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 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆