Skip to content

Commit

Permalink
Fix foreground service crashes when launching tts SDK > 33 (#1370)
Browse files Browse the repository at this point in the history
Update TtsService.java

* Handle foreground service for versions greater than sdk33
* Added missing Semi colons 😭
* Import build package
* Import service info package
  • Loading branch information
alexb151 authored Mar 1, 2024
1 parent 2276316 commit 5ec1a0b
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5ec1a0b

Please sign in to comment.