在 Android 上使用 SL4A 将参数传递给 python 脚本

发布于 2024-11-27 05:45:53 字数 308 浏览 4 评论 0原文

我正在尝试让我通常在 PC 上运行的 Python 脚本在我的 Android 手机(HTC Hero)上运行。我的手机上运行着 SL4A,并对 Python 脚本进行了一些调整,以便现在可以运行。我遇到的问题是如何将参数传递给脚本。我尝试在 SL4A 中创建一个 sh 脚本,该脚本使用参数调用 python 文件,但这不起作用。我还尝试使用应用程序 TaskBomb 调用 python 文件,但在提供参数时这又不起作用。当没有提供参数时,文件会正确加载,但是当我将 -h 添加到文件名时,它说它无法再找到我正在调用的 python 文件。

有人能够提供有关如何做到这一点的帮助吗?

I am trying to get a Python script which I normally run on my PC to run on my Android phone (HTC Hero). I have SL4A running on my phone and have made a few tweaks to the Python script so that this does now run. The problem that I am having is how to pass parameters to the script. I have tried creating a sh script in SL4A which called the python file with the parameters, but this didn't work. I have also tried using the app TaskBomb to call through to the python file, but again this doesn't work when parameters are supplied. When no params are supplied the file loads correctly, but when I add -h to the filename it says it can no longer find the python file I am calling.

Is anybody able to provide assistance with how to this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱冒险 2024-12-04 05:45:53

我建议修改脚本以调用 getDialogInput。

import android
app = android.Android()
response = app.dialogGetInput(Title, Message, Default_Values).result

然后设置脚本期望参数包含在响应中的任何变量。

我已经完成了这个,并且还修改了一个脚本来获取 android 剪贴板,而不是直接获取输入。您始终可以使用硬编码参数制作脚本的多个版本。

希望这会有所帮助,因为我对 python 和 sl4a 还很陌生。

I would suggest modifying the script to call getDialogInput.

import android
app = android.Android()
response = app.dialogGetInput(Title, Message, Default_Values).result

Then set whatever variable the script expects the parameters to be in to response.

Ive done this and also modified a script to get the android clipboard instead of taking input directly. You could always make several versions of the script with hard coded parameters.

Hope this helps as im pretty new to python and sl4a.

三岁铭 2024-12-04 05:45:53

我用了一个迂回的方法来规避这个问题。首先,需要修改 python 脚本以查找包含属性的文本文件。现在,每当我需要启动脚本时,我都必须推送包含属性的 txt 文件,然后启动脚本。

I used a round about method to circumvent the problem. First the python script needs to be modified to look for a text file containing the attributes. Now whenever I need to start the script, i have to push the txt file containing the attributes and then start the script.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文