How to pass a variable to "SL4A"?

Post your questions and help other users.

Moderator: Martin

Post Reply
Hayabusa
Posts: 2
Joined: 28 Jun 2013 00:39

How to pass a variable to "SL4A"?

Post by Hayabusa » 28 Jun 2013 01:01

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

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

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

Post by Martin » 28 Jun 2013 17:24

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

Hayabusa
Posts: 2
Joined: 28 Jun 2013 00:39

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

Post by Hayabusa » 29 Jun 2013 12:30

Thanks for the quick support Martin.

Worked perfectly thanks ! :D :D :D

Post Reply