Search code examples
androidpythonwshsl4a

How to open a script in sl4a script editor, programmatically from another script?


I'm new to Android python scripting with SL4A, but familliar with python. the question I have is, How to open a script in sl4a script editor, programmatically from another script? my english is not goodenough to explain my problem, so I show it with a pseudo code:

It would be really appreciated if someone give me a hint or do help me figure it out. thanks in advance :)

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

Solution

  • I don't know if you still need to know this, but the following will do what you want it to do:

    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)