Skip to content

Instantly share code, notes, and snippets.

Last active October 10, 2020 05:59
Show Gist options
  • Save tito/6118172 to your computer and use it in GitHub Desktop.
Save tito/6118172 to your computer and use it in GitHub Desktop.
Python-for-android / Pyjnius - test live-creation of native android widget.
Use with Kivy Remote Shell:
cat | ssh -p8000 -t -t admin@192.168.x.x
from jnius import autoclass, cast
from android.runnable import Runnable
activity = autoclass('').mActivity
AnalogClock = autoclass('android.widget.AnalogClock')
WebView = autoclass('android.webkit.WebView')
LinearLayout = autoclass('android.widget.LinearLayout')
LayoutParams = autoclass('android.view.ViewGroup$LayoutParams')
global clock
def create_clock():
# works
global clock
clock = AnalogClock(activity)
activity.addContentView(clock, LayoutParams(-1, -1))
def remove_clock():
global clock
cast(LinearLayout, clock.getParent()).removeView(clock)
def create_webview():
# works
webview = WebView(activity)
webview.loadData('<html><body>Hello<b>World</b></body></html>', 'text/html',
def create_clock2():
# failed, sdlview?
layout = LinearLayout(activity)
clock = AnalogClock(activity)
def sdl_view():
# failed, "Invalid indirect reference..."
def run(f, *args, **kwargs):
# args/kwargs to runnable was a bug, fixed in master
Runnable(f)(args, kwargs)
Copy link

hello, first sorry for my bad english.

I need help, when I run cat | ssh -p8000 -t -t admin@192.168.50.x, python say :
" Traceback (most recent call last):
File "", line 1, in
File "", line 3, in run
File "/home/....../Android/kivy/kivy-remote-shell-master/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/android/", line 29, in call
AttributeError: 'NoneType' object has no attribute 'runOnUiThread' "

can you help me please??


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment