sofdigital / DroidPython

Python app development with SL4A in Android Studio
MIT License
55 stars 17 forks source link

Passing parameters to a Python script #4

Closed confuste closed 8 years ago

confuste commented 8 years ago

Hello. How can I pass arguments to my python script?

The original script must be run as follows (3 arguments): $ python main.py --inject video_input.mp4 video_output.mp4

(Specifically I'm trying to use this script: https://github.com/google/spatial-media ).

Thank you.

michaelrinderle commented 8 years ago

Hi confuste,

Although I have never tried passing variables to the script, you can try two different approaches.

  1. Add parameters to the config setting for the script.

public static final String PYTHON_MAIN_SCRIPT_NAME = "hello.py";

DROID_PYTHON/apk-2.7/app/src/main/java/com/android/python27/config/GlobalConstants.java

  1. Add the parameters to the arguments array list or environment variables in scriptservice.java .

DROID_PYTHON/apk-2.7/app/src/main/java/com/android/python27/ScriptService.java

Let me know if you get it working and what approach for others. ill add it to the wiki.

confuste commented 8 years ago

Hello again

The first way can't work because with the "PYTHON_MAIN_SCRIPT_NAME" your project must generate the file with File java class but...

The second way works fine!

I have add the parameters in BackGroundScriptService.java (no ScriptService.java)

DROID_PYTHON/apk-2.7/app/src/main/java/com/android/python27/BackGroundScriptService.java

This is the code:

/* arguments List */
ArrayList<String> args = new ArrayList<>();
args.add(scriptName);
//I deleted this argument
//args.add("--foreground"); 

//I added three arguments more
args.add("--argument1");
args.add("input_file");
args.add("output_file");

Thank you very much ainsophical : )

michaelrinderle commented 8 years ago

right on! no problem. i'll add that into the wiki when i get a chance.