From 7cdefe43d529487eea4644401a385992c3a0c1a2 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 26 Nov 2018 12:25:00 +0100 Subject: [PATCH] refresh the incoming call notification every few secs to keep it visible --- .../contacts/pro/services/DialerCallService.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/DialerCallService.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/DialerCallService.kt index ed37d17e..9be869cd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/DialerCallService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/DialerCallService.kt @@ -8,6 +8,7 @@ import android.app.Service import android.content.Context import android.content.Intent import android.os.Build +import android.os.Handler import android.telecom.Call import androidx.core.app.NotificationCompat import com.simplemobiletools.commons.helpers.isOreoPlus @@ -17,6 +18,7 @@ import com.simplemobiletools.contacts.pro.helpers.* import com.simplemobiletools.contacts.pro.objects.CallManager class DialerCallService : Service() { + private val REFRESH_REMINDER_PERIOD = 3000L private val CALL_NOTIFICATION_ID = 1 private val LAUNCH_DIALER_INTENT_ID = 1 private val DISMISS_CALL_INTENT_ID = 2 @@ -25,6 +27,7 @@ class DialerCallService : Service() { private var callNumber = "" private var callStatus = Call.STATE_NEW private var isIncomingCall = false + private var reminderRefreshHandler = Handler() override fun onBind(intent: Intent?) = null @@ -46,6 +49,7 @@ class DialerCallService : Service() { override fun onDestroy() { super.onDestroy() stopForeground(true) + reminderRefreshHandler.removeCallbacksAndMessages(null) } @TargetApi(Build.VERSION_CODES.O) @@ -78,6 +82,12 @@ class DialerCallService : Service() { .addAction(0, getString(R.string.answer_call), getAnswerCallIntent()) startForeground(CALL_NOTIFICATION_ID, notification.build()) + + reminderRefreshHandler.postDelayed({ + if (callStatus == Call.STATE_RINGING) { + setupNotification() + } + }, REFRESH_REMINDER_PERIOD) } private fun getLaunchDialerIntent(): PendingIntent {