How to execute python script in android application with Embed python interpreter ? - android

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 ?

Related

Is there a way to get data from sensors from command line?

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.

How can i create an .apk application using matlab code? [duplicate]

I have an algorithm and some other code which is in MATLAB and I want to use it in my Android application.
How can I do this?
Can I make a jar file from MATLAB for use with Android?
I have to do something else?
If you have an additional product, MATLAB Builder JA for Java, you can produce a .jar file from your MATLAB code.
However, the .jar file requires the MATLAB Compiler Runtime (a freely redistributable component that you get with MATLAB Compiler and MATLAB Builder products) to be present. The MCR has a much larger footprint than is suitable for the typical Android device (it's like a copy of MATLAB itself, without the user interface).
You could think about either
Running your MATLAB .jar file remotely on a server, and having your Android application connect to it, or
Instead of using MATLAB Compiler and Builder products, use MATLAB Coder, which will convert a subset of the MATLAB language directly into C code. This C code doesn't require the MCR, and could be compiled to run directly on Android. Make sure your MATLAB algorithm falls within, or can be expressed in, the appropriate subset of the MATLAB language.
Edit: As of R2015a, functionality from MATLAB Builder JA for Java has been replaced by a new product, MATLAB Compiler SDK.
I am the developer of Addi. http://addi.googlecode.com Addi is quickly becoming a full port of Octave (which is an open source tool that uses Matlab syntax). Addi is going to have intents for other applications to use it as their math engines or plotting engines. So, if you can run your code on Octave, then very soon you will be able to run it on Android.
Our only option is to get C++ code from M code using MATLAB Coder toolbox, that generates standalone C and C++ code from MATLABĀ® code. It supports only some subset of all Matlab functions, therefore might be not suitable for your needs.
Having C code you can compile it using NDK. MATLAB Compiler is not an option here.
A new feature in Matlab 2014a:
http://www.mathworks.com/help/simulink/samsung-galaxy-android-devices.html
You can now directly install (limited set of) models to Samsung Android devices, and this should work actually on any Android device.
You can convert matlab code into python and then use the python code in the android .There are many tools to do this conversion. Python goes well with android than matlab.
You have 2 options,
Create a JAR and include in your Java Application and start using it. (I have not tested this by creating a JAR outside Eclipse)
You can code the same thing in C and use Android NDK to process it. (This will be faster and safer way)

How can I use code template in android when creating project from command line?

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?

Calling Lua Script From an Android Application

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!')

How to call Python script from Android

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).

Categories

Resources