Added isNotificationInCall variable
This commit is contained in:
@ -113,6 +113,7 @@ class BaresipService: Service() {
|
|||||||
private var mediaPlayer: MediaPlayer? = null
|
private var mediaPlayer: MediaPlayer? = null
|
||||||
private var androidContactsObserverRegistered = false
|
private var androidContactsObserverRegistered = false
|
||||||
private var hotSpotReceiverRegistered = false
|
private var hotSpotReceiverRegistered = false
|
||||||
|
private var isNotificationInCall = false
|
||||||
private var isServiceClean = false
|
private var isServiceClean = false
|
||||||
|
|
||||||
@SuppressLint("WakelockTimeout")
|
@SuppressLint("WakelockTimeout")
|
||||||
@ -1495,6 +1496,7 @@ class BaresipService: Service() {
|
|||||||
if (VERSION.SDK_INT >= 31)
|
if (VERSION.SDK_INT >= 31)
|
||||||
builder.foregroundServiceBehavior = Notification.FOREGROUND_SERVICE_IMMEDIATE
|
builder.foregroundServiceBehavior = Notification.FOREGROUND_SERVICE_IMMEDIATE
|
||||||
|
|
||||||
|
builder.setOngoing(true)
|
||||||
val notification = builder.build()
|
val notification = builder.build()
|
||||||
notification.flags = notification.flags or Notification.FLAG_NO_CLEAR or Notification.FLAG_ONGOING_EVENT
|
notification.flags = notification.flags or Notification.FLAG_NO_CLEAR or Notification.FLAG_ONGOING_EVENT
|
||||||
|
|
||||||
@ -1510,13 +1512,23 @@ class BaresipService: Service() {
|
|||||||
startForeground(STATUS_NOTIFICATION_ID, notification, type)
|
startForeground(STATUS_NOTIFICATION_ID, notification, type)
|
||||||
else
|
else
|
||||||
startForeground(STATUS_NOTIFICATION_ID, notification)
|
startForeground(STATUS_NOTIFICATION_ID, notification)
|
||||||
|
isNotificationInCall = true
|
||||||
} else {
|
} else {
|
||||||
stopForeground(STOP_FOREGROUND_REMOVE)
|
if (isNotificationInCall) {
|
||||||
if (VERSION.SDK_INT >= 34)
|
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||||
startForeground(STATUS_NOTIFICATION_ID, notification,
|
isNotificationInCall = false
|
||||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
|
if (VERSION.SDK_INT >= 34)
|
||||||
else
|
startForeground(STATUS_NOTIFICATION_ID, notification,
|
||||||
startForeground(STATUS_NOTIFICATION_ID, notification)
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
|
||||||
|
else if (VERSION.SDK_INT >= 30)
|
||||||
|
startForeground(STATUS_NOTIFICATION_ID, notification, 0)
|
||||||
|
else
|
||||||
|
startForeground(STATUS_NOTIFICATION_ID, notification)
|
||||||
|
} else {
|
||||||
|
// Use standard notify for standby updates.
|
||||||
|
// This is much more stable for background registration.
|
||||||
|
nm.notify(STATUS_NOTIFICATION_ID, notification)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Failed to update foreground notification: ${e.message}")
|
Log.e(TAG, "Failed to update foreground notification: ${e.message}")
|
||||||
|
|||||||
Reference in New Issue
Block a user