Page 1 of 1

How to pass a variable to "SL4A"?

Posted: 28 Jun 2013 01:01
by Hayabusa
Hello,
Thank you for the nice application.

How to pass a variable to "SL4A"?
This code does not work.

Automagic Action

ACTION TYPE = Plugin (Experimental)
PLUGIN = SL4A

OVERRIDE SETTINGS
//putBoolean("com.googlecode.android_scripting.extra.EXTRA_LAUNCH_IN_BACKGROUND", true);
//putString("com.googlecode.android_scripting.extra.SCRIPT_PATH", "/mnt/sdcard/sl4a/scripts/test.py");
putString("TEST", "TEST Message!");



SL4A PythonScript (/mnt/sdcard/sl4a/scripts/test.py)

import sys
import android

droid = android.Android()

try:
teststr = droid.getIntent().result[u'extras'][u'TEST']
droid.makeToast(teststr)
except:
droid.makeToast('Error') <----- :!:
sys.exit(1)

----

Best Regards

Re: How to pass a variable to "SL4A"?

Posted: 28 Jun 2013 17:24
by Martin
Hi,

According to the source of the SL4A plugin, the plugin component receives the intent and builds a completely new intent to start the script containing only the path of the script and the background property, all other extras are discarded.
In this case you have to bypass the plugin component and start the script directly yourself using an action Start Activity in Automagic:

Action:
com.googlecode.android_scripting.action.LAUNCH_FOREGROUND_SCRIPT
or
com.googlecode.android_scripting.action.LAUNCH_BACKGROUND_SCRIPT

Explicit Component: checked

Package Name:
com.googlecode.android_scripting
Class Name:
com.googlecode.android_scripting.activity.ScriptingLayerServiceLauncher

Extras:

putString("com.googlecode.android_scripting.extra.SCRIPT_PATH", "/mnt/sdcard/sl4a/scripts/test.py");
putString("TEST", "TEST Message!");


Alternatively you could use the clipboard or a temporary file to pass data to your script.

Regards,
Martin

Re: How to pass a variable to "SL4A"?

Posted: 29 Jun 2013 12:30
by Hayabusa
Thanks for the quick support Martin.

Worked perfectly thanks ! :D :D :D