diff --git a/{{ cookiecutter.format }}/app/src/main/java/org/beeware/android/MainActivity.java b/{{ cookiecutter.format }}/app/src/main/java/org/beeware/android/MainActivity.java index 26f06af..33c993d 100644 --- a/{{ cookiecutter.format }}/app/src/main/java/org/beeware/android/MainActivity.java +++ b/{{ cookiecutter.format }}/app/src/main/java/org/beeware/android/MainActivity.java @@ -3,6 +3,8 @@ import android.content.Intent; import android.content.res.Configuration; import android.os.Bundle; +import android.system.Os; +import android.system.ErrnoException; import android.util.Log; import android.view.Menu; import android.view.MenuItem; @@ -16,9 +18,11 @@ import com.chaquo.python.Python; import com.chaquo.python.android.AndroidPlatform; +import java.util.Iterator; import java.util.List; import org.json.JSONArray; +import org.json.JSONObject; import org.json.JSONException; import {{ cookiecutter.package_name }}.{{ cookiecutter.module_name }}.R; @@ -56,6 +60,22 @@ protected void onCreate(Bundle savedInstanceState) { this.setContentView(layout); singletonThis = this; + String environStr = getIntent().getStringExtra("org.beeware.ENVIRON"); + if (environStr != null) { + try { + JSONObject environJson = new JSONObject(environStr); + for (Iterator it = environJson.keys(); it.hasNext(); ) { + String key = it.next(); + String value = environJson.getString(key); + Os.setenv(key, value, true); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } catch (ErrnoException e) { + throw new RuntimeException(e); + } + } + Python py; if (Python.isStarted()) { Log.d(TAG, "Python already started");