On Android 16 how can an app programmatically switch STREAM_MUSIC in MODE_NORMAL to the TYPE_BUILDIN_SPEAKER device?
On Android 16 how can an app programmatically globally switch STREAM_MUSIC in MODE_NORMAL to the TYPE_BUILDIN_SPEAKER device ?
The SetSpeakerPhoneOn() and setAudioRoute() APIs are either deprecated or no longer work. SetCommunicationDevice() is for calls not for normal audio. An app producing audio can use AudioAttributes but this is not a global switch. Due to the frequent changes to the AudioManager most of the audio routing apps are broken.
The reason this is required is simple - plug in a usb headset or just a microphone and the audio output to the speaker is cut off. It is possible outside of the Media Output panel as the Spotify app provides Wired Connection and This Phone options.The setting affects the whole phone not just Spotify audio.
Strangely on Samsung the Media Output panel does not give a This Phone option, but this could be a One UI issue.