8

Is there any project that bridges Python and Dalvik in same address space?

That is an object created in one language can be registered as a listener in the other and vice versa?

--

Python could be CPython or PyPy;

Dalvik could be full Android Application Framework, or only Dalvik virtual machine, or in the worst case, could even be a non-Dalvik JVM;

Bridge could be written in Python/cffi, Python/jni, native C/C++ code, or even java.

Scripting environment, as far as I understand, doesn't do what I want.

In case of a total lack of Python--Dalvik bridge, I'll take full-featured C/C++-based C/C++--Dalvik bridge as a valid answer as a last resort. Then an example is required on instantiating a on object in C/C++ land that can be submitted as a valid listener to some Android API at runtime, including security considerations.

Alex Gaynor
  • 14,353
  • 9
  • 63
  • 113
Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120
  • "I'll take full-features C/C++-based C/C++--Dalvik bridge" like JNI? :) – JesusFreke Nov 18 '13 at 19:13
  • clarified, that's last resort. – Dima Tisnek Nov 19 '13 at 10:54
  • 1
    Are you aware of [pyjnius](https://github.com/kivy/pyjnius)? It is used by (for instance) the kivy python-for-android project to interact with java classes, including managing stuff like intent listening. I apologise if this is technically unsuitable, I don't know enough about this area. – inclement Nov 26 '13 at 21:58
  • @inclement I'll have a look! – Dima Tisnek Nov 27 '13 at 10:55
  • @inclement this is really good actually! uses `ctypes`, thus only works with CPython and won't work so efficiently with PyPy, but it's clearly a projected aimed in the right direction! Please convert into an answer. – Dima Tisnek Nov 27 '13 at 11:54

2 Answers2

4

(As per my original comment)

Are you aware of pyjnius? It is used by (for instance) the kivy python-for-android project to interact with java classes, including managing stuff like intent listening. I apologise if this is technically unsuitable, I don't know enough about this area.

As a minor reference, listener example implementing an intent listener interface in Python and registering it with Android runtime using pyjnius.

Super-simple example, calling into java.

>>> from jnius import autoclass
>>> autoclass('java.lang.System').out.println('Hello world')
Hello world
Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120
inclement
  • 29,124
  • 4
  • 48
  • 60
2

There is in fact a module called android in python. It can do quite a lot on an android system. You can download it here: https://pypi.python.org/pypi/python-android

There is also a python/java bridge that also supports Dalvik handling. Here is where you can get the software: https://bitbucket.org/reasonspace/reasonspace/src

Both of these should supply a good way to interface python and Android systems. If you wanted you could also probably get them both to read and write files to send messages or create some kind of similar way to communicate, but the above projects are better ways to do it.

trevorKirkby
  • 1,886
  • 20
  • 47
  • `python-android`'s linked github is pretty empty. what is actually implemented? There is code only in two files, `ota.py` and `boot.py`. What can this project actually do? – Dima Tisnek Nov 23 '13 at 15:43
  • `reasonspace` didn't have commits for 2 years; `jpype` on the other hand is apparently maintained. the latter allows to "implement" (sic.) a java interface, but doesn't support dalvik. – Dima Tisnek Nov 23 '13 at 15:55
  • I don't want to pass messages between the two. I want direct calls and callbacks, implementation f interfaces, etc. Well calls through the shim obviously. – Dima Tisnek Nov 27 '13 at 10:55