Skip to content

Commit 2004698

Browse files
committed
Fix orientation and app path
basically creating .kivy folder(logs), fetching files with paths relative to main.py and so on. ANDROID_APP_PATH has to be the folder of main.py file.
1 parent 4701523 commit 2004698

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

pythonforandroid/bootstraps/sdl2/build/src/org/kivy/android/PythonActivity.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.graphics.PixelFormat;
2424
import android.view.SurfaceHolder;
2525
import android.content.Context;
26+
import android.content.pm.ActivityInfo;
2627
import android.content.pm.PackageManager;
2728
import android.content.pm.ApplicationInfo;
2829
import android.content.Intent;
@@ -79,12 +80,23 @@ protected void onCreate(Bundle savedInstanceState) {
7980
//
8081
// Otherwise, we use the public data, if we have it, or the
8182
// private data if we do not.
83+
String app_root_dir = getAppRoot();
8284
if (getIntent() != null && getIntent().getAction() != null &&
8385
getIntent().getAction().equals("org.kivy.LAUNCH")) {
8486
File path = new File(getIntent().getData().getSchemeSpecificPart());
8587

8688
Project p = Project.scanDirectory(path);
8789
SDLActivity.nativeSetEnv("ANDROID_ENTRYPOINT", p.dir + "/main.py");
90+
SDLActivity.nativeSetEnv("ANDROID_ARGUMENT", p.dir);
91+
SDLActivity.nativeSetEnv("ANDROID_APP_PATH", p.dir);
92+
93+
if (p != null) {
94+
if (p.landscape) {
95+
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
96+
} else {
97+
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
98+
}
99+
}
88100

89101
// Let old apps know they started.
90102
try {
@@ -96,14 +108,13 @@ protected void onCreate(Bundle savedInstanceState) {
96108
}
97109
} else {
98110
SDLActivity.nativeSetEnv("ANDROID_ENTRYPOINT", "main.pyo");
111+
SDLActivity.nativeSetEnv("ANDROID_ARGUMENT", app_root_dir);
112+
SDLActivity.nativeSetEnv("ANDROID_APP_PATH", app_root_dir);
99113
}
100114

101-
String app_root_dir = getAppRoot();
102115
String mFilesDirectory = mActivity.getFilesDir().getAbsolutePath();
103116
Log.v(TAG, "Setting env vars for start.c and Python to use");
104117
SDLActivity.nativeSetEnv("ANDROID_PRIVATE", mFilesDirectory);
105-
SDLActivity.nativeSetEnv("ANDROID_ARGUMENT", app_root_dir);
106-
SDLActivity.nativeSetEnv("ANDROID_APP_PATH", app_root_dir);
107118
SDLActivity.nativeSetEnv("PYTHONHOME", app_root_dir);
108119
SDLActivity.nativeSetEnv("PYTHONPATH", app_root_dir + ":" + app_root_dir + "/lib");
109120
SDLActivity.nativeSetEnv("PYTHONOPTIMIZE", "2");

pythonforandroid/recipes/python2/patches/custom-loader.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
+
1818
+ /* Ensure we have access to libpymodules. */
1919
+ if (libpymodules == -1) {
20-
+ printf("ANDROID_APP_PATH = %s\n", getenv("ANDROID_APP_PATH"));
21-
+ PyOS_snprintf(pathbuf, sizeof(pathbuf), "%s/libpymodules.so", getenv("ANDROID_APP_PATH"));
20+
+ printf("ANDROID_PRIVATE = %s\n", getenv("ANDROID_PRIVATE"));
21+
+ PyOS_snprintf(pathbuf, sizeof(pathbuf), "%s/app/libpymodules.so", getenv("ANDROID_PRIVATE"));
2222
+ libpymodules = dlopen(pathbuf, RTLD_NOW);
2323
+
2424
+ if (libpymodules == NULL) {

testapps/testlauncher_setup/sdl2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
'requirements': (
88
'python2,sdl2,android,'
99
'sqlite3,docutils,pygments,kivy,pyjnius,plyer,'
10-
'cymunk,lxml,pil,' # audiostream, ffmpeg, openssl,
11-
'twisted,numpy'), # pyopenssl
10+
'cymunk,lxml,pil,openssl,pyopenssl,'
11+
'twisted'), # audiostream, ffmpeg, numpy
1212
'android-api': 14,
1313
'dist-name': 'launchertest_sdl2',
1414
'name': 'TestLauncher-sdl2',

0 commit comments

Comments
 (0)