简体   繁体   中英

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.

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. 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.

Here's the adb output grepped for "qpyplus" while running the script:

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). 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. 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. My problem now is that QPython seems to completely ignore my asking it to run a script on startup. 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

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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