Observe contacts changes
This commit is contained in:
@ -10,6 +10,7 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.database.ContentObserver
|
||||
import android.media.*
|
||||
import android.net.*
|
||||
import android.net.wifi.WifiManager
|
||||
@ -18,6 +19,7 @@ import android.os.Handler
|
||||
import android.os.IBinder
|
||||
import android.os.Looper
|
||||
import android.os.PowerManager
|
||||
import android.provider.ContactsContract
|
||||
import android.provider.Settings
|
||||
import android.telecom.TelecomManager
|
||||
import android.text.Spannable
|
||||
@ -60,6 +62,7 @@ class BaresipService: Service() {
|
||||
private lateinit var wifiLock: WifiManager.WifiLock
|
||||
private lateinit var bluetoothReceiver: BroadcastReceiver
|
||||
private lateinit var hotSpotReceiver: BroadcastReceiver
|
||||
private lateinit var contentObserver: ContentObserver
|
||||
|
||||
private var rtTimer: Timer? = null
|
||||
private var audioFocusRequest: AudioFocusRequestCompat? = null
|
||||
@ -296,7 +299,21 @@ class BaresipService: Service() {
|
||||
this.registerReceiver(bluetoothReceiver, filter)
|
||||
}
|
||||
|
||||
AndroidContactsActivity.fetchAndroidContacts(this)
|
||||
val contentObserver: ContentObserver = object : ContentObserver(null) {
|
||||
override fun onChange(self: Boolean) {
|
||||
Log.d(TAG, "Contacts change")
|
||||
AndroidContactsActivity.fetchAndroidContacts(this@BaresipService.applicationContext)
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
AndroidContactsActivity.fetchAndroidContacts(this)
|
||||
contentResolver.registerContentObserver(
|
||||
ContactsContract.Contacts.CONTENT_URI, true, contentObserver)
|
||||
} catch(e: SecurityException) {
|
||||
Log.i(TAG, "No Contacts permission")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
@ -1389,6 +1406,9 @@ class BaresipService: Service() {
|
||||
proximityWakeLock.release()
|
||||
if (this::wifiLock.isInitialized)
|
||||
wifiLock.release()
|
||||
if (this::contentObserver.isInitialized)
|
||||
contentResolver.unregisterContentObserver(contentObserver)
|
||||
|
||||
isServiceClean = true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user