Android (FireTV) Running Shell with Python? Help!
#1
Hey everyone!

So, I just recently got a FireTV Stick and have been experimenting with the way I can interact with one Android App with Kodi (RC2).

I am aware of the builtin function StartAndroidActivity(package,[intent,dataType,dataURI], but it doesn't seem to support extra parameters, so I built a .sh script to call it and it works when launched from adb command line.

/sdcard/test.sh
Code:
#!/system/bin/sh
am start -a "appxpto.intent.action.OPEN" -c "android.intent.category.DEFAULT" -e "extrapar" "extravalue"

I took the "Hello World!" addon, and modified it to see if I could make it launch the script, and this is where I'm stuck.
Code:
import sys
import xbmcaddon
import xbmcgui
import os

bashCommand = "/system/bin/sh /sdcard/test.sh"
os.system(bashCommand)

Also tried without sucess:
Code:
import sys
import xbmcaddon
import xbmcgui
import os

bashCommand = "/system/bin/sh /sdcard/test.sh"
subprocess.call(bashCommand, shell=True)

The code doesn't throw any errors, but the .sh script doesn't run either. Maybe it's because the file is not executable? I can't "chmod +x" the file because I don't have root privileges, so I don't know what other solution I have here. It does run from adb however.

I've also had a look at the python android module, but it doesn't seem to be available, and i'm not sure if it's possible to "import it" somehow?
This is what it would look like:
Code:
import sys
import xbmcaddon
import xbmcgui
import os
import android

droid = android.Android()
droid.startActivity('appxpto.intent.action.OPEN',
                    None,
                    None,
                    {"extrapar":"extravalue"},
                    False,
                    'com.appxpto.appxpto',
                    'android.intent.category.DEFAULT'
                   )

Also thought about doing a PHP script instead, but I can't seem to run a PHP Server on the FireTV either...
Any help would be appreciated Smile
Reply
#2
I don't get what you are trying to do, but you cannot load xbmc modules from _outside_ of kodi.
Reply
#3
(2015-07-19, 11:32)wsnipex Wrote: I don't get what you are trying to do, but you cannot load xbmc modules from _outside_ of kodi.

I wasn't running it outside of Kodi.
"I took the "Hello World!" addon, and modified it to see if I could make it launch the script, and this is where I'm stuck."

I'm trying (with a Kodi addon) to launch a Shell Script on the FireTV.
Reply
#4
Actually startandroidactivity receives arguments. Here's how I'm lauching sopcast player from a python addon. sop variable is a url 'sop://blablabla':

https://github.com/enen92/P2P-Streams-Ko...ast.py#L70

Same for aceplayer:

https://github.com/enen92/P2P-Streams-Ko...eam.py#L61
Reply
#5
IIRC android doesn't allow executeables on /sdcard, but I didn't test that.
enen92's method is the way to go for starting activities.
Reply
#6
Thanks both for your answers. I am aware of the StartAndroidActivity, however, I don't think it accepts "extra" parameters, unless it's undocumented as I couldn't find an example anywhere.

Extra parameters, afaik, cannot be passed on as dataURI.
Using Android Activity Manager, the former would be passed on with "-e", while dataURI uses -d.

Unfortunately, I don't think it's suited for this situation because the App is expecting to receive extra parameters.
It would be of course better to use a native function from Kodi, hence why I was am trying (and failing) to get my way around it using the script as a middleman.

Code:
start an Activity: am start [-D] [-W] <INTENT>
    -D: enable debugging
    -W: wait for launch to complete
(...)
<INTENT> specifications include these flags:
    [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
    [-c <CATEGORY> [-c <CATEGORY>] ...]
    [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
(...)
Reply
#7
did you try calling am start.. directly from python, without the shell script in between?
Reply
#8
I did, but now that I think of it, I might not have used the full path to am, which might be necessary? Undecided

I'll try again this evening!
Reply
#9
Hum, that did not solve it after all.

Code:
import sys
import xbmcaddon
import xbmcgui
import urlparse
import os

addon       = xbmcaddon.Addon()
addonname   = addon.getAddonInfo('name')

line1 = "Hello World!"
line2 = "We can write anything we want here"
line3 = "Using Python"

os.system('/system/bin/am start -a "appxpto.intent.action.OPEN" -c "android.intent.category.DEFAULT" -e "extrapar" "extravalue"')

Also tried the "/system/bin/sh /sdcard/test.sh" command again, this time adding /system/bin/am at the start of the shell script.
No error whatsoever (on screen or .log file) with any of the two tries, it's just that nothing happens while running the Addon.

However, doing this:
Code:
bashCommand = '/system/bin/am start -a "appxpto.intent.action.OPEN" -c "android.intent.category.DEFAULT" -e "extrapar" "extravalue"'
xbmc.executebuiltin('System.Exec(bashCommand)')
or this
Code:
bashCommand = '/system/bin/sh /sdcard/test.sh;'
xbmc.executebuiltin('System.Exec(bashCommand)')

completely leaves Kodi/FireTV non responsive or in a very messy state. And if I close and open it again, CPUs are maxed out at 100%... Weird!
Image
Image
Reply
#10
Its been my experience with Kodi and Android that the standard SU app for root permissions SUCKS!...Trying installing SUPERSU its free installs over SU and fixes permissions errors Kodi likes to kick out with just plain SU.....example... os.system('su -c reboot') no go with SU command works great with SUPERSU
Reply
#11
Hello,

I found this thread while trying to troubleshoot my addon. I'd like to add a command to start an android app from my addon. Currently, I'm trying to use os.system() in python, but that doesn't appear to be consistently working depending on what android box people have (and maybe their root permissions?)

At any rate, my goal is to launch retroarch from my addon, according to the documentation for retroarch, there are several 'intents' I need to include to launch the game.

As an example, this works for some people:
Code:
os.system('/system/bin/am start --user 0 -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -e ROM "%ROM_PATH%" -e LIBRETRO /data/data/com.retroarch/cores/4do_libretro_android.so -e CONFIGFILE %CFG_PATH% -e IME com.android.inputmethod.latin/.LatinIME -n com.retroarch/.browser.retroactivity.RetroActivityFuture')

but not for all. Is there a method to include -e intents with StartAndroidActivity?
Reply

Logout Mark Read Team Forum Stats Members Help
(FireTV) Running Shell with Python? Help!0