Skip to content

Commit

Permalink
Look in /sdcard/lovegame too in Android 9 and earlier for backward co…
Browse files Browse the repository at this point in the history
…mpatibility.

See #194 for further explanation about this change.
  • Loading branch information
MikuAuahDark committed Dec 25, 2020
1 parent 71c0736 commit aaae1f4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="23" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />

<!-- OpenGL ES 2.0 -->
Expand Down
19 changes: 16 additions & 3 deletions love/src/main/java/org/love2d/android/GameActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -308,11 +323,9 @@ public static String getGamePath() {
}
} else {
self.checkLovegameFolder();
if (gamePath.length() > 0)
return gamePath;
}

return "";
return gamePath;
}

public static DisplayMetrics getMetrics() {
Expand Down

0 comments on commit aaae1f4

Please sign in to comment.