Is it possible in Android to call Python script? I have already some scripts in Python 2.7 and I want to call that from Android(that script create file and fills with data). To be more specific I am trying to execute Python script on phone, that script connects to some site, download data and do some intelligence and then create file with new data(json on phone).
With googles SL4A-project, it's possible to have Python-scripts execute on your Android phone.
Parts of the Android API are wrapped for Python (but not all of it)
You can embed Python-scripts in your application (sounds like your approach).
Related
In Android, I know it's possible to use Runtime.getRuntime().exec(...) to execute native command line on android system like echo or ls.
I wonder if is there is any way to get data from any sensor module (like photo or gps) not from Android API (through Java or Kotlin), but by executing a command line with Runtime.getRuntime().exec(...). Is there a way to do it?
Technically all that the Android framework ( + HAL ) does is communicate via system calls with the kernel.
It would certainly be possible for you to write a binary ( C/C++) that does that communication for you, bypassing the framework.
And then you could call that binary with Runtime.getRuntime().exec(...) ( assuming rooted and have access ).
There aren't many tools to access the sensors like that ( expect maybe some vendors might have for testing). The only thing that comes to mind that you could use to get some information is by calling dumpsys in shell. This will give you lots of info about the current state of the system, and for example some location data as explaind in this answer
You can pack binary executables into your apk and launch them via Runtime.getRuntime().exec(...). Depending on the data you want to read it may be possible to implement an C/C++ program which reads /proc or /dev. If you completely statically link this executable (use i.e. musl libc) you can call it from your android app to read the data you need.
I need to create a app for to execute python script. This is basically a learnning application for python beginners. Student can write python code and then they run the python file it should show the result. Basically this app provide python lessons for students, according to the lesson i need to provide testing environment for them. So how can i do this ?
I have used android code templates in eclipse such as blank activity,login activity etc. I want to use these templates while creating project from command line. How can I do this?
You can write and render these templates (or any other template you want to create) using Ruby's ERB gem.
From http://www.ictforu.com/index.php/Ruby/erb-ruby.html:
ERB is an abbreviation for Embedded Ruby
ERB is a feature of Ruby that enables user to dynamically generate any
kind of text from templates. The templates combine plain text with
Ruby code for variable substitution and flow control, which makes them
easy to write and maintain.
ERB is commonly used in Rails platform to generate the webpages, It is
also used in generating XML files, Source code, etc.
Although it's quite common in Ruby on Rails you can use it wherever you want ;-)
I suggest you to check:
ERB documentation
How do I execute ruby template files (ERB) without a web server from command line?
Let me first of all clarify a few things:
I am not trying to run a a Lua script from a command line.
I am not trying to invoke any android functions from Lua
So with that out of the way, here is what I am trying to do.
From an Android Activity invoke directly OR indirectly (JNI/SL4A) a Lua script and get back the results in the activity.
Now looking at documentation for SL4A I see a few drawbacks:
1) I cannot find the documentation saying that it lets one programmatically call Lua.
2) It looks like SL4A might need to install as a separate application (not too seemless).
The only other option I see is to NDK cross compile all of Lua and then try to invoke it in C code in some manner.
You may want to look at my sample project AndroLua. It contains a Lua interpreter embedded directly into an Android application using the Android NDK. Only very small changes were necessary to successfully embed it into the Android application.
In order to actually use Lua from your application, LuaJava is also bundled to allow you to use Lua from Java and the other way round.
Look at the application to see an example how I override the print function to allow an output to a TextView instead of a console.
Update: loading modules
I assume the module you want to load is implemented in Lua. The standard Lua techniques for module loading work as usual - you just have to modify the package.path to your application data directory (or wherever you want to store your scripts/modules).
Imagine that you have a module called hello.lua in the application data directory:
$ adb shell
# cd /data/data/sk.kottman.androlua
# cat hello.lua
module(..., package.seeall)
function greet(name)
print('Hello ' .. name)
end
#
Then try running this code in the interpreter:
-- add the data directory to the module search path
package.path = '/data/data/sk.kottman.androlua/?.lua;'..package.path
-- load the module
require 'hello'
-- run a function, should show "Hello Lua!"
hello.greet('Lua!')
Is it possible to create a app and call a command-line utility from it (bundled with the app), like it could be with a desktop application in linux?
Example:
My app wants to load some files but needs them to be converted, so first it calls an utility with command-line (like "jpgconv -r -t image.png") to create converted copies. Is it technically possible on Android?
What you are trying to do is basically call the Android shell from your application and pass it a binary.
Android's shell doesn't seem to accept Intents, in which case it's not possible, and it's anyway severely limited, which is why most users who need a shell (which is a very small subset of Android users) install a separate shell application, as well as tune their filesystem appropriately.
You could however try to embed your binary using the NDK, since, for exemple, BusyBox is straight C.