From 4668d9c9a263d15b4db33abb7bcaf3259e01d53d Mon Sep 17 00:00:00 2001 From: artdeell Date: Thu, 22 Aug 2024 09:18:13 +0300 Subject: [PATCH] Feat[launcher]: update to SDK 34 --- app_pojavlauncher/build.gradle | 4 ++-- app_pojavlauncher/src/main/AndroidManifest.xml | 8 ++++++-- .../java/net/kdt/pojavlaunch/services/GameService.java | 10 +++++++++- .../net/kdt/pojavlaunch/services/ProgressService.java | 9 ++++++++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app_pojavlauncher/build.gradle b/app_pojavlauncher/build.gradle index d54854fc97..5272a1bce2 100644 --- a/app_pojavlauncher/build.gradle +++ b/app_pojavlauncher/build.gradle @@ -90,7 +90,7 @@ configurations { android { namespace 'net.kdt.pojavlaunch' - compileSdk = 33 + compileSdk = 34 lintOptions { abortOnError false @@ -114,7 +114,7 @@ android { defaultConfig { applicationId "net.kdt.pojavlaunch" minSdkVersion 21 - targetSdkVersion 33 + targetSdkVersion 34 versionCode getDateSeconds() versionName getVersionName() multiDexEnabled true //important diff --git a/app_pojavlauncher/src/main/AndroidManifest.xml b/app_pojavlauncher/src/main/AndroidManifest.xml index 4147e1f3a7..e252877c7b 100644 --- a/app_pojavlauncher/src/main/AndroidManifest.xml +++ b/app_pojavlauncher/src/main/AndroidManifest.xml @@ -18,6 +18,8 @@ + + - + + android:process=":game" + android:foregroundServiceType="mediaPlayback"/> diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/GameService.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/GameService.java index d259490f09..032dfbac9f 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/GameService.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/GameService.java @@ -1,8 +1,10 @@ package net.kdt.pojavlaunch.services; +import android.app.Notification; import android.app.PendingIntent; import android.app.Service; import android.content.Intent; +import android.content.pm.ServiceInfo; import android.os.Binder; import android.os.Build; import android.os.IBinder; @@ -43,7 +45,13 @@ public int onStartCommand(Intent intent, int flags, int startId) { .addAction(android.R.drawable.ic_menu_close_clear_cancel, getString(R.string.notification_terminate), pendingKillIntent) .setSmallIcon(R.drawable.notif_icon) .setNotificationSilent(); - startForeground(NotificationUtils.NOTIFICATION_ID_GAME_SERVICE, notificationBuilder.build()); + + Notification notification = notificationBuilder.build(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + startForeground(NotificationUtils.NOTIFICATION_ID_GAME_SERVICE, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK); + } else { + startForeground(NotificationUtils.NOTIFICATION_ID_GAME_SERVICE, notification); + } return START_NOT_STICKY; // non-sticky so android wont try restarting the game after the user uses the "Quit" button } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/ProgressService.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/ProgressService.java index fa005f0161..1973b715a7 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/ProgressService.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/ProgressService.java @@ -1,10 +1,12 @@ package net.kdt.pojavlaunch.services; import android.annotation.SuppressLint; +import android.app.Notification; import android.app.PendingIntent; import android.app.Service; import android.content.Context; import android.content.Intent; +import android.content.pm.ServiceInfo; import android.os.Build; import android.os.IBinder; import android.os.Process; @@ -64,7 +66,12 @@ public int onStartCommand(Intent intent, int flags, int startId) { } Log.d("ProgressService", "Started!"); mNotificationBuilder.setContentText(getString(R.string.progresslayout_tasks_in_progress, ProgressKeeper.getTaskCount())); - startForeground(NotificationUtils.NOTIFICATION_ID_PROGRESS_SERVICE, mNotificationBuilder.build()); + Notification notification = mNotificationBuilder.build(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + startForeground(NotificationUtils.NOTIFICATION_ID_PROGRESS_SERVICE, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC); + } else { + startForeground(NotificationUtils.NOTIFICATION_ID_PROGRESS_SERVICE, notification); + } if(ProgressKeeper.getTaskCount() < 1) stopSelf(); else ProgressKeeper.addTaskCountListener(this, false);