Migrate stopForeground

This commit is contained in:
Mygod
2022-07-11 17:10:27 -04:00
parent 7ba9fa38d4
commit ac452813aa

View File

@@ -64,7 +64,9 @@ 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()
service.stopForeground(shutdown) if (Build.VERSION.SDK_INT >= 33) {
service.stopForeground(if (shutdown) Service.STOP_FOREGROUND_REMOVE else Service.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))
} }