Use ServiceCompat.

This commit is contained in:
Isira Seneviratne 2023-02-06 08:10:05 +05:30
parent c75f1dcb85
commit 8cd1094526

View File

@ -5,9 +5,9 @@ import android.app.PendingIntent
import android.app.Service import android.app.Service
import android.content.Intent import android.content.Intent
import android.os.Binder import android.os.Binder
import android.os.Build
import android.os.IBinder import android.os.IBinder
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.app.ServiceCompat
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.api.CronetHelper import com.github.libretube.api.CronetHelper
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
@ -315,9 +315,7 @@ class DownloadService : Service() {
// Stop the service if no downloads are active. // Stop the service if no downloads are active.
if (downloadQueue.none { it.value }) { if (downloadQueue.none { it.value }) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_DETACH)
stopForeground(STOP_FOREGROUND_DETACH)
}
sendBroadcast(Intent(ACTION_SERVICE_STOPPED)) sendBroadcast(Intent(ACTION_SERVICE_STOPPED))
stopSelf() stopSelf()
} }