Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Comments

@omar-adel
Copy link

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
              }
        });
@FeralBytes
Copy link
Contributor

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.

@omar-adel
Copy link
Author

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 .

@FeralBytes
Copy link
Contributor

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.

@kived
Copy link
Contributor

kived commented Mar 23, 2015

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.

@kived kived closed this as completed Mar 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants