In Xamarin forms -> Android App, there is any way to call Python script?

Hi, I'm building an Xamarin Forms solution to create a mobile application, for now we are targeting Android, my boss ask me to include (package) an existing python code to be used by this mobile application, this python code do some specific treatments, basically the mobile application send command to python to execute some python scripts, and get the result from text file in local drive.
Since a few days, I'm trying lots of things without success.
I like to know if it's possible to Xamarin Forms (Adroid App) to call Python scripts?
Thank you!

Answers

  • amirvenusamirvenus USMember ✭✭✭

    The easiest solution would be to host the py script in a WebServer and access it by calling an API.

  • FayalKadriFayalKadri USMember ✭✭

    Thank you amirvenus for your response, this solution is already done, but for some business reasons we need to work in disconnected mode.

  • AllanJonesAllanJones Member ✭✭

    maybe a local webservice

  • Xami3Xami3 PKMember, University ✭✭✭

    @FayalKadri search if you can run python from native java code on android then you can also run it in xamarin forms (using Dependency service )

  • FayalKadriFayalKadri USMember ✭✭

    @Xami3 Thanks for your response I will try this approach

  • maria_nabilmaria_nabil Member

    @amirvenus how to host the py script in a WebServer and access it by calling an API please ?

  • amirvenusamirvenus USMember ✭✭✭

    @maria_nabil said:
    @amirvenus how to host the py script in a WebServer and access it by calling an API please ?

    For example, if you use PHP on the backend, you can do something like this:

    $output = "<pre>".shell_exec("python scriptname.py")."</pre>";
    echo $output;
    
Sign In or Register to comment.