Notification

This commit is contained in:
Dimitris
2026-04-06 13:25:18 +02:00
parent dd2bdc2768
commit b1d56d536d
2 changed files with 2 additions and 18 deletions
@@ -1,22 +1,15 @@
package com.kouros.navigation.car package com.kouros.navigation.car
import android.content.Intent import android.content.Intent
import android.location.Location
import android.os.Message
import android.util.Log
import androidx.car.app.CarContext import androidx.car.app.CarContext
import androidx.car.app.hardware.CarHardwareManager
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.repeatOnLifecycle
import com.kouros.navigation.data.Constants.TAG
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class NotificationManager( class NavigationNotificationManager(
private val carContext: CarContext, private val carContext: CarContext,
private val lifecycleOwner: LifecycleOwner,
) { ) {
private var notificationServiceStarted = false private var notificationServiceStarted = false
@@ -24,17 +17,8 @@ class NotificationManager(
private var serviceStarted = false private var serviceStarted = false
init { init {
lifecycleOwner.lifecycleScope.launch {
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
} }
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.DESTROYED) {
if (notificationServiceStarted) {
stopNotificationService()
}
}
}
}
fun startNotificationService() { fun startNotificationService() {
val intent = Intent(carContext, NavigationNotificationService::class.java) val intent = Intent(carContext, NavigationNotificationService::class.java)
@@ -111,7 +111,7 @@ class NavigationNotificationService : Service() {
* Initializes the notifications, if needed. * Initializes the notifications, if needed.
* *
* *
* [NotificationManager.IMPORTANCE_HIGH] is needed to show the alerts on top of the car * [NavigationNotificationManager.IMPORTANCE_HIGH] is needed to show the alerts on top of the car
* screen. However, the rail widget at the bottom of the screen will show regardless of the * screen. However, the rail widget at the bottom of the screen will show regardless of the
* importance setting. * importance setting.
*/ */