2121import android .content .pm .PackageManager ;
2222
2323import org .qtproject .qt .android .bindings .QtActivity ;
24- import org .qtproject .qt .android .QtNative ;
2524
2625public class PythonActivity extends QtActivity {
2726
@@ -52,6 +51,18 @@ public String getEntryPoint(String search_dir) {
5251 return "main.py" ;
5352 }
5453
54+ public void setEnvironmentVariable (String key , String value ) {
55+ /**
56+ * Sets an environment variable based on key/value.
57+ **/
58+ try {
59+ android .system .Os .setenv (key , value , true );
60+ } catch (Exception e ) {
61+ Log .e ("Qt bootstrap" , "Unable set environment variable:" + key + "=" + value );
62+ e .printStackTrace ();
63+ }
64+ }
65+
5566 @ Override
5667 public void onCreate (Bundle savedInstanceState ) {
5768 this .mActivity = this ;
@@ -69,14 +80,14 @@ public void onCreate(Bundle savedInstanceState) {
6980 String entry_point = getEntryPoint (app_root_dir );
7081
7182 Log .v (TAG , "Setting env vars for start.c and Python to use" );
72- QtNative . setEnvironmentVariable ("ANDROID_ENTRYPOINT" , entry_point );
73- QtNative . setEnvironmentVariable ("ANDROID_ARGUMENT" , app_root_dir );
74- QtNative . setEnvironmentVariable ("ANDROID_APP_PATH" , app_root_dir );
75- QtNative . setEnvironmentVariable ("ANDROID_PRIVATE" , mFilesDirectory );
76- QtNative . setEnvironmentVariable ("ANDROID_UNPACK" , app_root_dir );
77- QtNative . setEnvironmentVariable ("PYTHONHOME" , app_root_dir );
78- QtNative . setEnvironmentVariable ("PYTHONPATH" , app_root_dir + ":" + app_root_dir + "/lib" );
79- QtNative . setEnvironmentVariable ("PYTHONOPTIMIZE" , "2" );
83+ setEnvironmentVariable ("ANDROID_ENTRYPOINT" , entry_point );
84+ setEnvironmentVariable ("ANDROID_ARGUMENT" , app_root_dir );
85+ setEnvironmentVariable ("ANDROID_APP_PATH" , app_root_dir );
86+ setEnvironmentVariable ("ANDROID_PRIVATE" , mFilesDirectory );
87+ setEnvironmentVariable ("ANDROID_UNPACK" , app_root_dir );
88+ setEnvironmentVariable ("PYTHONHOME" , app_root_dir );
89+ setEnvironmentVariable ("PYTHONPATH" , app_root_dir + ":" + app_root_dir + "/lib" );
90+ setEnvironmentVariable ("PYTHONOPTIMIZE" , "2" );
8091
8192 Log .v (TAG , "About to do super onCreate" );
8293 super .onCreate (savedInstanceState );
0 commit comments