mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
Merge pull request #2750 from Isira-Seneviratne/startForegroundService_helper
Use ContextCompat.startForegroundService().
This commit is contained in:
commit
d002285b85
@ -1,15 +0,0 @@
|
||||
package com.github.libretube.compat
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
|
||||
class ServiceCompat(private val context: Context) {
|
||||
fun startForeground(intent: Intent) {
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
|
||||
context.startForegroundService(intent)
|
||||
} else {
|
||||
context.startService(intent)
|
||||
}
|
||||
}
|
||||
}
|
@ -3,23 +3,21 @@ package com.github.libretube.receivers
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.github.libretube.compat.ServiceCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.github.libretube.services.DownloadService
|
||||
|
||||
class NotificationReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (intent?.action == null) return
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (intent.action == null) return
|
||||
|
||||
val serviceIntent = Intent(context, DownloadService::class.java)
|
||||
serviceIntent.action = intent.action
|
||||
.setAction(intent.action)
|
||||
|
||||
val id = intent.getIntExtra("id", -1)
|
||||
if (id == -1) return
|
||||
serviceIntent.putExtra("id", id)
|
||||
|
||||
context?.let {
|
||||
ServiceCompat(it).startForeground(serviceIntent)
|
||||
}
|
||||
ContextCompat.startForegroundService(context, serviceIntent)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -3,7 +3,7 @@ package com.github.libretube.util
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.github.libretube.compat.ServiceCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.services.BackgroundMode
|
||||
|
||||
@ -33,7 +33,7 @@ object BackgroundHelper {
|
||||
intent.putExtra(IntentData.keepQueue, keepQueue)
|
||||
|
||||
// start the background mode as foreground service
|
||||
ServiceCompat(context).startForeground(intent)
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,7 +3,7 @@ package com.github.libretube.util
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import com.github.libretube.compat.ServiceCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.db.obj.DownloadItem
|
||||
@ -66,7 +66,7 @@ object DownloadHelper {
|
||||
intent.putExtra(IntentData.audioQuality, audioQuality)
|
||||
intent.putExtra(IntentData.subtitleCode, subtitleCode)
|
||||
|
||||
ServiceCompat(context).startForeground(intent)
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
|
||||
fun DownloadItem.getNotificationId(): Int {
|
||||
|
Loading…
x
Reference in New Issue
Block a user