21
21
import android .content .pm .PackageManager ;
22
22
23
23
import org .qtproject .qt .android .bindings .QtActivity ;
24
- import org .qtproject .qt .android .QtNative ;
25
24
26
25
public class PythonActivity extends QtActivity {
27
26
@@ -52,6 +51,18 @@ public String getEntryPoint(String search_dir) {
52
51
return "main.py" ;
53
52
}
54
53
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
+
55
66
@ Override
56
67
public void onCreate (Bundle savedInstanceState ) {
57
68
this .mActivity = this ;
@@ -69,14 +80,14 @@ public void onCreate(Bundle savedInstanceState) {
69
80
String entry_point = getEntryPoint (app_root_dir );
70
81
71
82
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" );
80
91
81
92
Log .v (TAG , "About to do super onCreate" );
82
93
super .onCreate (savedInstanceState );
0 commit comments