Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute Python script from Android app in Java?

I am trying to find a way to execute a Python script from my Java code in Android. I did a research on this matter but the only thing I found is, how I can convert python scripts in APK for android (Kivy e.t.c.).

More specifically I have a script which contains a lot of functions.What i want to do is to create an object based on this python script inside my java code and via this object to call my functions.

I can't convert my Python code into Java, because I use various libraries that exists only in python.

Any advice would be helpful and deeply appreciated.


The following a snippet of my Python script. I use the library charm for cryptography.

from charm.core.math.integer import integer,serialize,deserialize
class serializeClass:
    def __init__(self)
        ...

    def serialize(self, charm_object):
        assert type(charm_object) == integer, "required type is integer, not: ", type(charm_object)
        return serialize(charm_object)

    def deserialize(self, object):
        assert type(object) == bytes, "required type is bytes, not: ", type(object)
    return deserialize(object)
like image 444
PL13 Avatar asked Dec 12 '15 03:12

PL13


People also ask

Can you run Python scripts in an Android app?

Python can run on Android through various apps from the play store library. This tutorial will explain how to run python on Android using Pydroid 3 – IDE for Python 3 application. Features : Offline Python 3.7 interpreter: no Internet is required to run Python programs.

Can we use Python with Java in Android Studio?

My answer to this question is a Yes. You can definitely develop an Android app using Python. And this thing is not only limited to python, you can in fact develop Android applications in many more languages other than Java.

How do I open a .PY file on Android?

If you want to run Python on mobile, one of the easiest options is simply to download an IDE on your chosen platform. There is no need to download a separate interpreter, you can simply download the app and start typing and running your Python code.

Can Android run Python games?

Can We Build Android Mobile Game Using Python? YES! You can build the Android App using Python.


1 Answers

You can use SL4A project which would allow you run your Python code on Android.

  • Github: https://github.com/damonkohler/sl4a
  • Tutorials: https://github.com/damonkohler/sl4a/blob/wiki/Tutorials.md
like image 84
masnun Avatar answered Oct 15 '22 23:10

masnun