mirror of
https://github.com/love2d/love-android.git
synced 2026-08-17 03:02:45 +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:
+10
-8
@@ -6,14 +6,15 @@ android {
|
||||
// See https://code.google.com/p/android/issues/detail?id=52962
|
||||
// and http://stackoverflow.com/questions/27277433/why-does-gradle-build-my-module-in-release-mode-when-the-app-is-in-debug
|
||||
// defaultPublishConfig "debug"
|
||||
compileSdkVersion 28
|
||||
buildToolsVersion '28.0.3'
|
||||
compileSdkVersion 30
|
||||
buildToolsVersion '30.0.2'
|
||||
ndkVersion '21.3.6528147'
|
||||
|
||||
defaultConfig {
|
||||
compileSdkVersion 28
|
||||
buildToolsVersion "28.0.3"
|
||||
compileSdkVersion 30
|
||||
buildToolsVersion "30.0.2"
|
||||
minSdkVersion 14
|
||||
resValue "bool", "embed", "false"
|
||||
resValue 'bool', 'embed', 'false'
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
arguments "-j4"
|
||||
@@ -24,6 +25,7 @@ android {
|
||||
// libraries Gradle should build and package with your APK.
|
||||
abiFilters 'armeabi-v7a', 'arm64-v8a'
|
||||
}
|
||||
targetSdkVersion 30
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
@@ -41,7 +43,7 @@ android {
|
||||
}
|
||||
embed {
|
||||
dimension 'mode'
|
||||
resValue "bool", "embed", "true"
|
||||
resValue 'bool', 'embed', 'true'
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
@@ -59,7 +61,7 @@ android {
|
||||
}
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
path "src/jni/Android.mk"
|
||||
path 'src/jni/Android.mk'
|
||||
}
|
||||
}
|
||||
lintOptions {
|
||||
@@ -73,5 +75,5 @@ android {
|
||||
|
||||
dependencies {
|
||||
api fileTree(dir: 'libs', include: ['*.jar'])
|
||||
api 'androidx.appcompat:appcompat:1.1.0-alpha01'
|
||||
api 'androidx.appcompat:appcompat:1.2.0'
|
||||
}
|
||||
|
||||
@@ -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