简体   繁体   English

如何从MIT App Inventor Activity Starter启动QPython脚本并干净退出?

[英]How do I launch a QPython Script from MIT App Inventor Activity Starter and exit cleanly?

I have made a simple training app with MIT App Inventor 2. The app logs to a logfile, and I've made a small QPython script to analyze the log and display stats. 我使用MIT App Inventor 2开发了一个简单的培训应用程序。该应用程序记录到日志文件中,并且制作了一个小的QPython脚本来分析日志并显示统计信息。

I'd like to use the Activity Starter to launch my Python script, but I haven't been able to figure out the correct set of Action, ActivityClass, ActivityPackage and Extra[x] to make it work. 我想使用Activity Starter启动我的Python脚本,但是我无法找出正确的Action,ActivityClass,ActivityPackage和Extra [x]集合来使其正常工作。 I've run adb on my Android phone to find the correct strings but I get a "601 No corresponding activity was found" when I try. 我已经在Android手机上运行adb来找到正确的字符串,但是尝试时会收到“ 601未找到相应的活动”。

Here's the adb output grepped for "qpyplus" while running the script: 这是运行脚本时grepped为“ qpyplus”的adb输出:

I/Timeline( 1898): Timeline: Activity_launch_request id:com.hipipal.qpyplus time:15752330
I/ActivityManager(  862): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.hipipal.qpyplus/com.hipipal.qpylib.MPyApi bnds=[540,456][807,756] (has extras)} from uid 10116 on display 0
V/WindowManager(  862): addAppToken: AppWindowToken{1687ec32 token=Token{120bbc3d ActivityRecord{1ef9e994 u0 com.hipipal.qpyplus/com.hipipal.qpylib.MPyApi t5112}}} to stack=1 task=5112 at 0
V/WindowManager(  862): Adding window Window{e90d72c u0 Starting com.hipipal.qpyplus} at 18 of 26 (after Window{30168e12 u0 edu.mit.appinventor.aicompanion3/edu.mit.appinventor.aicompanion3.Screen1})
I/Timeline(31680): Timeline: Activity_launch_request id:com.hipipal.qpyplus time:15752447
I/ActivityManager(  862): START u0 {cmp=com.hipipal.qpyplus/jackpal.androidterm.Term (has extras)} from uid 10335 on display 0
V/WindowManager(  862): addAppToken: AppWindowToken{382fc5e2 token=Token{1e492ead ActivityRecord{2e34dfc4 u0 com.hipipal.qpyplus/jackpal.androidterm.Term t5112}}} to stack=1 task=5112 at 1
V/WindowManager(  862): Based on layer: Adding window Window{e90d72c u0 Starting com.hipipal.qpyplus} at 18 of 26
V/WindowManager(  862): Adding window Window{390e635c u0 com.hipipal.qpyplus/jackpal.androidterm.Term} at 18 of 27 (before Window{e90d72c u0 Starting com.hipipal.qpyplus})
I/ActivityManager(  862): Displayed com.hipipal.qpyplus/jackpal.androidterm.Term: +117ms (total +245ms)
I/Timeline(  862): Timeline: Activity_windows_visible id: ActivityRecord{2e34dfc4 u0 com.hipipal.qpyplus/jackpal.androidterm.Term t5112} time:15752597

I've read the docs and tried to decipher the logs and populate the tags. 我已经阅读了文档,并试图破译日志并填充标签。 I've also found an old answer from 2010 to the same sort of question, but it seems that QPython has moved on since then because the recipe doesn't correspond to my logcat (and also doesn't work). 我也找到了从2010年开始对同一问题的旧答案,但是自那以后,QPython似乎一直在发展,因为该食谱与我的logcat不符(并且也不起作用)。 Please see screenshot of both options (I'm a rookie here so I'm not allowed to embed images). 请查看两个选项的屏幕截图(我是新手,所以不允许嵌入图像)。

screenshot of two options that don't work 两个不起作用的选项的屏幕截图 在此处输入图片说明 Does anybody know how I should format the Activity Starter for this script to run? 有人知道我应该如何设置活动启动器的格式才能运行此脚本?

Update! 更新!
Taifun has put me on the right track, I think. 我认为Taifun使我走上了正确的道路。 I've followed his advice and re-compiled the .apk with new permissions and installed it so that it will be allowed to run a shell script. 我遵循了他的建议,并使用新权限重新编译了.apk并进行了安装,以便可以运行Shell脚本。 My problem now is that QPython seems to completely ignore my asking it to run a script on startup. 我现在的问题是QPython似乎完全忽略了我要求它在启动时运行脚本的问题。 The terminal opens okay, but my script doesn't run. 终端可以打开,但是我的脚本无法运行。 If I run the command manually, it runs just fine. 如果我手动运行该命令,它将运行正常。

Any thoughts? 有什么想法吗?

My new config that almost works. 我的新配置几乎可以正常工作。

http://i.hizliresim.com/mLqgP4.png http://i.hizliresim.com/mLqgP4.png

action="com.hipipal.qpyplus.action.MPyApi"
classname="com.hipipal.qpyplus.MPyApi"
packagename="com.hipipal.qpyplus"
extras={"app" : "appid", "act" : "onPyApi", "flag" : "onQPyExec", "param" : "", "pycode" : "print 'selam'\nprint 'naber'"}

This is working fine :) 这工作正常:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM