2012-03-01 91 views
2

我是新來的Android的Python腳本與SL4A,但familliar與Python。 我的問題是,如何在sl4a腳本編輯器中以編程方式從另一個腳本中打開腳本?我的英語不是簡單的解釋我的問題,所以我用一個僞代碼來展示它:如何在sl4a腳本編輯器中以編程方式從另一個腳本打開腳本?

如果有人給我一個提示或者幫我弄清楚,那將是非常感謝。 在此先感謝:)

from android import Android 
droid = Android() 

f = open("newScript.py", 'w') 
f.write("bla bla bla") 
f.close() 
#now here is what I want it to do: 
myintent = droid.makeIntent(WHAT, VARIABLES, SHOULD, I , USE, TO OPEN newScript.py?) 
#myintent should run the sl4a SCRIPT EDITOR 
droid.startActivityIntent(myintent) ` 

回答

2

我不知道你是否還需要知道這一點,但下面會做你想要它做的事情:

import android 

droid = android.Android() 

action = 'com.googlecode.android_scripting.action.EDIT_SCRIPT' 
extras = {'com.googlecode.android_scripting.extra.SCRIPT_PATH':'/any/path/you/like.py'} 

intent = droid.makeIntent(action, None, None, extras).result 

droid.startActivityIntent(intent) 
+0

謝謝!是的,這是正確的解決方案。 – Rebel 2016-08-30 00:13:30