You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can I pass String value from EditText In Android Activity to Python Script and also make the activity able to retrieve the String result from a function in the python script such as displaying the retrieved String in TextView ?
#346
Closed
omar-adel opened this issue
Mar 23, 2015
· 4 comments
How can I pass String value from EditText In Android Activity to Python Script and also make the activity able to retrieve the String result from a function in the python script such as displaying the retrieved String in TextView ?
And my python script is not in "sl4a" format but it is ordinary script
and it is also complex as it needs importing another scripts inside it which one of them connects to sqlite database .
I want to put the script in assets folder in Android or in res/raw folder
and I don't want the android application to need internet , I want all things embedded in the app .
simple example for this matter is
script.py
def addTwoNbrs(x,y):
return x+y
and in android activity
Button btn = (Button)findViewById(R.id.button1);
final EditText et1 = (EditText)findViewById(R.id.editText1);
final EditText et2 = (EditText)findViewById(R.id.editText2);
final TextView result = (TextView)findViewById(R.id.textView1);
btn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
int x = new Integer(et1.getText().toString());
int y = new Integer(et2.getText().toString());
// How to call python script with these 2 parameters x , y to calculate
// return the result from the script
}
});
The text was updated successfully, but these errors were encountered:
Where is this Python Script, and what is it?
I am making assumptions here which usually means we are off to a bad start.
Why not use something OSC or sockets to pass the value via the local loopback interface or if the script is on a server somewheres then again you can still use either OSC or sockets.
I apologize for not good clarification
I wrote a simple example above to the script
I want to put it in assets folder in Android or in res/raw folder
I don't want to store the script in server as I don't want the android application to need internet
so what do you mean by OSC "(open sound control)"
i searched for it but I don't know if it needs internet permission or not .
please explain even any initial steps to use it to with python script in android .
thanks .
Are you running this script as a service?
Yes Open Sound Control.
Yes it would require internet permissions.
It you wanted to avoid OSC or any networking approach then what I would do, is use a file or 2, in order to communicate, ie: pass the work to be done perhaps as a pickled object, and then pass the pickled result back. These files would be monitored by both the activity and the service, this monitoring essentially sets them up as buffers or a socket between the activity and service.
It sounds like you're trying to use python-for-android as a general purpose Python interpreter for Android - it isn't.
python-for-android is an application packaging framework to package whole Python apps as Android apks. It is not designed for embedding inside another Android app, and currently the implementation has a hard requirement that you use Kivy to write your program.
You could certainly look through the python-for-android code, and use it to help you build your own Python interpreter and have your existing app load it, but that's beyond the scope of p4a right now. If you like Python, though, you should look at Kivy and see if it would work for you.
How can I pass String value from EditText In Android Activity to Python Script and also make the activity able to retrieve the String result from a function in the python script such as displaying the retrieved String in TextView ?
And my python script is not in "sl4a" format but it is ordinary script
and it is also complex as it needs importing another scripts inside it which one of them connects to sqlite database .
I want to put the script in assets folder in Android or in res/raw folder
and I don't want the android application to need internet , I want all things embedded in the app .
simple example for this matter is
script.py
def addTwoNbrs(x,y):
return x+y
and in android activity
Button btn = (Button)findViewById(R.id.button1);
final EditText et1 = (EditText)findViewById(R.id.editText1);
final EditText et2 = (EditText)findViewById(R.id.editText2);
final TextView result = (TextView)findViewById(R.id.textView1);
btn.setOnClickListener(new OnClickListener()
{
The text was updated successfully, but these errors were encountered: