Android: Call Python Script (via SL4A) from Java code - java

Is it possible to call/run a python script file from Java code on the Android platform using SL4A? Basically I have a full blown Java Android app and I have several Python scripts that scrape some information from various web pages. I would like to be able to call these python scripts with the web page and get the results back. Is this possible? If so, can anyone point me in the direction of an example or two?
Thank you,
Harry

run an SL4A script from my application?
http://code.google.com/p/android-scripting/wiki/FAQ#Can_I_run_an_SL4A_script_from_my_application?

Here you go, a solution on how to make Android applications using SL4A and Python. I have developed a functional Python application following this tutorial so I can vouch for it. I assume you can add the Python code and do your data exchange with JSON.
I personally have never tried to mix these two together, though I will probably try after seeing your post.
Also, if you have any problems/questions, related to starting that example, post them here, I might help.

Related

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)
One option would be to create a Web Service API to allow your python results be served up over HTTP. Then it's just a matter of Android communicating with an HTTP web service which is simple.
You might find some python to java bridge out there but in my experience these things always have limitations in practice and seem great in theory but don't end up working correctly.
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
Check out Qpython, could be an easy solution. You can run your python script against the Qpython android python core, or deploy yours.
Checkout this repository: https://github.com/qpython-android/app-call-qpython-api

How do I use Java online on my web server?

I just started learning Java, and I have no idea how it works. The programming language I learned before this was PHP.
My question is, how do I use Java on my website? I created a .java file and it showed up like this (it showed the script): http://cpcheats.co/java/learning/index.java
I'm guessing I need to upload java onto my web server. If I do, can you please tell me where to download it, and where to upload it? If I don't need to download Java, can you please tell me how to use it on my website? Thanks.
I'm guessing I need to upload java onto my web server.
Ok....
Go to a bookstore/library and buy/borrow a book on Java. Spend a weekend on it and when you have a programming question, please post it here and many of us here will try to help you.
Well, what you need first is to understand the basic concept of java, and of a java web application (java on the server). You need to follow a course and this is not the place to write a java getting started, because this already exist.
I suggest that you read this:
http://docs.oracle.com/javase/tutorial/getStarted/
http://docs.oracle.com/javaee/1.4/tutorial/doc/WebApp.html
After a couple of hours you should have a better understanding of what java is and what you can do with it.

How to interact with a .aspx using Java?

I'd like to write a java program that has the ability to input information onto an asp, and then read back the data that is returned from the asp.
Does anyone have any suggestions on how to go about doing this?
Is there an easier/more elegant solution than web scraping?
In order for Java code to work in ASP, it has to be compiled byte-code that can be read by the CLR. A quick Google search of "Java" + ".NET" yielded this: http://www.janetdev.org/
Another thing you could do is just learn C#. If you already know Java, there hardly is a learning curve.

Execute javascript function from java

I want to know if it's possible to execute a javascript function from java. Basically I have a javascript function to which I want to pass a string and then get the output from that function.
If it's possible, how do I accomplish it?
EDIT -
I couldn't find a solution to this, what I did was re-write all the javascript code in Java. But I am guessing, Rhino ported on Android should do the trick. If someone has tried it out, please post a solution.
You probably want to take a look at the ScriptEngine. There are plenty of samples out there on how to use it. Works on anything but Mac where they for some reason selected to include AppleScript instead of JavaScript by default.
Edit: Take a look at this page, there seems to be a Rhino port for Android out there.
Javascript is not natively supported in java. If you need it, you may implement the Rhino javascript engine to do this.
"Rhino is an open-source implementation of JavaScript written entirely in Java. It is typically embedded into Java applications to provide scripting to end users."

Sending HTML Form Data to Java

I have a Java program that I'm trying to interact with over the web.
I need to gather form data from the user on a Drupal site that I don't have any control over, send it to the Java program, and send the output back to the user. The Java program needs to load a lot of libraries every time it's run, so it needs to be up waiting for data from the user.
It'd be best for me to just have an HTML form for the input. What's the simplest way to deal with HTML form data using Java?
Also, I'm trying to call the Java program from a shell script. I want the program running in the background though so the libraries are loaded in advance. So ideally, I could use the server I set up for both applications.
Thanks for any help.
It sounds like you really just want to write a servlet (or use a higher level web framework, but a servlet would work fine). That makes it very easy to get web form data - you just ask for values by name, basically.
You could then "script" the application using curl, wget or something similar to make requests to the servlet.
Apologies if this doesn't answer your question - I'm finding it slightly tricky to understand exactly what you're trying to do, particularly as there are multiple layers of web UI involved, as far as I can see.
The easiest way to make POST requests with java is to use the Apache HttpClient or the more recent HttpComponents libraries.

Categories

Resources