3

i am trying to get result from a python script using (SL4A) after calling startActivityForResult() in my java android app. However i always get a null intent in my onActivityResult()

Running the python Script from my Java app

public static Intent buildStartInBackgroundIntent(File script) {
final ComponentName componentName = Constants.SL4A_SERVICE_LAUNCHER_COMPONENT_NAME;
Intent intent = new Intent();
intent.setComponent(componentName);
intent.setAction(Constants.ACTION_LAUNCH_BACKGROUND_SCRIPT);
intent.putExtra(Constants.EXTRA_SCRIPT_PATH, script.getAbsolutePath());
return intent;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_layout_running);
String pythonScript = "/sdcard/sl4a/scripts/pythondecoder.py";
Intent intent = buildStartInBackgroundIntent(new File(pythonScript));
intent.putExtra("serialinput","MessageIn");
startActivityForResult(intent, PYTHONSCRIPTDECODE);
}

Receiving the Result from pythonscript upon completion

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode){
case  PYTHONSCRIPTDECODE:
Log.d("Robin_ValueCheck","Python reply me -> "+data.getExtras().getString("SCRIPT_RESULT"));
break;
}

however upon Activity result, Logcat Error Msg.

08-27 09:56:41.945: E/AndroidRuntime(29438): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=3050, result=0, data=null} to activity {xxx.xxx.xxx/com.xxx.xxx.CustomLayoutViewer}: java.lang.NullPointerException

This is my python script, run by SL4A

import android
droid = android.Android()
mIntent = droid.getIntent().result
Extras = mIntent["extras"]
Input = Extras["serialinput"]

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

When the python script exits, my onActivityResult is notified as seen by REQUEST = 3050. However the Intent that should comes back with it is NULL. I have already called setResultString() in my python script. Any idea what could have gone wrong?

1 Answer 1

1

unfortunately this does not work, see also issue 239... you might want to star that issue there: http://code.google.com/p/android-scripting/issues/detail?id=239

Sign up to request clarification or add additional context in comments.

1 Comment

The above link doesnt work. Please follow the link. "Allow scripts to exit with a result" github.com/damonkohler/sl4a/issues/262

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.