I would like to receive the CallAudioState
during a call. I have already tried various implementations of InCallServiceCompat
and InCallService
. Unfortunately, I do not receive any information in onCallAudioStateChanged()
or onMuteStateChanged()
because they are not called.
I am very grateful for any tips that help me get this information during a call. Thank you very much for your efforts.
Daniel
I would like to receive the CallAudioState
during a call. I have already tried various implementations of InCallServiceCompat
and InCallService
. Unfortunately, I do not receive any information in onCallAudioStateChanged()
or onMuteStateChanged()
because they are not called.
I am very grateful for any tips that help me get this information during a call. Thank you very much for your efforts.
Daniel
Share Improve this question asked Feb 5 at 8:55 drindtdrindt 89911 silver badges15 bronze badges1 Answer
Reset to default 0To receive the CallAudioState
and MuteState
during a call, ensure you have the correct permissions and configuration for InCallService
. First, add the necessary permission in the AndroidManifest.xml
<uses-permission android:name="android.permission.BIND_INCALL_SERVICE" />
<service
android:name=".MyInCallService"
android:permission="android.permission.BIND_INCALL_SERVICE">
<intent-filter>
<action android:name="android.telecom.InCallService" />
</intent-filter>
</service>
Then, implement InCallService
properly by overriding onCallAudioStateChanged()
and onMuteStateChanged()
:
class MyInCallService : InCallService() {
override fun onCallAudioStateChanged(audioState: CallAudioState?) {
super.onCallAudioStateChanged(audioState)
Log.d("InCallService", "Audio state: $audioState")
}
override fun onMuteStateChanged(muted: Boolean) {
super.onMuteStateChanged(muted)
Log.d("InCallService", "Mute state: $muted")
}
}
Ensure your app is the default dialer or has a self-managed ConnectionService
. If still not receiving updates, manually request audio focus:
val audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
audioManager.mode = AudioManager.MODE_IN_CALL
Monitor call events using TelecomManager:
val telecomManager = getSystemService(Context.TELECOM_SERVICE) as TelecomManager
val calls = telecomManager.callCapablePhoneAccounts
Log.d("MyInCallService", "Phone accounts: $calls")
Testing on a real device is recommended as InCallService
may not work well on emulators. If the issue persists, further debugging of the call state may be required.