Minor manifest change and some GameActivity changes.

Fixed storage permission request and do not hardcode "game.love" as the cache output
file.
This commit is contained in:
Miku AuahDark
2019-07-26 13:01:25 +08:00
parent 117bba5ff2
commit 5090a072b2
2 changed files with 27 additions and 17 deletions
+7 -7
View File
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest package="org.love2d.android.executable" <manifest package="org.love2d.android.executable"
android:installLocation="auto" xmlns:android="http://schemas.android.com/apk/res/android"> android:installLocation="auto" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
<!-- OpenGL ES 2.0 --> <!-- OpenGL ES 2.0 -->
<uses-feature android:glEsVersion="0x00020000" /> <uses-feature android:glEsVersion="0x00020000" />
@@ -17,7 +17,7 @@
<service android:name="org.love2d.android.DownloadService" /> <service android:name="org.love2d.android.DownloadService" />
<activity <activity
android:name="org.love2d.android.GameActivity" android:name="org.love2d.android.GameActivity"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden|navigation" android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden|navigation"
android:label="LÖVE for Android" android:label="LÖVE for Android"
android:launchMode="singleTask" android:launchMode="singleTask"
android:screenOrientation="landscape" android:screenOrientation="landscape"
@@ -25,7 +25,7 @@
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
<category android:name="tv.ouya.intent.category.GAME"/> <category android:name="tv.ouya.intent.category.GAME" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
@@ -109,24 +109,33 @@ public class GameActivity extends SDLActivity {
if (game != null) { if (game != null) {
String scheme = game.getScheme(); String scheme = game.getScheme();
String path = game.getPath();
// If we have a game via the intent data we we try to figure out how we have to load it. We // If we have a game via the intent data we we try to figure out how we have to load it. We
// support the following variations: // support the following variations:
// * a main.lua file: set gamePath to the directory containing main.lua // * a main.lua file: set gamePath to the directory containing main.lua
// * otherwise: set gamePath to the file // * otherwise: set gamePath to the file
if (scheme.equals("file")) { if (scheme.equals("file")) {
Log.d("GameActivity", "Received intent with path: " + game.getPath()); Log.d("GameActivity", "Received file:// intent with path: " + path);
// If we were given the path of a main.lua then use its // If we were given the path of a main.lua then use its
// directory. Otherwise use full path. // directory. Otherwise use full path.
List<String> path_segments = game.getPathSegments(); List<String> path_segments = game.getPathSegments();
if (path_segments.get(path_segments.size() - 1).equals("main.lua")) { if (path_segments.get(path_segments.size() - 1).equals("main.lua")) {
gamePath = game.getPath().substring(0, game.getPath().length() - "main.lua".length()); gamePath = path.substring(0, path.length() - "main.lua".length());
} else { } else {
gamePath = game.getPath(); gamePath = path;
} }
} else if (scheme.equals("content")) { } else if (scheme.equals("content")) {
Log.d("GameActivity", "Received content:// intent with path: " + path);
try { try {
String destination_file = this.getCacheDir().getPath() + "/game.love"; String filename = "game.love";
String[] pathSegments = path.split("/");
if (pathSegments != null && pathSegments.length > 0) {
filename = pathSegments[pathSegments.length - 1];
}
String destination_file = this.getCacheDir().getPath() + "/" + filename;
InputStream data = getContentResolver().openInputStream(game); InputStream data = getContentResolver().openInputStream(game);
// copyAssetFile automatically closes the InputStream // copyAssetFile automatically closes the InputStream
if (copyAssetFile(data, destination_file)) { if (copyAssetFile(data, destination_file)) {
gamePath = destination_file; gamePath = destination_file;
@@ -139,7 +148,7 @@ public class GameActivity extends SDLActivity {
Log.e("GameActivity", "Unsupported scheme: '" + game.getScheme() + "'."); Log.e("GameActivity", "Unsupported scheme: '" + game.getScheme() + "'.");
AlertDialog.Builder alert_dialog = new AlertDialog.Builder(this); AlertDialog.Builder alert_dialog = new AlertDialog.Builder(this);
alert_dialog.setMessage("Could not load LÖVE game '" + game.getPath() alert_dialog.setMessage("Could not load LÖVE game '" + path
+ "' as it uses unsupported scheme '" + game.getScheme() + "' as it uses unsupported scheme '" + game.getScheme()
+ "'. Please contact the developer."); + "'. Please contact the developer.");
alert_dialog.setTitle("LÖVE for Android Error"); alert_dialog.setTitle("LÖVE for Android Error");
@@ -191,13 +200,14 @@ public class GameActivity extends SDLActivity {
protected void checkLovegameFolder() { protected void checkLovegameFolder() {
// If no game.love was found fall back to the game in <external storage>/lovegame // If no game.love was found fall back to the game in <external storage>/lovegame
Log.d("GameActivity", "fallback to lovegame folder");
if (hasExternalStoragePermission()) { if (hasExternalStoragePermission()) {
File ext = Environment.getExternalStorageDirectory(); File ext = Environment.getExternalStorageDirectory();
if ((new File(ext, "/lovegame/main.lua")).exists()) { if ((new File(ext, "/lovegame/main.lua")).exists()) {
gamePath = ext.getPath() + "/lovegame/"; gamePath = ext.getPath() + "/lovegame/";
} }
} else { } else {
Log.d("GameActivity", "Cannot load game from external storage: permission not granted"); Log.d("GameActivity", "Cannot load game from /sdcard/lovegame: permission not granted");
} }
} }
@@ -409,7 +419,7 @@ public class GameActivity extends SDLActivity {
Log.d("GameActivity", "Permission granted"); Log.d("GameActivity", "Permission granted");
} else { } else {
Log.d("GameActivity", "Did not get permission."); Log.d("GameActivity", "Did not get permission.");
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
showExternalStoragePermissionMissingDialog(); showExternalStoragePermissionMissingDialog();
} }
} }
@@ -426,13 +436,13 @@ public class GameActivity extends SDLActivity {
@Keep @Keep
public boolean hasExternalStoragePermission() { public boolean hasExternalStoragePermission() {
if (ActivityCompat.checkSelfPermission(this, if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) Manifest.permission.READ_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) { == PackageManager.PERMISSION_GRANTED) {
return true; return true;
} }
Log.d("GameActivity", "Requesting permission and locking LÖVE thread until we have an answer."); Log.d("GameActivity", "Requesting permission and locking LÖVE thread until we have an answer.");
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, EXTERNAL_STORAGE_REQUEST_CODE); ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, EXTERNAL_STORAGE_REQUEST_CODE);
synchronized (externalStorageRequestDummy) { synchronized (externalStorageRequestDummy) {
try { try {
@@ -443,7 +453,7 @@ public class GameActivity extends SDLActivity {
} }
} }
return ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; return ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
} }
@Keep @Keep