damonkohler / sl4a

SL4A brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device.
Apache License 2.0
2.44k stars 800 forks source link

problem with setResultInteger #154

Open damonkohler opened 9 years ago

damonkohler commented 9 years ago

From @GoogleCodeExporter on May 31, 2015 11:29

device : Samsung S GT-I9000

firmware version : 2.2

the values sent with setResultInteger in script pyhton isn't received
in intent of onActivityResult(int requestCode, int resultCode, Intent
data) in my app. (data = null) 

My app :

public class TestScripting extends Activity {
    /** Called when the activity is first created. */

    static private final int RESULT = 3;
    public static final String EXTRA_RESULT = "SCRIPT_RESULT";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = new Intent("com.googlecode.android_scripting.action.LAUNCH_BACKGROUND_SCRIPT");
        intent.setClassName("com.googlecode.android_scripting", "com.googlecode.android_scripting.activity.ScriptingLayerServiceLauncher");
        intent.putExtra("com.googlecode.android_scripting.extra.SCRIPT_PATH", "/sdcard/hello_world.py");        
        startActivityForResult(intent, RESULT);            
    }

     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         super.onActivityResult(requestCode, resultCode, data);
         switch (requestCode) {
             case RESULT:
                 int resultIntegerScript = data.getIntExtra(EXTRA_RESULT, 0); 
                 if(resultIntegerScript == 6)
                 {
                     Toast.makeText(TestScripting.this, "END SCRIPT", 2000);
                 }
                 return;
         }         
     }   
}

My script : 

import android
droid = android.Android()
droid.makeToast('Hello, Android!')
print 'Hello, Android!'
droid.setResultInteger(0, 6) 

log cat :

03-24 11:06:21.708: 
VERBOSE/sl4a.InterpreterConfiguration$InterpreterListener:127(25380): 
Interpreter discovered: com.googlecode.pythonforandroid
03-24 11:06:21.708: 
VERBOSE/sl4a.InterpreterConfiguration$InterpreterListener:127(25380): Binary: 
/data/data/com.googlecode.pythonforandroid/files/python/bin/python
03-24 11:06:21.712: 
VERBOSE/sl4a.InterpreterConfiguration$InterpreterListener:127(25380): 
Interpreter discovered: com.googlecode.pythonforandroid
03-24 11:06:21.712: 
VERBOSE/sl4a.InterpreterConfiguration$InterpreterListener:127(25380): Binary: 
/data/data/com.googlecode.pythonforandroid/files/python/bin/python
03-24 11:06:55.165: VERBOSE/sl4a.SimpleServer:197(25380): Bound to 
127.0.0.1:36199
03-24 11:06:55.196: VERBOSE/sl4a.Process:115(25380): Executing 
/data/data/com.googlecode.pythonforandroid/files/python/bin/python with 
arguments [/sdcard/hello_world.py] and with environment 
{ANDROID_SOCKET_zygote=10, AP_HANDSHAKE=caffc2f2-207d-4811-922f-f500bc3b3603, 
TMPDIR=/data/local/tmp, ANDROID_BOOTLOGO=1, 
EXTERNAL_STORAGE=/mnt/sdcard/external_sd, ANDROID_ASSETS=/system/app, 
PY4A_EXTRAS=/mnt/sdcard/com.googlecode.pythonforandroid/extras/, 
PATH=/sbin:/system/sbin:/system/bin:/system/xbin, ASEC_MOUNTPOINT=/mnt/asec, 
PYTHONPATH=/mnt/sdcard/com.googlecode.pythonforandroid/extras/python:/data/data/
com.googlecode.pythonforandroid/files/python/lib/python2.6/lib-dynload:/data/dat
a/com.googlecode.pythonforandroid/files/python/lib/python2.6, 
AP_HOST=127.0.0.1, 
TEMP=/mnt/sdcard/com.googlecode.pythonforandroid/extras/python/tmp, 
BOOTCLASSPATH=/system/framework/core.jar:/system/framework/ext.jar:/system/frame
work/framework.jar:/system/framework/android.policy.jar:/system/framework/servic
es.jar, AP_PORT=36199, INTERNAL_STORAGE=/mnt/sdcard, ANDROID_DATA=/data, 
PYTHONHOME=/data/data/com.googlecode.pythonforandroid/files/python, 
LD_LIBRARY_PATH=/data/data/com.googlecode.pythonforandroid/files/python/lib, 
ANDROID_ROOT=/system, ANDROID_PROPERTY_WORKSPACE=9,32768}
03-24 11:06:56.536: VERBOSE/sl4a.SimpleServer$ConnectionThread:88(25380): 
Server thread 16 started.
03-24 11:06:56.673: VERBOSE/sl4a.JsonRpcServer:74(25380): Received: {"params": 
["caffc2f2-207d-4811-922f-f500bc3b3603"], "id": 0, "method": "_authenticate"}
03-24 11:06:56.677: VERBOSE/sl4a.JsonRpcServer:117(25380): Sent: 
{"error":null,"id":0,"result":true}
03-24 11:06:56.677: VERBOSE/sl4a.JsonRpcServer:74(25380): Received: {"params": 
["Hello, Android!"], "id": 1, "method": "makeToast"}
03-24 11:06:56.708: VERBOSE/sl4a.JsonRpcServer:117(25380): Sent: 
{"error":null,"id":1,"result":null}
03-24 11:06:56.712: VERBOSE/sl4a.JsonRpcServer:74(25380): Received: {"params": 
[0, 6], "id": 2, "method": "setResultInteger"}
03-24 11:06:56.723: VERBOSE/sl4a.JsonRpcServer:117(25380): Sent: 
{"error":null,"id":2,"result":null}
03-24 11:06:56.735: VERBOSE/sl4a.SimpleServer$ConnectionThread:101(25380): 
Server thread 16 died.
03-24 11:06:56.743: VERBOSE/sl4a.Process$1:135(25380): Process 25440 exited 
with result code 0.

