最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Correct implementation for receiving the `CallAudioState` - Stack Overflow

programmeradmin9浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

To 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.

发布评论

评论列表(0)

  1. 暂无评论