From 5ec1a0b255332f8f43166f0c61425a5f5c4b51e3 Mon Sep 17 00:00:00 2001 From: alexb151 Date: Fri, 1 Mar 2024 17:38:14 +0000 Subject: [PATCH] Fix foreground service crashes when launching tts SDK > 33 (#1370) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update TtsService.java * Handle foreground service for versions greater than sdk33 * Added missing Semi colons 😭 * Import build package * Import service info package --- .../main/java/fr/gaulupeau/apps/Poche/tts/TtsService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/tts/TtsService.java b/app/src/main/java/fr/gaulupeau/apps/Poche/tts/TtsService.java index e7a7f2d78..3b0d95247 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/tts/TtsService.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/tts/TtsService.java @@ -10,10 +10,12 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; +import android.content.pm.ServiceInfo; import android.graphics.Bitmap; import android.media.AudioManager; import android.media.MediaPlayer; import android.os.Binder; +import android.os.Build; import android.os.Handler; import android.os.IBinder; import android.os.SystemClock; @@ -1138,7 +1140,11 @@ private void setForegroundAndNotification(boolean forceForeground) { if (foreground) { if (!isForeground) { Log.v(TAG, "setForegroundAndNotification() startForeground()"); - startForeground(NOTIFICATION_ID, generateNotification()); + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.TIRAMISU) { + startForeground(NOTIFICATION_ID, generateNotification()); + } else { + startForeground(NOTIFICATION_ID, generateNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK); + } isForeground = true; } } else {