Original issue reported on code.google.com by SofianeM...@gmail.com on 24 Mar 2011 at 10:15

Copied from original issue: damonkohler/android-scripting#537

damonkohler commented 9 years ago

From @GoogleCodeExporter on May 31, 2015 11:29

Original comment by rjmatthews62 on 25 Mar 2011 at 1:05

damonkohler commented 9 years ago

From @GoogleCodeExporter on May 31, 2015 11:29

I also encounter the same problem. See my activity, script, and logcat output 
below.

Activity:

package com.madc.sl4atest;

import java.io.*;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;

import com.googlecode.android_scripting.Constants;
import com.googlecode.android_scripting.IntentBuilders;

public class TestActivity extends Activity {

    public static final int TOUCHNNDECODE = 7;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // in case you have created a separate IntentBuilders.java file
        // Intent intent = IntentBuilders.buildStartInTerminalIntent(new File("/sdcard/sl4a/scripts/say_time.py"));

        // else use this one
        Intent intent = IntentBuilders.buildStartInBackgroundIntent(new File(Environment.getExternalStorageDirectory(), "sl4a/scripts/test_migs.py"));
        intent.putExtra("in", "TouchNN");

        Log.d("SL4ATest", "The intent is " + intent.toString());
        startActivityForResult(intent, TOUCHNNDECODE);
    } // onCreate

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch(requestCode){
            case  TOUCHNNDECODE:
                if(data == null)
                    Log.d("SL4ATest", "Python reply -> NULL");
                else
                    Log.d("SL4ATest", "Python reply -> " + data.toString());
            break;
        }
    }
}

Python Script:

import android,time
droid = android.Android()

mIntent = droid.getIntent().result
Extras = mIntent["extras"]
Input = Extras["in"]

droid.makeToast('Hello' + Input + 'from Python!')
droid.vibrate(300)

Result_OK = -1
resultData = "Returned from SL4a Script!"
droid.setResultString(Result_OK, resultData)

Logcat:

