Use ServiceCompat
This commit is contained in:
@@ -6,6 +6,7 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
|
import androidx.core.app.ServiceCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
@@ -64,9 +65,8 @@ object ServiceNotification {
|
|||||||
fun stopForeground(service: Service) = synchronized(this) {
|
fun stopForeground(service: Service) = synchronized(this) {
|
||||||
deviceCountsMap.remove(service) ?: return@synchronized
|
deviceCountsMap.remove(service) ?: return@synchronized
|
||||||
val shutdown = deviceCountsMap.isEmpty()
|
val shutdown = deviceCountsMap.isEmpty()
|
||||||
if (Build.VERSION.SDK_INT >= 33) {
|
ServiceCompat.stopForeground(service,
|
||||||
service.stopForeground(if (shutdown) Service.STOP_FOREGROUND_REMOVE else Service.STOP_FOREGROUND_DETACH)
|
if (shutdown) ServiceCompat.STOP_FOREGROUND_REMOVE else ServiceCompat.STOP_FOREGROUND_DETACH)
|
||||||
} else @Suppress("DEPRECATION") service.stopForeground(shutdown)
|
|
||||||
if (!shutdown) manager.notify(NOTIFICATION_ID, buildNotification(service))
|
if (!shutdown) manager.notify(NOTIFICATION_ID, buildNotification(service))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user