mirror of
https://github.com/love2d/love-android.git
synced 2026-08-16 08:11:44 +02:00
Android 11.0 compatibility (#195)
* Update dependencies and target SDK * Update Gradle to 6.6.1 * Update target API level to 30 * Update AGP to 4.0.1 * Update Android Build Dependencies (androidx.appcompat:appcompat:1.2.0, androidx.multidex:multidex:2.0.1) * Update readme * Move /sdcard/lovegame directory. (closes #194) * Potentially fixes black screen when reopening LOVE from app drawer (fixes #190) * Downloader cleanup. * Merge SDL AndroidManifest.xml to LOVE * Implement partial "Share to LOVE" support. * Enable resizeableActivity
This commit is contained in:
@@ -243,6 +243,8 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||
|
||||
// love2d-mod-start: allow restarting of the native thread
|
||||
public void startNative() {
|
||||
boolean hadSDLThread = SDLActivity.mSDLThread != null;
|
||||
|
||||
// Set up JNI
|
||||
SDL.setupJNI();
|
||||
|
||||
@@ -283,6 +285,10 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||
SDLActivity.onNativeDropFile(filename);
|
||||
}
|
||||
}
|
||||
|
||||
if (hadSDLThread) {
|
||||
resumeNativeThread();
|
||||
}
|
||||
}
|
||||
// love2d-mod-end: allow restarting of the native thread
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ import android.content.Intent;
|
||||
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;
|
||||
@@ -112,6 +111,7 @@ public class GameActivity extends SDLActivity {
|
||||
storagePermissionUnnecessary = false;
|
||||
embed = context.getResources().getBoolean(R.bool.embed);
|
||||
|
||||
// Get filename from "Open with" of another application
|
||||
handleIntent(this.getIntent());
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -134,7 +134,17 @@ public class GameActivity extends SDLActivity {
|
||||
}
|
||||
|
||||
protected void handleIntent(Intent intent) {
|
||||
Uri game = intent.getData();
|
||||
Uri game = null;
|
||||
|
||||
// Try to handle "Share" intent.
|
||||
// This is actually "bit tricky" to get working in user phone
|
||||
// because shared static variables issue in the native side
|
||||
// (user have to clear LOVE for Android in their recent apps list).
|
||||
if (Intent.ACTION_SEND.equals(intent.getAction())) {
|
||||
game = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||
} else {
|
||||
game = intent.getData();
|
||||
}
|
||||
|
||||
if (!embed && game != null) {
|
||||
String scheme = game.getScheme();
|
||||
@@ -229,17 +239,13 @@ public class GameActivity extends SDLActivity {
|
||||
}
|
||||
|
||||
protected void checkLovegameFolder() {
|
||||
// If no game.love was found fall back to the game in <external storage>/lovegame
|
||||
// if using normal or playstore build
|
||||
// If no game.love was found and embed flavor is not used, fall back to the game in
|
||||
// <external storage>/Android/data/<package name>/games/lovegame
|
||||
if (!embed) {
|
||||
Log.d("GameActivity", "fallback to lovegame folder");
|
||||
if (hasExternalStoragePermission()) {
|
||||
File ext = Environment.getExternalStorageDirectory();
|
||||
if ((new File(ext, "/lovegame/main.lua")).exists()) {
|
||||
gamePath = ext.getPath() + "/lovegame/";
|
||||
}
|
||||
} else {
|
||||
Log.d("GameActivity", "Cannot load game from /sdcard/lovegame: permission not granted");
|
||||
File ext = getExternalFilesDir("games");
|
||||
if ((new File(ext, "/lovegame/main.lua")).exists()) {
|
||||
gamePath = ext.getPath() + "/lovegame/";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -295,7 +301,6 @@ public class GameActivity extends SDLActivity {
|
||||
} else {
|
||||
Log.d("GameActivity", "cannot open game " + gamePath + ": no external storage permission given!");
|
||||
}
|
||||
|
||||
} else {
|
||||
self.checkLovegameFolder();
|
||||
if (gamePath.length() > 0)
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.Manifest;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -37,7 +38,7 @@ public class DownloadActivity extends Activity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= 29 ||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ||
|
||||
ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)
|
||||
{
|
||||
runDownloader();
|
||||
|
||||
@@ -60,14 +60,14 @@ public class DownloadService extends IntentService {
|
||||
request.setTitle(uri.getLastPathSegment());
|
||||
request.setMimeType("application/x-love-game");
|
||||
|
||||
// in order for this if to run, you must use the android 3.2 to compile your app
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
DownloadRequestSettings_API11 settings = new DownloadRequestSettings_API11();
|
||||
settings.setup(request);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||
request.allowScanningByMediaScanner();
|
||||
}
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, uri.getLastPathSegment());
|
||||
// get download service and enqueue file
|
||||
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, uri.getLastPathSegment());
|
||||
|
||||
// get download service and enqueue file
|
||||
Log.d("DownloadActivity", "creating manager");
|
||||
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
Log.d("DownloadActivity", "enqueuing download");
|
||||
@@ -78,26 +78,6 @@ public class DownloadService extends IntentService {
|
||||
registerReceiver(downloadReceiver, intentFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context used to check the device version and DownloadManager information
|
||||
* @return true if the download manager is available
|
||||
*/
|
||||
public static boolean isDownloadManagerAvailable(Context context) {
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
|
||||
return false;
|
||||
}
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
intent.setClassName("com.android.providers.downloads.ui", "com.android.providers.downloads.ui.DownloadList");
|
||||
List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
|
||||
PackageManager.MATCH_DEFAULT_ONLY);
|
||||
return list.size() > 0;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private BroadcastReceiver downloadReceiver = new BroadcastReceiver() {
|
||||
|
||||
@Override
|
||||
@@ -107,10 +87,3 @@ public class DownloadService extends IntentService {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
class DownloadRequestSettings_API11 {
|
||||
public static void setup(DownloadManager.Request request) {
|
||||
request.allowScanningByMediaScanner();
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user