mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
Properly clear missed calls on start
This commit is contained in:
@@ -2,7 +2,6 @@ package com.simplemobiletools.dialer.activities
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.SearchManager
|
import android.app.SearchManager
|
||||||
import android.content.ContentValues
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ShortcutInfo
|
import android.content.pm.ShortcutInfo
|
||||||
@@ -12,7 +11,6 @@ import android.graphics.drawable.Icon
|
|||||||
import android.graphics.drawable.LayerDrawable
|
import android.graphics.drawable.LayerDrawable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.provider.CallLog
|
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
@@ -44,6 +42,7 @@ import kotlinx.android.synthetic.main.fragment_favorites.*
|
|||||||
import kotlinx.android.synthetic.main.fragment_recents.*
|
import kotlinx.android.synthetic.main.fragment_recents.*
|
||||||
import me.grantland.widget.AutofitHelper
|
import me.grantland.widget.AutofitHelper
|
||||||
|
|
||||||
|
|
||||||
class MainActivity : SimpleActivity() {
|
class MainActivity : SimpleActivity() {
|
||||||
private var isSearchOpen = false
|
private var isSearchOpen = false
|
||||||
private var launchedDialer = false
|
private var launchedDialer = false
|
||||||
@@ -301,7 +300,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
wantedTab = main_tabs_holder.tabCount - 1
|
wantedTab = main_tabs_holder.tabCount - 1
|
||||||
|
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
resetMissedCalls()
|
clearMissedCalls()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,21 +449,15 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear the missed calls count. Doesn't seem to always work, but having it can't hurt
|
@SuppressLint("MissingPermission")
|
||||||
// found at https://android.googlesource.com/platform/packages/apps/Dialer/+/nougat-release/src/com/android/dialer/calllog/MissedCallNotifier.java#181
|
private fun clearMissedCalls() {
|
||||||
private fun resetMissedCalls() {
|
|
||||||
val values = ContentValues().apply {
|
|
||||||
put(CallLog.Calls.NEW, 0)
|
|
||||||
put(CallLog.Calls.IS_READ, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
val selection = "${CallLog.Calls.TYPE} = ?"
|
|
||||||
val selectionArgs = arrayOf(CallLog.Calls.MISSED_TYPE.toString())
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val uri = CallLog.Calls.CONTENT_URI
|
// notification cancellation triggers MissedCallNotifier.clearMissedCalls() which, in turn,
|
||||||
contentResolver.update(uri, values, selection, selectionArgs)
|
// should update the database and reset the cached missed call count in MissedCallNotifier.java
|
||||||
|
// https://android.googlesource.com/platform/packages/services/Telecomm/+/master/src/com/android/server/telecom/ui/MissedCallNotifierImpl.java#170
|
||||||
|
telecomManager.cancelMissedCallsNotification()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user