mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-21 12:39:58 +01:00
Improve call detection
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
a79a8733a6
commit
90cf68fd4c
@ -25,6 +25,7 @@ import android.content.Context
|
|||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Vibrator
|
import android.os.Vibrator
|
||||||
|
import android.telephony.TelephonyManager
|
||||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||||
|
|
||||||
object DoNotDisturbUtils {
|
object DoNotDisturbUtils {
|
||||||
@ -62,6 +63,15 @@ object DoNotDisturbUtils {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun areWeInTelephonyCall(context: Context): Boolean {
|
||||||
|
val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
||||||
|
if (telephonyManager.callState != TelephonyManager.CALL_STATE_IDLE) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
fun shouldPlaySound(importantConversation: Boolean): Boolean {
|
fun shouldPlaySound(importantConversation: Boolean): Boolean {
|
||||||
val context = NextcloudTalkApplication.sharedApplication?.applicationContext
|
val context = NextcloudTalkApplication.sharedApplication?.applicationContext
|
||||||
|
|
||||||
@ -86,7 +96,7 @@ object DoNotDisturbUtils {
|
|||||||
shouldPlaySound = true
|
shouldPlaySound = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (audioManager.mode == AudioManager.MODE_IN_CALL) {
|
if (areWeInTelephonyCall(context)) {
|
||||||
shouldPlaySound = false
|
shouldPlaySound = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,9 +111,7 @@ object DoNotDisturbUtils {
|
|||||||
|
|
||||||
fun shouldVibrate(vibrate: Boolean): Boolean {
|
fun shouldVibrate(vibrate: Boolean): Boolean {
|
||||||
val context = NextcloudTalkApplication.sharedApplication?.applicationContext
|
val context = NextcloudTalkApplication.sharedApplication?.applicationContext
|
||||||
val audioManager = context?.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
if (areWeInTelephonyCall(context!!)) {
|
||||||
|
|
||||||
if (audioManager.mode == AudioManager.MODE_IN_CALL) {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user