Properly cancel missed mobile calls notification when call history is entered
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
package com.tutpro.baresip
|
package com.tutpro.baresip
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.telecom.TelecomManager
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
@@ -98,7 +100,11 @@ private fun CallsScreen(navController: NavController, viewModel: ViewModel, aor:
|
|||||||
var refreshTrigger by remember { mutableIntStateOf(0) }
|
var refreshTrigger by remember { mutableIntStateOf(0) }
|
||||||
val lifecycleOwner = LocalLifecycleOwner.current
|
val lifecycleOwner = LocalLifecycleOwner.current
|
||||||
|
|
||||||
LaunchedEffect(aor, refreshTrigger) {
|
val ctx = LocalContext.current
|
||||||
|
|
||||||
|
LaunchedEffect(ua, refreshTrigger) {
|
||||||
|
if (ua.account.isMobile)
|
||||||
|
clearSystemMissedCalls(ctx)
|
||||||
callHistory.value = loadCallHistory(aor)
|
callHistory.value = loadCallHistory(aor)
|
||||||
isHistoryLoaded = true
|
isHistoryLoaded = true
|
||||||
}
|
}
|
||||||
@@ -114,8 +120,6 @@ private fun CallsScreen(navController: NavController, viewModel: ViewModel, aor:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val ctx = LocalContext.current
|
|
||||||
|
|
||||||
BackHandler(enabled = true) {
|
BackHandler(enabled = true) {
|
||||||
val serviceIntent = Intent(ctx, BaresipService::class.java)
|
val serviceIntent = Intent(ctx, BaresipService::class.java)
|
||||||
serviceIntent.action = "Clear Missed"
|
serviceIntent.action = "Clear Missed"
|
||||||
@@ -594,3 +598,16 @@ fun callTint(direction: Int): Int {
|
|||||||
else -> R.color.colorTrafficYellow
|
else -> R.color.colorTrafficYellow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("MissingPermission")
|
||||||
|
private fun clearSystemMissedCalls(ctx: Context) {
|
||||||
|
val telecom = ctx.getSystemService(TelecomManager::class.java)
|
||||||
|
try {
|
||||||
|
telecom.cancelMissedCallsNotification()
|
||||||
|
Log.d(TAG, "cancelMissedCallsNotification() succeeded")
|
||||||
|
} catch (e: SecurityException) {
|
||||||
|
Log.w(TAG, "Cannot clear missed call notification: $e")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Unexpected failure clearing missed call notification", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user