@@ -11,6 +11,7 @@ import android.app.PendingIntent
1111import android.content.Context
1212import android.content.Intent
1313import android.graphics.Bitmap
14+ import android.os.Build
1415import android.os.Bundle
1516import android.os.Process
1617import android.os.ResultReceiver
@@ -303,7 +304,7 @@ open class MediaService : MediaBrowserServiceCompat(), CoroutineScope by MainSco
303304 val currentNavigator: StateFlow <MediaSessionNavigator ?> get() = navigator
304305
305306 fun getNavigator (context : Context , publication : Publication , publicationId : PublicationId , initialLocator : Locator ? ): MediaSessionNavigator {
306- context.startService (Intent (context, serviceClass))
307+ context.startForegroundServiceCompat (Intent (context, serviceClass))
307308
308309 currentNavigator.value
309310 ?.takeIf { it.publicationId == publicationId }
@@ -329,6 +330,14 @@ open class MediaService : MediaBrowserServiceCompat(), CoroutineScope by MainSco
329330
330331}
331332
333+ private fun Context.startForegroundServiceCompat (intent : Intent ) {
334+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
335+ startForegroundService(intent)
336+ } else {
337+ startService(intent)
338+ }
339+ }
340+
332341// FIXME: Move to r2-shared
333342internal fun <T > createIfNull (property : KMutableProperty0 <T ?>, owner : Any , factory : () -> T ): T =
334343 property.get() ? : synchronized(owner) {
0 commit comments