From aaae1f4392ec73daaa1e1c4fec93ba2cccf678ef Mon Sep 17 00:00:00 2001 From: Miku AuahDark Date: Fri, 25 Dec 2020 23:06:41 +0800 Subject: [PATCH] Look in /sdcard/lovegame too in Android 9 and earlier for backward compatibility. See #194 for further explanation about this change. --- app/src/main/AndroidManifest.xml | 2 +- .../java/org/love2d/android/GameActivity.java | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9846f8877..07e313231 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,7 +5,7 @@ - + diff --git a/love/src/main/java/org/love2d/android/GameActivity.java b/love/src/main/java/org/love2d/android/GameActivity.java index 741dda00a..4ac10d72a 100644 --- a/love/src/main/java/org/love2d/android/GameActivity.java +++ b/love/src/main/java/org/love2d/android/GameActivity.java @@ -38,6 +38,7 @@ import android.media.AudioManager; import android.net.Uri; import android.os.Bundle; +import android.os.Environment; import android.os.Vibrator; import android.util.Log; import android.util.DisplayMetrics; @@ -251,7 +252,21 @@ protected void checkLovegameFolder() { File ext = getExternalFilesDir("games"); if ((new File(ext, "/lovegame/main.lua")).exists()) { gamePath = ext.getPath() + "/lovegame/"; + storagePermissionUnnecessary = true; + } else if (android.os.Build.VERSION.SDK_INT <= 28) { + // Try to fallback to /sdcard/lovegame in Android 9 and earlier too. + if (hasExternalStoragePermission()) { + ext = Environment.getExternalStorageDirectory(); + if ((new File(ext, "/lovegame/main.lua")).exists()) { + gamePath = ext.getPath() + "/lovegame/"; + storagePermissionUnnecessary = false; + } + } else { + Log.d("GameActivity", "Cannot load game from /sdcard/lovegame: permission not granted"); + } } + + Log.d("GameActivity", "lovegame directory: " + gamePath); } } @@ -308,11 +323,9 @@ public static String getGamePath() { } } else { self.checkLovegameFolder(); - if (gamePath.length() > 0) - return gamePath; } - return ""; + return gamePath; } public static DisplayMetrics getMetrics() {