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

查看:854
本文介绍了如何在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.

有可能吗?可以在此处找到示例

Is that possible? The example can be found here QPython Java Sample

推荐答案

我认为这些项目都不会有帮助.例如,即使Kivy是从Java启动的,它也会驱动Python执行.

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天全站免登陆