Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Executing my own Python scripts in Android using Eclipse

Received: by 10.66.78.106 with SMTP id a10mr789786pax.14.1348745374486;
        Thu, 27 Sep 2012 04:29:34 -0700 (PDT)
X-BeenThere: python-for-android@googlegroups.com
Received: by 10.68.242.38 with SMTP id wn6ls9174021pbc.8.gmail; Thu, 27 Sep
 2012 04:29:33 -0700 (PDT)
Received: by 10.68.222.162 with SMTP id qn2mr743106pbc.0.1348745373847;
        Thu, 27 Sep 2012 04:29:33 -0700 (PDT)
Received: by 10.68.222.162 with SMTP id qn2mr743105pbc.0.1348745373833;
        Thu, 27 Sep 2012 04:29:33 -0700 (PDT)
Return-Path: <anthony.pri...@gmail.com>
Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com [209.85.160.53])
        by gmr-mx.google.com with ESMTPS id nt8si865162pbb.1.2012.09.27.04.29.33
        (version=TLSv1/SSLv3 cipher=OTHER);
        Thu, 27 Sep 2012 04:29:33 -0700 (PDT)
Received-SPF: pass (google.com: domain of anthony.pri...@gmail.com designates 209.85.160.53 as permitted sender) client-ip=209.85.160.53;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of anthony.pri...@gmail.com designates 209.85.160.53 as permitted sender) smtp.mail=anthony.pri...@gmail.com; dkim=pass header...@gmail.com
Received: by mail-pb0-f53.google.com with SMTP id wz12so3422084pbc.12
        for <python-for-android@googlegroups.com>; Thu, 27 Sep 2012 04:29:33 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=mime-version:in-reply-to:references:date:message-id:subject:from:to
         :content-type;
        bh=oIcIM3Xmv2Ve39HeJTjdkPN3usDT2ZFQ0WK95c3xq44=;
        b=oCZt+p8iYR5s9rQX7vt4wJA1bVHb8B9TaEEBlok8isduTRQWp4C6bKuOq5ZUKrQHbU
         bsbZkvuPGXI6CoTo25x9t53CNt4fcyZE58g8A0xfiT4ANGIMyBOdMvdi0NOo5g8/nGgm
         O5NaHnSXqdltyWNy5tSEsVi4wZy8AhOI6Beb2x4NY/sYORrzFCryWHhm6b+ufc/J/9/s
         Qh9zEQ0A/WW4ImXieursVXso49bI0cR7B84S06KTRVyKR4wq58+Rx70JAcG+IFeMi59c
         mAyWOojRRnsFYBxuRIhKI+b/qSY3JHX/+jFtb5jTFx6I59X465eKPd4bR57uZ9i9I2sa
         NzVw==
MIME-Version: 1.0
Received: by 10.68.216.131 with SMTP id oq3mr10453964pbc.147.1348745373625;
 Thu, 27 Sep 2012 04:29:33 -0700 (PDT)
Received: by 10.66.234.201 with HTTP; Thu, 27 Sep 2012 04:29:33 -0700 (PDT)
In-Reply-To: <7900fdb9-958d-470c-8e5c-2f51d48aa970@googlegroups.com>
References: <01b2f854-2b62-4172-84a5-551ba7f9ddff@googlegroups.com>
	<f15446cc-c76c-4279-8e91-7f4ca62552ac@googlegroups.com>
	<865df0ad-7809-4a2b-80d0-5cf58651bd7f@googlegroups.com>
	<CAHEBZ9H7eAn3QDckjbLtF40=dPS-y=dpoESGuL8K-eRX-kL...@mail.gmail.com>
	<b3e5b62d-71b7-46ed-bf28-a05f1fc9d764@googlegroups.com>
	<CAHEBZ9H9ajqiU10yUnOQxMwKTZThDQ76nN_rWv3+hCTh+8Z...@mail.gmail.com>
	<CAOUmUKX3V+75rn65ppeVEVEmNC8NUbpF_4hEccs+nZqV1MX...@mail.gmail.com>
	<CAHEBZ9Hk7b6G6sxMKRQP6f5vubQLTWKKe=nGDr_qWgbg5Ux...@mail.gmail.com>
	<CAOUmUKVWdt1WqDbDJ10pbwe51pQQcuqgeGhnmv9PKGc+Hgk...@mail.gmail.com>
	<CAHEBZ9FWHYJqbxVOgQ2DxydYyMf00YNaxLtZQfbSmHoQOHN...@mail.gmail.com>
	<CAOUmUKUGJJKczVqxhh_p2d4ouc0a-eGccrAJXchav0rBq57...@mail.gmail.com>
	<ce065301-6808-4499-a010-d3efefacd086@googlegroups.com>
	<7900fdb9-958d-470c-8e5c-2f51d48aa970@googlegroups.com>