V/sl4a.SimpleServer:225(25766): Bound to localhost/127.0.0.1
V/sl4a.Process:115(25766): Executing 
/data/data/com.googlecode.pythonforandroid/files/python/bin/python with a
rguments [/mnt/sdcard/sl4a/scripts/test_migs.py] and with environment 
{ANDROID_SOCKET_zygote=10, AP_HANDSHAKE=
85c513bf-c7e6-40a7-a28d-bf95233ebd7d, ANDROID_BOOTLOGO=1, 
EXTERNAL_STORAGE=/mnt/sdcard, ANDROID_ASSETS=/system
/app, PY4A_EXTRAS=/mnt/sdcard/com.googlecode.pythonforandroid/extras/, 
PATH=/sbin:/vendor/bin:/system/sbin:/sy
stem/bin:/system/xbin, ASEC_MOUNTPOINT=/mnt/asec, 
PYTHONPATH=/mnt/sdcard/com.googlecode.pythonforandroid/extra
s/python:/data/data/com.googlecode.pythonforandroid/files/python/lib/python2.6/l
ib-dynload:/data/data/com.goog
lecode.pythonforandroid/files/python/lib/python2.6, AP_HOST=127.0.0.1, 
LOOP_MOUNTPOINT=/mnt/obb, TEMP=/mnt/sdc
ard/com.googlecode.pythonforandroid/extras/python/tmp, 
BOOTCLASSPATH=/system/framework/core.jar:/system/framew
ork/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/
system/framework/android.polic
y.jar:/system/framework/services.jar:/system/framework/core-junit.jar:/system/fr
amework/com.htc.commonctrl.jar
:/system/framework/com.htc.framework.jar:/system/framework/com.htc.android.pimli
b.jar:/system/framework/com.ht
c.android.easopen.jar:/system/framework/com.scalado.util.ScaladoUtil.jar:/system
/framework/com.orange.authenti
cation.simcard.jar:/system/framework/android.supl.jar:/system/framework/com.ecri
o.sip.jar, AP_PORT=38736, ANDR
OID_DATA=/data, 
PYTHONHOME=/data/data/com.googlecode.pythonforandroid/files/python, 
LD_LIBRARY_PATH=/data/data
/com.googlecode.pythonforandroid/files/python/lib, ANDROID_ROOT=/system, 
ANDROID_PROPERTY_WORKSPACE=9,65536}
D/SL4ATest(26655): Python reply -> NULL
D/ActivityManager( 1378): destroyActivityLocked, r=HistoryRecord{40b27fb0 
com.googlecode.android_scripting/.ac
tivity.ScriptingLayerServiceLauncher}
V/ActivityManager( 1378): destroyActivityLocked, 
dalvik.system.VMStack.getThreadStackTrace(Native Method)
V/ActivityManager( 1378): destroyActivityLocked, 
java.lang.Thread.getStackTrace(Thread.java:745)
V/ActivityManager( 1378): destroyActivityLocked, 
com.android.server.am.ActivityStack.destroyActivityLocked(Act
ivityStack.java:3332)
V/ActivityManager( 1378): destroyActivityLocked, 
com.android.server.am.ActivityStack.activityIdleInternal(Acti
vityStack.java:3010)
V/ActivityManager( 1378): destroyActivityLocked, 
com.android.server.am.ActivityManagerService.activityIdle(Act
ivityManagerService.java:4410)
V/ActivityManager( 1378): destroyActivityLocked, 
android.app.ActivityManagerNative.onTransact(ActivityManagerN
ative.java:371)
V/ActivityManager( 1378): destroyActivityLocked, 
com.android.server.am.ActivityManagerService.onTransact(Activ
ityManagerService.java:1642)
V/ActivityManager( 1378): destroyActivityLocked, 
android.os.Binder.execTransact(Binder.java:320)
V/ActivityManager( 1378): destroyActivityLocked, 
dalvik.system.NativeStart.run(Native Method)
D/WindowManagerImpl( 1378): finishRemoveViewLocked, mViews[1]: 
com.android.internal.policy.impl.PhoneWindow$De
corView@40e99ea8
D/StatusBarPolicy( 1536): Network Type: 8
V/sl4a.SimpleServer$ConnectionThread:89(25766): Server thread 39 started.
D/dalvikvm(25766): GC_CONCURRENT freed 433K, 48% free 3212K/6151K, external 
0K/0K, paused 2ms+3ms
D/dalvikvm(25766): GC_CONCURRENT freed 484K, 48% free 3239K/6151K, external 
0K/0K, paused 2ms+3ms
V/sl4a.JsonRpcServer:74(25766): Received: {"params": 
["85c513bf-c7e6-40a7-a28d-bf95233ebd7d"], "id": 0, "metho
d": "_authenticate"}
V/sl4a.JsonRpcServer:117(25766): Sent: {"error":null,"id":0,"result":true}
V/sl4a.JsonRpcServer:74(25766): Received: {"params": [], "id": 1, "method": 
"getIntent"}
V/sl4a.JsonRpcServer:117(25766): Sent: 
{"error":null,"id":1,"result":{"action":"com.googlecode.android_scripti
ng.action.LAUNCH_BACKGROUND_SCRIPT","categories":null,"flags":0,"classname":"com
.googlecode.android_scripting.
activity.ScriptingLayerService","packagename":"com.googlecode.android_scripting"
,"extras":{"com.googlecode.and
roid_scripting.extra.SCRIPT_PATH":"\/mnt\/sdcard\/sl4a\/scripts\/test_migs.py","
in":"TouchNN"}}}
V/sl4a.JsonRpcServer:74(25766): Received: {"params": ["HelloTouchNNfrom 
Python!"], "id": 2, "method": "makeToa
st"}
V/sl4a.JsonRpcServer:117(25766): Sent: {"error":null,"id":2,"result":null}
V/sl4a.JsonRpcServer:74(25766): Received: {"params": [300], "id": 3, "method": 
"vibrate"}
D/WindowManagerImpl(25766): addView, new view, mViews[0]: 
android.widget.LinearLayout@405ac180
V/sl4a.JsonRpcServer:117(25766): Sent: {"error":null,"id":3,"result":null}
V/sl4a.JsonRpcServer:74(25766): Received: {"params": [-1, "Returned from SL4a 
Script!"], "id": 4, "method": "s
etResultString"}
V/sl4a.JsonRpcServer:117(25766): Sent: {"error":null,"id":4,"result":null}
V/sl4a.SimpleServer$ConnectionThread:100(25766): Server thread 39 died.
V/sl4a.Process$1:135(25766): Process 27915 exited with result code 0.
I/keystore( 1271): uid: 1000 action: e -> 7 state: 2 -> 2 retry: 4
D/lights  ( 1378): [LedInfo] write attr ok 
name=/sys/class/leds/green/brightness string=1,len=1

Original comment by migscab...@gmail.com on 22 Mar 2013 at 7:03