AudioManager or audio focus.
AudioManager mode
TheAudioManager mode controls how audio hardware behaves. For voice sessions, use
MODE_IN_COMMUNICATION:
Speaker vs earpiece
Control whether audio plays through the loudspeaker or the earpiece:isSpeakerphoneOn only takes effect when audioManager.mode == MODE_IN_COMMUNICATION.
Setting it in MODE_NORMAL has no effect.ProximityWakeLock — auto earpiece on approach
Enable auto-switching to earpiece when the user holds the device to their ear. This requires theWAKE_LOCK permission:
ProximityAudioRouter.start() when the voice session starts and stop() when it ends.
AudioFocusRequest
Request audio focus before starting the voice session. This ensures your app is notified when another source (phone call, navigation, alarm) needs audio:Bluetooth SCO
Enable the Bluetooth SCO profile to route audio through a paired Bluetooth headset (HFP — Hands-Free Profile):Bluetooth SCO (
startBluetoothSco) is asynchronous — the connection may take 200–2000 ms.
Do not start the voice session until the SCO_AUDIO_STATE_CONNECTED broadcast is received.
If SCO is unavailable, fall back to speakerphone.