Date: Thu, 27 Sep 2012 13:29:33 +0200
Message-ID: <CAHEBZ9GGmkc1gJdBkOoJ1LGN8LZoKDVG=iaObuzKTDQCZFT...@mail.gmail.com>
Subject: Re: [Py4A] Re: Executing my own Python scripts in Android using Eclipse
From: Anthony Prieur <anthony.pri...@gmail.com>
To: python-for-android@googlegroups.com
Content-Type: text/plain; charset=UTF-8

1)  You could dump the result in a file after the toast:

f = open("myfile", "wb")
f.write(str(average))
f.close()

You can use also pickle module to dump more complex data structure:
http://docs.python.org/library/pickle.html

2) You can dump the result in a database:
http://docs.python.org/library/sqlite3.html

3) you can post the result to the SL4A server, using you own facade to
manage it: https://code.google.com/p/android-python27/wiki/TutorialHowToCreateCustomRpcFacade

I would use 3)


On Thu, Sep 27, 2012 at 1:12 PM, Archana <ramalingam.arch...@gmail.com> wrote:
> My script is like:
>
> import android
>
> droid = android.Android()
>
> score1 = 10
>
> score2 = 20
>
> average = (score1 + score2)/2
>
> droid.makeToast('Result is: ' +str(average))
>
>
> Can I get the value of average and store it in a file(in internal memory)?
> Please let me know if it is possible to do it?
>
>
>
> On Thursday, September 27, 2012 12:29:55 PM UTC+3, Archana wrote:
>>
>> Hi Anthony,
>>
>> Can I write the output of my script to a new file(in phone's internal
>> memory)? Basically, I need to get the result from the script(like simple
>> calculation). Can you also let me know of more sample Python scripts?
>>
>> Thank you!
>>
>> On Wednesday, September 26, 2012 3:33:59 PM UTC+3, Archana wrote:
>>>
>>> Ya am able to see the print statements. Thanks for the clarification.  I
>>> want to post the updated JSON(after script execution) to a server. Now I m
>>> calling ScriptActivity from my ownActivity using startActivityForResult().
>>> Can I define post method in onActivityResult() in my own activity?
>>>
>>> On Wed, Sep 26, 2012 at 3:13 PM, Anthony Prieur
>>> <anthony.pri...@gmail.com> wrote:
>>>>
>>>> ScriptLauncher.launchScript last arguments is a callback called when
>>>> the script ended:
>>>>
>>>>         ScriptLauncher.launchScript(script, mInterpreterConfiguration,
>>>>                 mProxy, new Runnable() {
>>>>                     @Override
>>>>                     public void run() {
>>>>                         // here your script ended
>>>>                     }
>>>>                 });
>>>>
>>>> So do whatever you need in run(), add some print in the Java code to see
>>>> better.
>>>>
>>>>
>>>> On Wed, Sep 26, 2012 at 1:58 PM, Archana r
>>>> <ramalingam.arch...@gmail.com> wrote:
>>>> > Can u pls explain? I m not getting what you are saying
>>>> >
>>>> >
>>>> > On Wed, Sep 26, 2012 at 2:53 PM, Anthony Prieur
>>>> > <anthony.pri...@gmail.com>
>>>> > wrote:
>>>> >>
>>>> >> Add some printf and check the exec path.
>>>> >>
>>>> >>
>>>> >> On Wed, Sep 26, 2012 at 1:51 PM, Archana r
>>>> >> <ramalingam.arch...@gmail.com>
>>>> >> wrote:
>>>> >> > Hi,
>>>> >> > Actually I want to know, after ScriptLauncher.launchScript(),
>>>> >> > where(from
>>>> >> > which class) does the following get printed?
>>>> >> >
>>>> >> >
>>>> >> > 09-26 09:41:11.881: D/dalvikvm(6427): mprotect(RO) failed (13),
>>>> >> > file
>>>> >> > will
>>>> >> > remain read-write
>>>> >> >
>>>> >> > 09-26 09:41:11.891: D/dalvikvm(6427): mprotect(RO) failed (13),
>>>> >> > file
>>>> >> > will
>>>> >> > remain read-write
>>>> >> >
>>>> >> > 09-26 09:41:11.891: D/dalvikvm(6427): mprotect(RO) failed (13),
>>>> >> > file
>>>> >> > will
>>>> >> > remain read-write
>>>> >> >
>>>> >> > 09-26 09:41:11.891: D/dalvikvm(6427): mprotect(RO) failed (13),
>>>> >> > file
>>>> >> > will
>>>> >> > remain read-write
>>>> >> >
>>>> >> > 09-26 09:41:11.901: D/dalvikvm(6427): mprotect(RO) failed (13),
>>>> >> > file
>>>> >> > will
>>>> >> > remain read-write
>>>> >> >
>>>> >> > 09-26 09:41:11.901: D/dalvikvm(6427): mprotect(RO) failed (13),
>>>> >> > file
>>>> >> > will
>>>> >> > remain read-write
>>>> >> >
>>>> >> > 09-26 09:41:11.911: D/dalvikvm(6427): mprotect(RO) failed (13),
>>>> >> > file
>>>> >> > will
>>>> >> > remain read-write
>>>> >> >
>>>> >> > 09-26 09:41:12.071: D/dalvikvm(6427): mprotect(RO) failed (13),
>>>> >> > file
>>>> >> > will
>>>> >> > remain read-write
>>>> >> >
>>>> >> > 09-26 09:41:12.461: D/dalvikvm(6427): No JNI_OnLoad found in
>>>> >> > /system/lib/libandroid_runtime.so 0x0, skipping init
>>>> >> >
>>>> >> > 09-26 09:41:14.111: V/sl4a.SimpleServer$ConnectionThread:89(6411):
>>>> >> > Server
>>>> >> > thread 15 started.
>>>> >> >
>>>> >> > 09-26 09:41:14.571: D/dalvikvm(6411): GC_CONCURRENT freed 509K, 55%
>>>> >> > free
>>>> >> > 2862K/6279K, external 410K/517K, paused 5ms+5ms
>>>> >> >
>>>> >> > 09-26 09:41:15.011: D/dalvikvm(6411): GC_CONCURRENT freed 478K, 54%
>>>> >> > free
>>>> >> > 2893K/6279K, external 410K/517K, paused 5ms+6ms
>>>> >> >
>>>> >> > 09-26 09:41:15.161: D/dalvikvm(6411): GC_FOR_MALLOC freed 189K, 54%
>>>> >> > free
>>>> >> > 2892K/6279K, external 410K/517K, paused 38ms
>>>> >> >
>>>> >> > 09-26 09:41:15.161: I/dalvikvm-heap(6411): Grow heap (frag case) to
>>>> >> > 5.777MB
>>>> >> > for 8208-byte allocation
>>>> >> >
>>>> >> > 09-26 09:41:15.251: D/dalvikvm(6411): GC_FOR_MALLOC freed 4K, 55%
>>>> >> > free
>>>> >> > 2895K/6343K, external 410K/517K, paused 75ms
>>>> >> >
>>>> >> > 09-26 09:41:15.251: V/sl4a.JsonRpcServer:74(6411): Received:
>>>> >> >
>>>> >> >
>>>> >> > {"id":1,"method":"_authenticate","params":["c7b9507b-6249-4ea9-9776-87fd801c9932"]}
>>>> >> >
>>>> >> > 09-26 09:41:15.281: V/sl4a.JsonRpcServer:117(6411): Sent:
>>>> >> > {"error":null,"id":1,"result":true}
>>>> >> >
>>>> >> > 09-26 09:41:15.301: V/sl4a.JsonRpcServer:74(6411): Received:
>>>> >> > {"id":2,"method":"makeToast","params":["hello javascript15"]}
>>>> >> >
>>>> >> > 09-26 09:41:15.351: V/sl4a.JsonRpcServer:117(6411): Sent:
>>>> >> > {"error":null,"id":2,"result":null}
>>>> >> >
>>>> >> > 09-26 09:41:15.401: V/sl4a.JsonRpcServer:74(6411): Received:
>>>> >> > {"id":3,"method":"notify","params":["javaScript","Success"]}
>>>> >> >
>>>> >> > 09-26 09:41:15.451: V/sl4a.JsonRpcServer:117(6411): Sent:
>>>> >> > {"error":null,"id":3,"result":null}
>>>> >> >
>>>> >> > 09-26 09:41:15.561: D/dalvikvm(6427): GC_EXPLICIT freed 707K, 55%
>>>> >> > free
>>>> >> > 648K/1411K, external 0K/0K, paused 106ms
>>>> >> >
>>>> >> > 09-26 09:41:15.611: D/dalvikvm(6427): GC_CONCURRENT freed 15K, 56%
>>>> >> > free
>>>> >> > 633K/1411K, external 0K/0K, paused 1ms+2ms
>>>> >> >
>>>> >> > 09-26 09:41:15.811: V/sl4a.SimpleServer$ConnectionThread:100(6411):
>>>> >> > Server
>>>> >> > thread 15 died.
>>>> >> >
>>>> >> > 09-26 09:41:15.822: V/sl4a.Process$1:135(6411): Process 6427 exited
>>>> >> > with
>>>> >> > result code 0.
>>>> >> >
>>>> >> >
>>>> >> >
>>>> >> > Thank you!!
>>>> >> >
>>>> >> >
>>>> >> >
>>>> >> >
>>>> >> > On Wed, Sep 26, 2012 at 2:46 PM, Anthony Prieur
>>>> >> > <anthony.pri...@gmail.com>
>>>> >> > wrote:
>>>> >> >>
>>>> >> >> When your script ends:
>>>> >> >>
>>>> >> >> @Override
>>>> >> >>  public void run() {
>>>> >> >>
>>>> >> >> Is executed, see line 195 of
>>>> >> >>
>>>> >> >>
>>>> >> >>
>>>> >> >> https://code.google.com/p/android-python27/source/browse/apk/src/com/android/python27/ScriptService.java
>>>> >> >>
>>>> >> >>
>>>> >> >> On Wed, Sep 26, 2012 at 12:36 PM, Archu
>>>> >> >> <ramalingam.arch...@gmail.com>
>>>> >> >> wrote:
>>>> >> >> > Hi Anthony,
>>>> >> >> >
>>>> >> >> > I am parsing a JSON(for my Python scripts) and able to see the
>>>> >> >> > output
>>>> >> >> > in
>>>> >> >> > emulator. I want to modify the JSON fields and post it back to
>>>> >> >> > the
>>>> >> >> > server. I
>>>> >> >> > used startActivityForResult() while calling the
>>>> >> >> > ScriptActivity(so
>>>> >> >> > that I
>>>> >> >> > can
>>>> >> >> > define HTTP Post method in onActivityResult()). But I want to
>>>> >> >> > know
>>>> >> >> > when
>>>> >> >> > my
>>>> >> >> > service(Script Service) gets over.?  I can define my HTTP Post
>>>> >> >> > only
>>>> >> >> > after
>>>> >> >> > actual execution of my script Is there a means to do the same?
>>>> >> >> >
>>>> >> >> > Regards,
>>>> >> >> > Archana
>>>> >> >> >
>>>> >> >> >
>>>> >> >> > On Tuesday, September 25, 2012 3:59:42 PM UTC+3, anthony wrote:
>>>> >> >> >>
>>>> >> >> >> Alternatively you can just put your scripts in a .zip, put the
>>>> >> >> >> .zip
>>>> >> >> >> in
>>>> >> >> >> res/raw folder, fix variable name:
>>>> >> >> >>
>>>> >> >> >>
>>>> >> >> >>
>>>> >> >> >>
>>>> >> >> >> https://code.google.com/p/android-python27/source/browse/apk/src/com/android/python27/config/GlobalConstants.java
>>>> >> >> >>
>>>> >> >> >> "Run as -> Android Application", and you're done.
>>>> >> >> >>
>>>> >> >> >>
>>>> >> >> >> On Tue, Sep 25, 2012 at 2:49 PM, Archu <ramalinga...@gmail.com>
>>>> >> >> >> wrote:
>>>> >> >> >> > Yes i am now able to execute my own scripts. Just I am
>>>> >> >> >> > putting in
>>>> >> >> >> > a
>>>> >> >> >> > file
>>>> >> >> >> > and
>>>> >> >> >> > passing the File object to launchScript() method.
>>>> >> >> >> >
>>>> >> >> >> >
>>>> >> >> >> > On Tuesday, September 25, 2012 4:56:59 AM UTC+3, Prat wrote:
>>>> >> >> >> >>
>>>> >> >> >> >> Hi Archu,
>>>> >> >> >> >>
>>>> >> >> >> >> I am working on a similar issue. Did you have any luck with
>>>> >> >> >> >> python
>>>> >> >> >> >> scripts
>>>> >> >> >> >> in eclipse for android app?
>>>> >> >> >> >>
>>>> >> >> >> >> Regards,
>>>> >> >> >> >>
>>>> >> >> >> >> Prat
>>>> >> >> >> >>
>>>> >> >> >> >> On Wednesday, September 12, 2012 6:01:55 AM UTC-5, Archu
>>>> >> >> >> >> wrote:
>>>> >> >> >> >>>
>>>> >> >> >> >>> Hi, I m new to Android. I used the link
>>>> >> >> >> >>>
>>>> >> >> >> >>>
>>>> >> >> >> >>>
>>>> >> >> >> >>>
>>>> >> >> >> >>> http://jokar-johnk.blogspot.fi/2011/02/how-to-make-android-app-with-sl4a.html
>>>> >> >> >> >>> to execute Python script in Android. However, I need to run
>>>> >> >> >> >>> my
>>>> >> >> >> >>> own
>>>> >> >> >> >>> script(after parsing from a JSON file). In my case, I
>>>> >> >> >> >>> cannot
>>>> >> >> >> >>> place
>>>> >> >> >> >>> the
>>>> >> >> >> >>> script in /res/raw folder. Please let me know the
>>>> >> >> >> >>> modifications
>>>> >> >> >> >>> in
>>>> >> >> >> >>> ScriptService.java. Any help will be appreciated. Thanks in
>>>> >> >> >> >>> advance
>>>> >> >> >> >>> !
>>>> >> >
>>>> >> >
>>>> >> >
>>>> >> >
>>>> >> > --
>>>> >> > Regards,
>>>> >> > Archana
>>>> >
>>>> >
>>>> >
>>>> >
>>>> > --
>>>> > Regards,
>>>> > Archana
>>>
>>>
>>>
>>>
>>> --
>>> Regards,
>>> Archana