Skip to content

Commit 353860d

Browse files
committed
Remove notification wwhen clean recent, fix calling notification
1 parent 30337fc commit 353860d

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

android/src/main/kotlin/com/hiennv/flutter_callkit_incoming/CallkitNotificationManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,10 @@ class CallkitNotificationManager(
593593
data: Bundle, isConnected: Boolean? = false
594594
): CallkitNotification? {
595595

596+
val isCallingNotificationShow =
597+
data.getBoolean(CallkitConstants.EXTRA_CALLKIT_CALLING_SHOW, true)
598+
if (!isCallingNotificationShow) return null
599+
596600
val callingId = data.getString(
597601
CallkitConstants.EXTRA_CALLKIT_CALLING_ID,
598602
data.getString(CallkitConstants.EXTRA_CALLKIT_ID, "callkit_incoming")
@@ -1129,6 +1133,7 @@ class CallkitNotificationManager(
11291133
}
11301134

11311135
fun destroy() {
1136+
11321137
callkitSoundPlayerManager?.destroy()
11331138
}
11341139

android/src/main/kotlin/com/hiennv/flutter_callkit_incoming/CallkitNotificationService.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.content.pm.ServiceInfo
88
import android.os.Build
99
import android.os.Bundle
1010
import android.os.IBinder
11+
import android.util.Log
1112
import androidx.core.content.ContextCompat
1213

1314
class CallkitNotificationService : Service() {
@@ -26,7 +27,13 @@ class CallkitNotificationService : Service() {
2627
putExtra(CallkitConstants.EXTRA_CALLKIT_INCOMING_DATA, data)
2728
}
2829
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && intent.action in ActionForeground) {
29-
ContextCompat.startForegroundService(context, intent)
30+
data?.let {
31+
if(it.getBoolean(CallkitConstants.EXTRA_CALLKIT_CALLING_SHOW, true)) {
32+
ContextCompat.startForegroundService(context, intent)
33+
}else {
34+
context.startService(intent)
35+
}
36+
}
3037
} else {
3138
context.startService(intent)
3239
}
@@ -66,6 +73,8 @@ class CallkitNotificationService : Service() {
6673
callkitNotificationManager?.clearIncomingNotification(it, true)
6774
if (it.getBoolean(CallkitConstants.EXTRA_CALLKIT_CALLING_SHOW, true)) {
6875
showOngoingCallNotification(it)
76+
}else {
77+
stopSelf()
6978
}
7079
}
7180
}
@@ -101,6 +110,17 @@ class CallkitNotificationService : Service() {
101110
}
102111

103112

113+
override fun onTaskRemoved(rootIntent: Intent?) {
114+
super.onTaskRemoved(rootIntent)
115+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
116+
stopForeground(STOP_FOREGROUND_REMOVE)
117+
}else {
118+
stopForeground(true)
119+
}
120+
stopSelf()
121+
}
122+
123+
104124

105125
}
106126

0 commit comments

Comments
 (0)